I'm showing a list of users in a recycleview/listview.
Each item shows user image and other information. I'm having user image urls as
ThumbNail : www.image_storage_server.com/thumbs/userid
FullImage : www.image_storage_server.com/images/userid
I want to show this thumbnails in list item. It should work as below
- Download the image and show it in list.
- Cache the downloaded image. And use it while loading the image.
- If there's no network, show the cached image.
Basically i want to load the thumbnails every time, if there's network.
When user clicks on list item, I want to show user's full image.
And while loading , i want to show the cached thumbnail as the default image.
I'm currently using universal-image-loader but i didn't find a way to achieve this.
How to achieve this ?
Is there any other library which provides this kind of functionality ?
Below is my code.
//Initializing imageloader in application's oncreate
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.avatar)
.showImageOnFail(R.drawable.avatar)
.cacheInMemory(true) // default
.cacheOnDisk(true) // default
.build();
ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
config.threadPriority(Thread.NORM_PRIORITY - 2);
config.denyCacheImageMultipleSizesInMemory();
config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
config.tasksProcessingOrder(QueueProcessingType.LIFO);
config.defaultDisplayImageOptions(options);
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config.build());
Loading image using image loader in RecycleAdapter
ImageLoader.getInstance().displayImage(user.getThumbnailUrl(), vh.avatarIV);