How to upload an image using volleyball and store in the cache until the image is used

I am using the volley library to download network responses. I know that volleyball downloads images only when necessary. But I want to download all the images in one go and save in my cache.

So, basically I want to download all the images at once and save them in the cache, so if there is no interenet, the user will also be able to see all the images.

I can store images in cache using my own LruBitmapCacheclass. And for uploading images I use the 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 works great when uploading images and storing in cache. But this is only loading images that are on my main screen.

, ,

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());
  }

}

, ImageView. , . , , ?

:

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);
    }
}

, LRUCache ? ? Thnaks.

+4
1

volley imageloader..

imageLoader.get(data.getImages().getSmallImage(), new ImageLoader.ImageListener() {
        @Override
        public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {

        }

        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });

imageloader volley singleton class. imagelistener.

+1

All Articles