1package com.bumptech.glide.load.model; 2 3import com.bumptech.glide.load.model.stream.StreamStringLoader; 4import com.bumptech.glide.load.data.DataFetcher; 5import com.bumptech.glide.load.resource.bitmap.BitmapDecoder; 6 7/** 8 * An interface for translating an arbitrarily complex data model into a concrete data type that can be used by an 9 * {@link DataFetcher} to obtain the data for an image represented by the model. 10 * 11 * This interface has two objectives: 12 * 1. To translate a specific data model into something that can be used by a decoder to load a Bitmap. 13 * 14 * 2. To allow a data model to be combined with the dimensions of the view to fetch an image of a specific size. 15 * 16 * This not only avoids having to duplicate dimensions in xml and in your code in order to determine the size of a 17 * view on devices with different densities, but also allows you to use layout weights or otherwise 18 * programatically set the dimensions of the view without forcing you to fetch a generic image size. 19 * 20 * The smaller the image you fetch, the less bandwidth and battery life you use, and the lower your memory 21 * footprint per image. 22 * 23 * 24 * @param <T> The type of the model 25 * @param <Y> The type of the data that can be used by a {@link BitmapDecoder} 26 * to decode a Bitmap. 27 */ 28public interface ModelLoader<T, Y> { 29 30 /** 31 * Obtain an {@link DataFetcher} that can load the data required to decode the 32 * image represented by this model. The {@link DataFetcher} will not be used if 33 * the image is already cached. 34 * 35 * <p> 36 * Note - If the {@link StreamStringLoader} in any way retains a reference a context, either directly or as an 37 * anonymous inner class, that context may be leaked. The leak will only be an issue if this load can run for a 38 * long time or indefinitely (because of a particularly slow or paused/failed download for example). 39 * </p> 40 * 41 * 42 * @param model The model representing the image 43 * @param width The width of the view the image will be loaded into 44 * @param height The height of the view the image will be loaded into 45 * @return A {@link DataFetcher} that can obtain the data for the image if the 46 * image is not cached. 47 */ 48 public DataFetcher<Y> getResourceFetcher(T model, int width, int height); 49} 50