Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using RequestOptions in AppGlideModule with Glide 4

I used the `Glide library with AppGlideModule, version of library 4.1.1. Here is my glide module class:

@GlideModule
public class GlideUtil extends AppGlideModule {

    private final int IMAGE_CACHE_SIZE = 20 * 1024 * 1024; // 20 MB
    private final String IMAGE_FOLDER = "/User/Images";

    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        RequestOptions requestOptions = new RequestOptions();
        requestOptions.format(DecodeFormat.PREFER_ARGB_8888);
        requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL);
        builder.setDefaultRequestOptions(requestOptions);
        InternalCacheDiskCacheFactory factory = new InternalCacheDiskCacheFactory(context, IMAGE_FOLDER, IMAGE_CACHE_SIZE);
        builder.setDiskCache(factory);

    }

    @Override
    public boolean isManifestParsingEnabled() {
        return false;
    }

This code worked successfully. But when i updated version of glide library to 4.3.1

compile 'com.github.bumptech.glide:glide:4.3.1' 
annotationProcessor 'com.github.bumptech.glide:compiler:4.3.1'

in GlideUtil class i saw messages: "The result of format is not used", "The result of diskCacheStrategyis not used":

enter image description here

So, how to resolve this? And do the methods diskCacheStrategy and format work on Glide 4.3.1 ?

like image 287
Alex D. Avatar asked Nov 13 '17 13:11

Alex D.


People also ask

What is placeholder Glide?

Placeholders are Drawables that are shown while a request is in progress.


1 Answers

The problem is, that you are not using the builder object, that is returned by format(), thus your actions become pointless, that's why lint warns you. You can see that method annotated with @CheckResult, that's how lint understands, that you are on a wrong way, because you are "not checking the result" returned by that method.

Instead perform following:


    RequestOptions requestOptions = new RequestOptions();
    requestOptions = requestOptions.format(DecodeFormat.PREFER_ARGB_8888);
    requestOptions = requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL);

Now the warning would be gone.

Or you may perform following directly:


    builder.setDefaultRequestOptions(new RequestOptions()
                                        .format(DecodeFormat.PREFER_ARGB_8888)
                                        .diskCacheStrategy(DiskCacheStrategy.ALL));

like image 183
azizbekian Avatar answered Oct 05 '22 05:10

azizbekian