I've a custom Loader, DataFetcher and LoaderFactory to load images from a NDK library. Then I create a signature to cache the data so it loads fast to the user.
However, I want to have the following behavior:
1. Load the cached image if available
2. Get the image from remote
3. Load the new image and save it to cache
Here's my current implementation:
GlideApp.with(imageView)
.load(customObject)
.downsample(DownsampleStrategy.CENTER_INSIDE)
.error(R.drawable.img_error)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(this)
That only shows me the cached image, and if there's none, then it gets it from remote and caches it.
Related
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
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.
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!
Picasso.with(getApplicationContext())
.load(image_url)
.noFade()
.networkPolicy(NetworkPolicy.OFFLINE)
.into(_imgview);
This is my code with the call back I have written. Since this is horizontal listview of images it is loading previously cached image when next image has to load.
Here image is not cached so program calls error and I will load from network. In other case I am checking if it is cached then I will load from cache itself else network.
It is not triggering success or error ?
I don't know what's happening ?
In documentation in written that picasso caches images downloaded , but i havent seen an example how to call that image again from cache.
Here i first time load the image :
Picasso.with(getActivity())
.load(thirdArticle.getImageURL())
.resize(200, 150)
.centerCrop()
.into(mainThreeArticleImage);
Second time when i call same code above it shouldnt get from cache ???
If not, how to call cached images by that url ??
Picasso automatically caches the loaded images, So that next time they will be loaded from the cache. You can check whether the image is loaded from the web, cache or disk by enabling the indicator
Picasso.get().setIndicatorsEnabled(true);
Indicators will be shown for each image, specifying where the image is loaded from.
I got the reference from here
Its been sometime I started using Picasso for Image Loading in Android. The usual scenario is , it downloads images and cache it and if later needed it retrieves from Cache.
just found this use case,
if the ImageURL ends with .(jpg,png, etc etc .....)
Ex:http://www.androidguys.com/wp-content/uploads/2014/07/android-for-wallpaper-8.png
Picasso work as expected ,
but if the imageURL's are of type
http://cloud.clubsalive.com.au/download/33/404e58cf-d890-4eaa-981e-c2f3442f9348
then its not reloading from cache , its downloading every time when the view is loaded.
Is it a normal behavior of Picasso ???
Your image is giant. Try to increase cache size. Or scale down your image
I want to display only those images that were loaded into cache memory once we downloaded from url using Universal Image Loader
Example
I have 15 URLS to download image and display inViewPager, but out of them only 5 were downloaded and i closed the app.. Now i don't have any internet connection to get all the other images from web, but app will show only 5 images and remaining pages will be blank..
Is is possible to get the list of only those images from cache Memory??
How can we restrict ViewPager from other blank pages?
I have successfully implemented Universal Image Loader, but got stuck on these issues.
Any idea/suggestion/sample would be appreciated..
Thanks
You can define whether image was cached on disc using disc cache:
File cachedImage = imageLoader.getDiscCache().get(imageUrl);
if (cachedImage.exists()) {
/// image is cached
}
You can check every image URL, define which images are cached and configure ViewPager appropriately.