12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)package com.bumptech.glide.load.model;
2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)import com.bumptech.glide.load.model.stream.StreamStringLoader;
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)import com.bumptech.glide.load.data.DataFetcher;
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)import com.bumptech.glide.load.resource.bitmap.BitmapDecoder;
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/**
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * An interface for translating an arbitrarily complex data model into a concrete data type that can be used by an
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * {@link DataFetcher} to obtain the data for an image represented by the model.
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * This interface has two objectives:
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *   1. To translate a specific data model into something that can be used by a decoder to load a Bitmap.
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *   2. To allow a data model to be combined with the dimensions of the view to fetch an image of a specific size.
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *      This not only avoids having to duplicate dimensions in xml and in your code in order to determine the size of a
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *      view on devices with different densities, but also allows you to use layout weights or otherwise
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *      programatically set the dimensions of the view without forcing you to fetch a generic image size.
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *      The smaller the image you fetch, the less bandwidth and battery life you use, and the lower your memory
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *      footprint per image.
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * @param <T> The type of the model
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * @param <Y> The type of the data that can be used by a {@link BitmapDecoder}
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *           to decode a Bitmap.
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) */
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public interface ModelLoader<T, Y> {
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    /**
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     * Obtain an {@link DataFetcher} that can load the data required to decode the
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     * image represented by this model. The {@link DataFetcher} will not be used if
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     * the image is already cached.
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     *
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     * <p>
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     *     Note - If the {@link StreamStringLoader} in any way retains a reference a context, either directly or as an
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     *     anonymous inner class, that context may be leaked. The leak will only be an issue if this load can run for a
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     *     long time or indefinitely (because of a particularly slow or paused/failed download for example).
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     * </p>
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     *
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     *
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     * @param model The model representing the image
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     * @param width The width of the view the image will be loaded into
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     * @param height The height of the view the image will be loaded into
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     * @return A {@link DataFetcher} that can obtain the data for the image if the
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     *          image is not cached.
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)     */
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    public DataFetcher<Y> getResourceFetcher(T model, int width, int height);
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)