Package 

Interface Target

  • 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
    The typical lifecycle is onLoadStarted -> onResourceReady or onLoadFailed -> onLoadCleared. However, there are no guarantees. onLoadStarted may not be called if the resource is in memory or if the load will fail because of a null model object. onLoadCleared similarly may never be called if the target is never cleared. See the docs for the individual methods for details.
    • Method Summary

      Modifier and Type Method Description
      abstract void onLoadStarted(@Nullable() Drawable placeholder) A lifecycle callback that is called when a load is started.
      abstract void onLoadFailed(@Nullable() Drawable errorDrawable) A mandatory lifecycle callback that is called when a load fails.
      abstract void onResourceReady(@NonNull() R resource, @Nullable() Transition<out Object> transition) The method that will be called when the resource load has finished.
      abstract void onLoadCleared(@Nullable() Drawable placeholder) A mandatory lifecycle callback that is called when a load is cancelled and its resourcesare freed.
      abstract void getSize(@NonNull() SizeReadyCallback cb) A method to retrieve the size of this target.
      abstract void removeCallback(@NonNull() SizeReadyCallback cb) Removes the given callback from the pending set if it's still retained.
      abstract void setRequest(@Nullable() Request request) Sets the current request for this target to retain, should not be called outside of ImageModule.
      abstract Request getRequest() Retrieves the current request for this target, should not be called outside of ImageModule.
      • Methods inherited from class com.mobwith.imgmodule.manager.LifecycleListener

        onDestroy, onStart, onStop
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.
      • 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.