-
public interface RequestListener<R>A class for monitoring the status of a request while images load.
All methods in this interface will be called from a background thread if the
{@code * RequestListener}is added to a request that is started with submit, submit, or into. Those methods no longer post results back to the main thread to avoid the unnecessary thread interactions and corresponding latency. As a side affect though, listeners added to those requests are no longer called on the main thread.{@code RequestListeners}added to requests started with or into will continue to be called back on the main thread.
-
-
Method Summary
Modifier and Type Method Description abstract booleanonLoadFailed(@Nullable() ImageModuleException e, Object model, Target<R> target, boolean isFirstResource)Called when an exception occurs during a load, immediately before . abstract booleanonResourceReady(R resource, Object model, Target<R> target, DataSource dataSource, boolean isFirstResource)Called when a load completes successfully, immediately before . -
-
Method Detail
-
onLoadFailed
abstract boolean onLoadFailed(@Nullable() ImageModuleException e, Object model, Target<R> target, boolean isFirstResource)
Called when an exception occurs during a load, immediately before . Will only be called if we currently want to display an imagefor the given model in the given target. It is recommended to create a single instance peractivity/fragment rather than instantiate a new object for each call to
{@code * ImageModule.with(fragment/activity).load()}to avoid object churn.It is not safe to reload this or a different model in this callback. If you need to do souse error instead.
Although you can't start an entirely new load, it is safe to change what is displayed in the Target at this point, as long as you return
{@code true}from the method to prevent onLoadFailed from being called.For threading guarantees, see the class comment.
For example:
{@code * public boolean onLoadFailed(Exception e, T model, Target target, boolean isFirstResource) { * target.setPlaceholder(R.drawable.a_specific_error_for_my_exception); * return true; // Prevent onLoadFailed from being called on the Target. * } * }- Parameters:
e- The maybe{@code null}exception containing information about why the request failed.model- The model we were trying to load when the exception occurred.target- The Target we were trying to load the image into.isFirstResource-{@code true}if this exception is for the first resource to load.
-
onResourceReady
abstract boolean onResourceReady(R resource, Object model, Target<R> target, DataSource dataSource, boolean isFirstResource)
Called when a load completes successfully, immediately before .
For threading guarantees, see the class comment.
- Parameters:
resource- The resource that was loaded for the target.model- The specific model that was used to load the image.target- The target the model was loaded into.dataSource- The DataSource the resource was loaded from.isFirstResource-{@code true}if this is the first resource to in this load to be loadedinto the target.
-
-
-
-