I'm using MaterialDrawer library and loading profile images with Picasso. But I am unable to save it locally with Picasso and loading it from cache in the future.
Before creating the drawer,
//below line is for loading profile image from url
DrawerImageLoader.init(new DrawerImageLoader.IDrawerImageLoader() {
@Override
public void set(ImageView imageView, Uri uri, Drawable placeholder) {
Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
}
@Override
public void cancel(ImageView imageView) {
Picasso.with(imageView.getContext()).cancelRequest(imageView);
}
@Override
public Drawable placeholder(Context ctx) {
return null;
}
});
I wrote this as material library says. Then I set my profile picture:
String myURL = "http://www.american.edu/uploads/profiles/large/chris_palmer_profile_11.jpg"
profile = new ProfileDrawerItem().withName(person.getFullName()).withEmail(person.getStMajorName()).withIcon(myURL)
But everytime I run the app, it loads it from the internet.
How can I cache the image?
By default
Picasso
comes with a default implementation which are suitable for most usecases.There are various solutions which allow you to force
Picasso
to load the images from the cache. Or to change this behavior.You should check out the following StackOverFlow question which come with different solutions to your issue:
How do I use disk caching in Picasso?