-
- All Implemented Interfaces:
-
com.mobwith.imgmodule.manager.LifecycleListener
public interface Target<R> implements LifecycleListener
An interface that ImageModule can load a resource into and notify of relevant lifecycle events during a load.
The lifecycle events in this class are as follows:
- onLoadStarted
- onResourceReady
- onLoadCleared
- onLoadFailed
-
-
Method Summary
Modifier and Type Method Description abstract voidonLoadStarted(@Nullable() Drawable placeholder)A lifecycle callback that is called when a load is started. abstract voidonLoadFailed(@Nullable() Drawable errorDrawable)A mandatory lifecycle callback that is called when a load fails. abstract voidonResourceReady(@NonNull() R resource, @Nullable() Transition<out Object> transition)The method that will be called when the resource load has finished. abstract voidonLoadCleared(@Nullable() Drawable placeholder)A mandatory lifecycle callback that is called when a load is cancelled and its resourcesare freed. abstract voidgetSize(@NonNull() SizeReadyCallback cb)A method to retrieve the size of this target. abstract voidremoveCallback(@NonNull() SizeReadyCallback cb)Removes the given callback from the pending set if it's still retained. abstract voidsetRequest(@Nullable() Request request)Sets the current request for this target to retain, should not be called outside of ImageModule. abstract RequestgetRequest()Retrieves the current request for this target, should not be called outside of ImageModule. -
-
Method Detail
-
onLoadStarted
abstract void onLoadStarted(@Nullable() Drawable placeholder)
A lifecycle callback that is called when a load is started.
Note - This may not be called for every load, it is possible for example for loads to failbefore the load starts (when the model object is null).
Note - This method may be called multiple times before any other lifecycle method is called.Loads can be paused and restarted due to lifecycle or connectivity events and each restart maycause a call here.
- Parameters:
placeholder- The placeholder drawable to optionally show, or null.
-
onLoadFailed
abstract void onLoadFailed(@Nullable() Drawable errorDrawable)
A mandatory lifecycle callback that is called when a load fails.
Note - This may be called before onLoadStarted if the model object is null.
You must ensure that any current Drawable received in onResourceReady is no longer used before redrawing the container (usually a View) or changing itsvisibility.
- Parameters:
errorDrawable- The error drawable to optionally show, or null.
-
onResourceReady
abstract void onResourceReady(@NonNull() R resource, @Nullable() Transition<out Object> transition)
The method that will be called when the resource load has finished.
- Parameters:
resource- the loaded resource.
-
onLoadCleared
abstract void onLoadCleared(@Nullable() Drawable placeholder)
A mandatory lifecycle callback that is called when a load is cancelled and its resourcesare freed.
You must ensure that any current Drawable received in onResourceReady is no longer used before redrawing the container (usually a View) or changing itsvisibility.
- Parameters:
placeholder- The placeholder drawable to optionally show, or null.
-
getSize
abstract void getSize(@NonNull() SizeReadyCallback cb)
A method to retrieve the size of this target.
- Parameters:
cb- The callback that must be called when the size of the target has been determined
-
removeCallback
abstract void removeCallback(@NonNull() SizeReadyCallback cb)
Removes the given callback from the pending set if it's still retained.
- Parameters:
cb- The callback to remove.
-
setRequest
abstract void setRequest(@Nullable() Request request)
Sets the current request for this target to retain, should not be called outside of ImageModule.
-
getRequest
@Nullable() abstract Request getRequest()
Retrieves the current request for this target, should not be called outside of ImageModule.
-
-
-
-