1
votes

I have RecyclerView where image load from server URL. so I use Glide library to load an image, glide store image into cache to reload as fast as possible. I use a placeholder() as a loader for loading image first time, but if I off the internet and start app its still load placeholder first and then load an image into ImageView. So, my question is, is there any way to load an image into ImageView so user experience like smoothness (offline) app while loading images

Glide.with(context)
        .load(www.abc.com/abcd.jpg)
        .placeholder(R.drawable.placeholder)          
        .into(viewHolder.ivSleepImage)

you can check this app Walking UP it loads image first time than there is no loader, and next time when image load means when you open app image already loaded in list.

Please somebody help me to achieve this task

2
try adding .diskCacheStrategy(DiskCacheStrategy.ALL)Lakhwinder Singh
already try val requestOptions = RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.ALL) still not worked for meP A Gosai

2 Answers

0
votes

There are 2 ways you can do that task but it can be very lengthy because storing and loading is not the way to approach in the android development

1.Store the data in the cache

2.store data in the database

the cache strategy is relatively easy. as you are requesting the data from the server if the connection is not available then you have to load data from the cache. Same can be said from the database but it is very lengthy and can be very slow.

0
votes

A quick solution to your problem would be to add diskCacheStrategy to your Glide call. This would help you cache ALL versions of your image and thus reduce load-time. Here's an implementation:

Glide.with(context)
    .load(www.abc.com/abcd.jpg)
    .placeholder(R.drawable.placeholder)          
    .into(viewHolder.ivSleepImage)
    .diskCacheStrategy(DiskCacheStrategy.ALL)

I hope this helps. Merry coding!