Search code examples
androidandroid-listviewuniversal-image-loader

Android Universal Image Loader store downloaded progress listview


I am using Universal Image Loader in ListView. My problem is with following usecase:

when I scroll on listview,it works perfectly, and load all images. Lets suppose, I have 2 items on screen in listview, they are in download progress. I can see it's progress by ImageLoadingProgressListener(), as soon as i scroll anywhere and come back to same images, THE PROGRESS STARTS AGAIN, Previously downloaded data lost!! Is there any way to store that downloaded progress so that it can resume that process later when we come back to that image in listview.

Edit: I can cache those images once they downloaded, and also able to use those cached image, My problem is with THAT TIME WHEN THAY ARE BEING DOWNLOADED , SCROLL AND COME BACK.

My DisplayImageOptions:

options =  new DisplayImageOptions.Builder()
                    .displayer(new RoundedBitmapDisplayer(100))
                    .cacheInMemory(true)
                    .cacheOnDisk(true)
                    .considerExifParams(true)
                    .bitmapConfig(Bitmap.Config.RGB_565)
                    .build();

My ImageLoaderConfiguration:

new ImageLoaderConfiguration.Builder(context)
                .threadPriority(Thread.NORM_PRIORITY - 2)
                .denyCacheImageMultipleSizesInMemory()
                .diskCacheFileNameGenerator(new Md5FileNameGenerator())
                .diskCacheSize(50 * 1024 * 1024) // 50 Mb
                .tasksProcessingOrder(QueueProcessingType.LIFO)
                .writeDebugLogs() // Remove for release app
                .build();

My getView():

 @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;

        if(convertView == null){

            convertView = inflater.inflate(R.layout.card, parent,false);

            holder = new ViewHolder();

            holder.ivContent = (ImageView) convertView.findViewById(R.id.ivContent);

            convertView.setTag(holder);
        }
        else{
            holder = (ViewHolder) convertView.getTag();
        }
        try {
            ImageLoader.getInstance().displayImage(url, holder.ivContent, options, new        SimpleImageLoadingListener(){
                @Override
                public void onLoadingComplete(String imageUri, View view,Bitmap loadedImage){
                    holder.ivContent.setVisibility(View.VISIBLE);
                }
            },
            new ImageLoadingProgressListener() {
                @Override
                public void onProgressUpdate(String arg0, View arg1, int count, int total) {
                    System.out.println("prog: "+(count*100)/total);
                    //holder.ivLoaderUp.setClipping((count*100)/total);
                }
            });
         }   
         catch (ParseException e) {
             e.printStackTrace();
         }
        return convertView;
   }

Has anyone run into this problem, Please help.


Solution

  • You can found the answer why loadings are started again - here. UIL abort downloading if there is loaded less than 75% of image data. If you want to change it then you should change the sources of IoUtil class. Change constant from:

    public static final int CONTINUE_LOADING_PERCENTAGE = 75;
    

    to

    public static final int CONTINUE_LOADING_PERCENTAGE = 0;