Reputation: 5134
I am using volley library to download network responses. I know volley download images when it is needed only. But what I want to achieve is to download all the images at a time and store in my cache memory.
So basically I want to download all the images at once and store in cache so if there will no interenet also user can see all the images.
I am able to store images in cache using my own LruBitmapCache
class.And to download images I am using following method
public void downloadImage(NetworkImageView view, MyApplication application, String imageUrl, Context ctx) {
NetworkImageView image = view;
ImageLoader loader = new ImageLoader(application.getRequestQueue(), new LruBitmapCache(
LruBitmapCache.getCacheSize(ctx)));
image.setImageUrl(imageUrl, loader);
}
This is working fine in downloading the images and storing in cache. But it is only downloading images those are in my main screen.
To download all the images I tried following method
public void downloadCoverImages(){
int i = 0;
for(ImageData data: GetData._instance.getImageList()){
NetworkImageView iv = new NetworkImageView(BaseActivity.this);
iv.setLayoutParams(new LinearLayout.LayoutParams(300,150));
GetData._instance.downloadImage(iv, (MyApplication) getApplicationContext(),
data.getImages().getSmallImage(),BaseActivity.this);
//Log.e("Download",++i+" "+data.getImages().getSmallImage());
}
}
But it's not to download an image a proper ImageView is required I guess and that also needs to in main screen. So in this case what should I do?
My singleton class as follows:
public enum GetData {
_instance;
private List<Sections> sectionsList = new ArrayList<Sections>();
private List<DealDetails> dealDetailsList = new ArrayList<DealDetails>();
private DealDetails dealDetails;
public List<Sections> getSectionsList() {
return sectionsList;
}
public void setSectionsList(List<Sections> sectionsList) {
this.sectionsList = sectionsList;
}
public List<DealDetails> getDealDetailsList() {
return dealDetailsList;
}
public void setDealList(List<DealDetails> dealDetailsList) {
this.dealDetailsList = dealDetailsList;
}
public DealDetails getDealDetails() {
return dealDetails;
}
public void setDealDetails(DealDetails dealDetails) {
this.dealDetails = dealDetails;
}
public void downloadImage(NetworkImageView view, MyApplication application, String imageUrl, Context ctx) {
NetworkImageView image = view;
ImageLoader loader = new ImageLoader(application.getRequestQueue(), new LruBitmapCache(
LruBitmapCache.getCacheSize(ctx)));
image.setImageUrl(imageUrl, loader);
}
}
Is it possible if I download image without using volley and store in my LRUCache and show it using volley? Any good tutorial for that? Thnaks.
Upvotes: 4
Views: 4061
Reputation: 1255
you can also get bitmap of remote image using volley imageloader.. in this way you don't need to have imageview and all
imageLoader.get(data.getImages().getSmallImage(), new ImageLoader.ImageListener() {
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
}
@Override
public void onErrorResponse(VolleyError error) {
}
});
get the imageloader instance from volley singleton class. in your case you don't need to handle the imagelistener callbacks ..
Upvotes: 1