1 package com.bumptech.glide.load.model; 2 3 import com.bumptech.glide.load.data.DataFetcher; 4 5 /** 6 * A factory interface for translating an arbitrarily complex data model into a concrete data type that can be used 7 * by an {@link DataFetcher} to obtain the data for a resource represented by the model. 8 * 9 * <p> 10 * This interface has two objectives: 11 * 1. To translate a specific model into a data type that can be decoded into a resource. 12 * 13 * 2. To allow a model to be combined with the dimensions of the view to fetch a resource of a specific size. 14 * 15 * This not only avoids having to duplicate dimensions in xml and in your code in order to determine the size of a 16 * view on devices with different densities, but also allows you to use layout weights or otherwise 17 * programatically set the dimensions of the view without forcing you to fetch a generic resource size. 18 * 19 * The smaller the resource you fetch, the less bandwidth and battery life you use, and the lower your memory 20 * footprint per resource. 21 *</p> 22 * 23 * @param <T> The type of the model. 24 * @param <Y> The type of the data that can be used by a {@link com.bumptech.glide.load.ResourceDecoder} to decode a 25 * resource. 26 */ 27 public interface ModelLoader<T, Y> { 28 29 /** 30 * Obtains an {@link DataFetcher} that can fetch the data required to decode the resource represented by this model. 31 * The {@link DataFetcher} will not be used if the resource is already cached. 32 * 33 * <p> 34 * Note - If no valid data fetcher can be returned (for example if a model has a null URL), then it is 35 * acceptable to return a null data fetcher from this method. Doing so will be treated any other failure or 36 * exception during the load process. 37 * </p> 38 * 39 * @param model The model representing the resource. 40 * @param width The width in pixels of the view or target the resource will be loaded into 41 * @param height The height in pixels of the view or target the resource will be loaded into 42 * @return A {@link DataFetcher} that can obtain the data the resource can be decoded from if the resource is not 43 * cached, or null if no valid {@link com.bumptech.glide.load.data.DataFetcher} could be constructed. 44 */ getResourceFetcher(T model, int width, int height)45 DataFetcher<Y> getResourceFetcher(T model, int width, int height); 46 } 47