Home | History | Annotate | Download | only in request
      1 package com.bumptech.glide.request;
      2 
      3 import com.bumptech.glide.request.target.Target;
      4 
      5 /**
      6  * A class for monitoring the status of a request while images load.
      7  *
      8  * @param <T> The type of the model being loaded.
      9  * @param <R> The type of resource being loaded.
     10  */
     11 public interface RequestListener<T, R> {
     12 
     13     /**
     14      * Called when an exception occurs during a load. Will only be called if we currently want to display an image
     15      * for the given model in the given target. It is recommended to create a single instance per activity/fragment
     16      * rather than instantiate a new object for each call to {@code Glide.load()} to avoid object churn.
     17      *
     18      * <p>
     19      *     It is safe to reload this or a different model or change what is displayed in the target at this point.
     20      *     For example:
     21      * <pre>
     22      * {@code
     23      * public void onException(Exception e, T model, Target target, boolean isFirstResource) {
     24      *     target.setPlaceholder(R.drawable.a_specific_error_for_my_exception);
     25      *     Glide.load(model).into(target);
     26      * }
     27      * }
     28      * </pre>
     29      * </p>
     30      *
     31      * <p>
     32      *     Note - if you want to reload this or any other model after an exception, you will need to include all
     33      *     relevant builder calls (like centerCrop, placeholder etc).
     34      * </p>
     35      *
     36      * @param e The exception, or null.
     37      * @param model The model we were trying to load when the exception occurred.
     38      * @param target The {@link Target} we were trying to load the image into.
     39      * @param isFirstResource True if this exception is for the first resource to load.
     40      * @return True if the listener has handled updating the target for the given exception, false to allow
     41      *         Glide's request to update the target.
     42      */
     43     boolean onException(Exception e, T model, Target<R> target, boolean isFirstResource);
     44 
     45     /**
     46      * Called when a load completes successfully, immediately after
     47      * {@link Target#onResourceReady(Object, com.bumptech.glide.request.animation.GlideAnimation)}.
     48      *
     49      * @param resource The resource that was loaded for the target.
     50      * @param model The specific model that was used to load the image.
     51      * @param target The target the model was loaded into.
     52      * @param isFromMemoryCache True if the load completed synchronously (useful for determining whether or not to
     53      *                          animate)
     54      * @param isFirstResource True if this is the first resource to in this load to be loaded into the target. For
     55      *                        example when loading a thumbnail and a fullsize image, this will be true for the first
     56      *                        image to load and false for the second.
     57      * @return True if the listener has handled setting the resource on the target (including any animations), false to
     58      *         allow Glide's request to update the target (again including animations).
     59      */
     60     boolean onResourceReady(R resource, T model, Target<R> target, boolean isFromMemoryCache, boolean isFirstResource);
     61 }
     62