-
- All Implemented Interfaces:
-
com.mobwith.imgmodule.ModelTypes,java.lang.Cloneable
public class RequestBuilder<TranscodeType> extends BaseRequestOptions<RequestBuilder<TranscodeType>> implements Cloneable, ModelTypes<RequestBuilder<TranscodeType>>
A generic class that can handle setting options and staring loads for generic resource types.
-
-
Method Summary
Modifier and Type Method Description RequestBuilder<TranscodeType>apply(@NonNull() BaseRequestOptions<out Object> requestOptions)Applies the given options to the request. RequestBuilder<TranscodeType>transition(@NonNull() TransitionOptions<out Object, out Object> transitionOptions)Sets the TransitionOptions to use to transition from the placeholder or thumbnail whenthis load completes. RequestBuilder<TranscodeType>listener(@Nullable() RequestListener<TranscodeType> requestListener)Sets a RequestListener to monitor the resource load. RequestBuilder<TranscodeType>addListener(@Nullable() RequestListener<TranscodeType> requestListener)Adds a RequestListener. RequestBuilder<TranscodeType>error(@Nullable() RequestBuilder<TranscodeType> errorBuilder)Sets a RequestBuilder that is built and run if the load started by this fails. RequestBuilder<TranscodeType>error(Object model)Identical to calling error where the {@code RequestBuilder}is theresult of calling clone and removing any existing thumbnail and error{@code * RequestBuilders}.RequestBuilder<TranscodeType>thumbnail(@Nullable() RequestBuilder<TranscodeType> thumbnailRequest)Loads and displays the resource retrieved by the given thumbnail request if it finishes beforethis request. RequestBuilder<TranscodeType>thumbnail(@Nullable() Array<RequestBuilder<TranscodeType>> thumbnails)Recursively applies thumbnail so that the RequestBuilders areloaded as thumbnails in the given priority order. RequestBuilder<TranscodeType>thumbnail(@Nullable() List<RequestBuilder<TranscodeType>> thumbnails)Recursively applies thumbnail so that the RequestBuilders areloaded as thumbnails in the given priority order. RequestBuilder<TranscodeType>thumbnail(float sizeMultiplier)Loads a resource in an identical manner to this request except with the dimensions of thetarget multiplied by the given size multiplier. RequestBuilder<TranscodeType>load(@Nullable() Object model)Sets the specific model to load data for. RequestBuilder<TranscodeType>load(@Nullable() Bitmap bitmap)Returns an object to load the given Bitmap. RequestBuilder<TranscodeType>load(@Nullable() Drawable drawable)Returns a request builder to load the given Drawable. RequestBuilder<TranscodeType>load(@Nullable() String string)Returns a request builder to load the given String. RequestBuilder<TranscodeType>load(@Nullable() Uri uri)Returns a request builder to load the given Uri. RequestBuilder<TranscodeType>load(@Nullable() File file)Returns a request builder to load the given File. RequestBuilder<TranscodeType>load(@RawRes() @DrawableRes() @Nullable() Integer resourceId)Returns a request builder that uses the currently registered or Integer toload the image represented by the given Integer resource id. RequestBuilder<TranscodeType>load(@Nullable() URL url)Returns a request builder to load the given URL. RequestBuilder<TranscodeType>load(@Nullable() Array<byte> model)Returns a request to load the given byte array. RequestBuilder<TranscodeType>clone()Returns a copy of this request builder with all of the options put so far on this builder. <Y extends Target<TranscodeType>> Yinto(@NonNull() Y target)Set the target the resource will be loaded into. ViewTarget<ImageView, TranscodeType>into(@NonNull() ImageView view)Sets the ImageView the resource will be loaded into, cancels any existing loads intothe view, and frees any resources ImageModule may have previously loaded into the view so they may bereused. FutureTarget<TranscodeType>into(int width, int height)Returns a future that can be used to do a blocking get on a background thread. FutureTarget<TranscodeType>submit()Returns a future that can be used to do a blocking get on a background thread. FutureTarget<TranscodeType>submit(int width, int height)Returns a future that can be used to do a blocking get on a background thread. Target<TranscodeType>preload(int width, int height)Preloads the resource into the cache using the given width and height. Target<TranscodeType>preload()Preloads the resource into the cache using SIZE_ORIGINAL as the target width andheight. <Y extends Target<File>> YdownloadOnly(@NonNull() Y target)Loads the original unmodified data into the cache and calls the given Target with the cacheFile. FutureTarget<File>downloadOnly(int width, int height)Loads the original unmodified data into the cache and returns a that can be used to retrieve the cache File containing the data. -
Methods inherited from class com.mobwith.imgmodule.request.BaseRequestOptions
apply, autoClone, centerCrop, centerInside, circleCrop, clone, decode, disallowHardwareConfig, diskCacheStrategy, dontAnimate, dontTransform, downsample, encodeFormat, encodeQuality, equals, error, error, fallback, fallback, fitCenter, format, frame, getDiskCacheStrategy, getErrorId, getErrorPlaceholder, getFallbackDrawable, getFallbackId, getOnlyRetrieveFromCache, getOptions, getOverrideHeight, getOverrideWidth, getPlaceholderDrawable, getPlaceholderId, getPriority, getResourceClass, getSignature, getSizeMultiplier, getTheme, getTransformations, getUseAnimationPool, getUseUnlimitedSourceGeneratorsPool, hashCode, isDiskCacheStrategySet, isLocked, isMemoryCacheable, isPrioritySet, isSkipMemoryCacheSet, isTransformationAllowed, isTransformationRequired, isTransformationSet, isValidOverride, lock, onlyRetrieveFromCache, optionalCenterCrop, optionalCenterInside, optionalCircleCrop, optionalFitCenter, optionalTransform, optionalTransform, override, override, placeholder, placeholder, priority, set, signature, sizeMultiplier, skipMemoryCache, theme, timeout, transform, transform, transform, transforms, useAnimationPool, useUnlimitedSourceGeneratorsPool -
Methods inherited from class com.mobwith.imgmodule.ModelTypes
load, load, load, load, load, load, load, load, load -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
apply
@NonNull()@CheckResult() RequestBuilder<TranscodeType> apply(@NonNull() BaseRequestOptions<out Object> requestOptions)
Applies the given options to the request.
As with apply,
{@code #apply}only replaces thosevalues that are explicitly set in the given RequestOptions object. If you need tocompletely reset all previously set options, create a new{@code RequestBuilder}instead ofusing this method.
-
transition
@NonNull()@CheckResult() RequestBuilder<TranscodeType> transition(@NonNull() TransitionOptions<out Object, out Object> transitionOptions)
Sets the TransitionOptions to use to transition from the placeholder or thumbnail whenthis load completes.
The given TransitionOptions will replace any TransitionOptions setpreviously.
-
listener
@NonNull()@CheckResult() RequestBuilder<TranscodeType> listener(@Nullable() RequestListener<TranscodeType> requestListener)
Sets a RequestListener to monitor the resource load. It's best to create a singleinstance of an exception handler per type of request (usually activity/fragment) rather thanpass one in per request to avoid some redundant object allocation.
Subsequent calls to this method will replace previously set listeners. To set multiplelisteners, use addListener instead.
- Parameters:
requestListener- The request listener to use.
-
addListener
@NonNull()@CheckResult() RequestBuilder<TranscodeType> addListener(@Nullable() RequestListener<TranscodeType> requestListener)
Adds a RequestListener. If called multiple times, all passed listeners will be called in order.
- Parameters:
requestListener- The request listener to use.
-
error
@NonNull() RequestBuilder<TranscodeType> error(@Nullable() RequestBuilder<TranscodeType> errorBuilder)
Sets a RequestBuilder that is built and run if the load started by this fails.
If this RequestBuilder uses a thumbnail that succeeds the given error will be started anyway if the non-thumbnail request fails.
Recursive calls to this method as well as calls to thumbnail and are supported for the given error RequestBuilder.
Unlike thumbnail and thumbnail, no options fromthis primary RequestBuilder are propagated to the given error RequestBuilder.Options like priority, override widths and heights and transitions must be appliedindependently to the error builder.
The given RequestBuilder will start and potentially override a fallback drawable ifit's set on this RequestBuilder via or .
-
error
@NonNull()@CheckResult() RequestBuilder<TranscodeType> error(Object model)
Identical to calling error where the
{@code RequestBuilder}is theresult of calling clone and removing any existing thumbnail and error{@code * RequestBuilders}.Other than thumbnail and error
{@code RequestBuilder}s, which are removed, all other optionsare retained from the primary request. However, order matters! Any options applied afterthis method is called will not be applied to the error{@code RequestBuilder}.WARNING: Calling this method with a
{@code model}whose type does not match the type of themodel passed to{@code load()}may be dangerous! Any options that were applied by the varioustype specific{@code load()}methods, like load will be copied to the errorrequest here even if the{@code model}you pass to this method doesn't match. Similary, optionsthat would be normally applied by type specific{@code load()}methods will not beapplied to this request. If this behavior is confusing or unexpected, use instead.
-
thumbnail
@NonNull()@CheckResult() RequestBuilder<TranscodeType> thumbnail(@Nullable() RequestBuilder<TranscodeType> thumbnailRequest)
Loads and displays the resource retrieved by the given thumbnail request if it finishes beforethis request. Best used for loading thumbnail resources that are smaller and will be loadedmore quickly than the full size resource. There are no guarantees about the order in which therequests will actually finish. However, if the thumb request completes after the full request,the thumb resource will never replace the full resource.
Recursive calls to thumbnail are supported.
Overrides any previous calls to this method, thumbnail and .
- Parameters:
thumbnailRequest- The request to use to load the thumbnail.
-
thumbnail
@NonNull()@CheckResult() RequestBuilder<TranscodeType> thumbnail(@Nullable() Array<RequestBuilder<TranscodeType>> thumbnails)
Recursively applies thumbnail so that the RequestBuilders areloaded as thumbnails in the given priority order.
thumbnail is applied in the order given so that the at position 0 has the RequestBuilder at position 1 applied as using itsthumbnail method, the RequestBuilder at position 1 has the RequestBuilder atposition 2 applied using its thumbnail method and so on.
Calling this method with an
{@code null}array of RequestBuilder thumbnails or anempty array of RequestBuilder thumbnails is equivalent to calling with{@code null}.Any individual RequestBuilder in the array of thumbnails provided here may be
{@code * null}.{@code null}RequestBuilders are ignored and excluded from the recursive chain.The RequestBuilder objects provided here may be mutated and have any previous callsto this method or thumbnail methods overridden.
Overrides any previous calls to thumbnail, and this method.
-
thumbnail
@NonNull()@CheckResult() RequestBuilder<TranscodeType> thumbnail(@Nullable() List<RequestBuilder<TranscodeType>> thumbnails)
Recursively applies thumbnail so that the RequestBuilders areloaded as thumbnails in the given priority order.
thumbnail is applied in the order given so that the at position 0 has the RequestBuilder at position 1 applied as using itsthumbnail method, the RequestBuilder at position 1 has the RequestBuilder atposition 2 applied using its thumbnail method and so on.
Calling this method with a
{@code null}list of RequestBuilder thumbnails or anempty list of RequestBuilder thumbnails is equivalent to calling with{@code null}.Any individual RequestBuilder in the list of thumbnails provided here may be
{@code * null}.{@code null}RequestBuilders are ignored and excluded from the recursive chain.The RequestBuilder objects provided here may be mutated and have any previous callsto this method or thumbnail methods overridden.
Overrides any previous calls to thumbnail, and this method.
-
thumbnail
@NonNull()@CheckResult() RequestBuilder<TranscodeType> thumbnail(float sizeMultiplier)
Loads a resource in an identical manner to this request except with the dimensions of thetarget multiplied by the given size multiplier. If the thumbnail load completes before the fullsize load, the thumbnail will be shown. If the thumbnail load completes after the full sizeload, the thumbnail will not be shown.
Note - The thumbnail resource will be smaller than the size requested so the target (or ImageView) must be able to scale the thumbnail appropriately. See .
Almost all options will be copied from the original load, including the , com.mobwith.imgmodule.load.ResourceDecoder,and com.mobwith.imgmodule.load.Transformations. However, and , and listener will only be used on the full size load and will not be copied for the thumbnail load.
Recursive calls to thumbnail are supported.
Overrides any previous calls to this method, thumbnail, and thumbnail.
- Parameters:
sizeMultiplier- The multiplier to apply to the Target's dimensions when loadingthe thumbnail.
-
load
@NonNull()@CheckResult() RequestBuilder<TranscodeType> load(@Nullable() Object model)
Sets the specific model to load data for.
- Parameters:
model- The model to load data for, or null.
-
load
@NonNull()@CheckResult() RequestBuilder<TranscodeType> load(@Nullable() Bitmap bitmap)
Returns an object to load the given Bitmap.
It's almost always better to allow ImageModule to load Bitmaps than pass Bitmapsinto ImageModule. If you have a custom way to obtain Bitmaps that is not supported by ImageModuleby default, consider registering a custom com.mobwith.imgmodule.load.model.ModelLoader or com.mobwith.imgmodule.load.ResourceDecoder instead of using this method.
The DiskCacheStrategy is set to NONE. Previous calls to apply or previously applied DiskCacheStrategys will beoverridden by this method. Applying an DiskCacheStrategy other than after calling this method may result in undefined behavior.
In memory caching relies on Object equality. The contents of the Bitmaps are notcompared.
-
load
@NonNull()@CheckResult() RequestBuilder<TranscodeType> load(@Nullable() Drawable drawable)
Returns a request builder to load the given Drawable.
It's almost always better to allow ImageModule to load Bitmaps than to pass s into ImageModule using this method . If you have a custom way to obtain Bitmaps thatis not supported by ImageModule by default, consider registering a custom or com.mobwith.imgmodule.load.ResourceDecoder instead of using this method.
The DiskCacheStrategy is set to NONE. Previous calls to apply or previously applied DiskCacheStrategys will beoverridden by this method. Applying an DiskCacheStrategy other than after calling this method may result in undefined behavior.
In memory caching relies on Object equality. The contents of the Drawables are notcompared.
-
load
@NonNull()@CheckResult() RequestBuilder<TranscodeType> load(@Nullable() String string)
Returns a request builder to load the given String.
Note - this method caches data using only the given String as the cache key. If the data isa Uri outside of your control, or you otherwise expect the data represented by the given Stringto change without the String identifier changing, Consider using to mixin asignature you create that identifies the data currently at the given String that willinvalidate the cache if that data changes. Alternatively, using and/or may be appropriate.
- Parameters:
string- A file path, or a uri or url handled by .
-
load
@NonNull()@CheckResult() RequestBuilder<TranscodeType> load(@Nullable() Uri uri)
Returns a request builder to load the given Uri.
Note - this method caches data at Uris using only the Uri itself as the cache key. The datarepresented by Uris from some content providers may change without the Uri changing, whichmeans using this method can lead to displaying stale data. Consider using to mixin asignature you create based on the data at the given Uri that will invalidate the cache if thatdata changes. Alternatively, using and/or may be appropriate.
- Parameters:
uri- The Uri representing the image.
-
load
@NonNull()@CheckResult() RequestBuilder<TranscodeType> load(@Nullable() File file)
Returns a request builder to load the given File.
Note - this method caches data for Files using only the file path itself as the cache key.The data in the File can change so using this method can lead to displaying stale data. If youexpect the data in the File to change, Consider using to mixin asignature you create that identifies the data currently in the File that will invalidate thecache if that data changes. Alternatively, using and/or may be appropriate.
- Parameters:
file- The File containing the image
-
load
@NonNull()@CheckResult() RequestBuilder<TranscodeType> load(@RawRes() @DrawableRes() @Nullable() Integer resourceId)
Returns a request builder that uses the currently registered or Integer toload the image represented by the given Integer resource id. Defaults to to load resource id models.
By default this method adds a version code and night mode based signature to the cache keyused to cache this resource in ImageModule. This signature is sufficient to guarantee that end userswill see the most up to date versions of your Drawables, but during development if you do notincrement your version code before each install and you replace a Drawable with different datawithout changing the Drawable name, you may see inconsistent cached data. To get around this,consider using NONE via duringdevelopment, and re-enabling the default for release builds.
This method will load non-Bitmap resources like s. Although ImageModule makes a best effort to apply s to these Drawables by either extracting theunderlying Bitmap or by converting the Drawable to a Bitmap, ImageModule isstill not able to transform all types of resources. Animated Drawables cannot betransformed (other than com.mobwith.imgmodule.load.resource.gif.GifDrawable). To avoidload failures if a Drawable can't be transformed, use the optional transformationmethods like optionalTransform.
In some cases converting Drawables to Bitmaps may be inefficient. Use thismethod, especially in conjunction with com.mobwith.imgmodule.load.Transformations withcaution for non-BitmapDrawables.
-
load
@Deprecated()@CheckResult() RequestBuilder<TranscodeType> load(@Nullable() URL url)
Returns a request builder to load the given URL.
- Parameters:
url- The URL representing the image.
-
load
@NonNull()@CheckResult() RequestBuilder<TranscodeType> load(@Nullable() Array<byte> model)
Returns a request to load the given byte array.
Note - by default loads for bytes are not cached in either the memory or the disk cache.
- Parameters:
model- the data to load.
-
clone
@CheckResult() RequestBuilder<TranscodeType> clone()
Returns a copy of this request builder with all of the options put so far on this builder.
This method returns a "deep" copy in that all non-immutable arguments are copied such thatchanges to one builder will not affect the other builder. However, in addition to immutablearguments, the current model is not copied so changes to the model will affect both builders.
-
into
@NonNull() <Y extends Target<TranscodeType>> Y into(@NonNull() Y target)
Set the target the resource will be loaded into.
- Parameters:
target- The target to load the resource into.
-
into
@NonNull() ViewTarget<ImageView, TranscodeType> into(@NonNull() ImageView view)
Sets the ImageView the resource will be loaded into, cancels any existing loads intothe view, and frees any resources ImageModule may have previously loaded into the view so they may bereused.
- Parameters:
view- The view to cancel previous loads for and load the new resource into.
-
into
@Deprecated() FutureTarget<TranscodeType> into(int width, int height)
Returns a future that can be used to do a blocking get on a background thread.
- Parameters:
width- The desired width in pixels, or SIZE_ORIGINAL.height- The desired height in pixels, or SIZE_ORIGINAL.
-
submit
@NonNull() FutureTarget<TranscodeType> submit()
Returns a future that can be used to do a blocking get on a background thread.
This method defaults to SIZE_ORIGINAL for the width and the height. However,since the width and height will be overridden by values passed to , this method can be used whenever RequestOptions with override values are applied, or whenever you want to retrieve the image in its originalsize.
-
submit
@NonNull() FutureTarget<TranscodeType> submit(int width, int height)
Returns a future that can be used to do a blocking get on a background thread.
- Parameters:
width- The desired width in pixels, or SIZE_ORIGINAL.height- The desired height in pixels, or SIZE_ORIGINAL.
-
preload
@NonNull() Target<TranscodeType> preload(int width, int height)
Preloads the resource into the cache using the given width and height.
Pre-loading is useful for making sure that resources you are going to to want in the nearfuture are available quickly.
- Parameters:
width- The desired width in pixels, or SIZE_ORIGINAL.height- The desired height in pixels, or SIZE_ORIGINAL.
-
preload
@NonNull() Target<TranscodeType> preload()
Preloads the resource into the cache using SIZE_ORIGINAL as the target width andheight. Equivalent to calling preload with SIZE_ORIGINAL asthe width and height.
-
downloadOnly
@Deprecated()@CheckResult() <Y extends Target<File>> Y downloadOnly(@NonNull() Y target)
Loads the original unmodified data into the cache and calls the given Target with the cacheFile.
- Parameters:
target- The Target that will receive the cache File when the load completes
-
downloadOnly
@Deprecated()@CheckResult() FutureTarget<File> downloadOnly(int width, int height)
Loads the original unmodified data into the cache and returns a that can be used to retrieve the cache File containing the data.
- Parameters:
width- The width in pixels to use to fetch the data.height- The height in pixels to use to fetch the data.
-
-
-
-