glide icon indicating copy to clipboard operation
glide copied to clipboard

First and last item in list not shown

Open lunf opened this issue 12 years ago • 8 comments

Hi,

I have a list of 7 items, if I move to see the last item, the first item is not visible on screen. When I move up to view the first item, the image is gone, place holder is not set and image will not appear again.

Thanks

lunf avatar Jun 13 '14 03:06 lunf

Hmm, can you share any code or a sample app that demonstrates this? I totally believe you're seeing it, but it's hard to tell what might be going wrong without seeing code. At a minimum can you paste the Glide.load line you're using the xml of the view you're trying to load into? Thanks!

sjudd avatar Jun 13 '14 20:06 sjudd

Also this sounds very similar to https://github.com/bumptech/glide/issues/74, does it sound similar to what you're seeing to you? If so, if you try disabling the memory cache or setting its size to 0, does that fix your issue too?

sjudd avatar Jun 15 '14 15:06 sjudd

Ok, let me try your recommendations.

Thanks

lunf avatar Jun 15 '14 15:06 lunf

Here is the code that I have tried to turn off cached, but it won't work.

YouTube link to demo the issue (sorry for bg noise): http://youtu.be/Q7GYlX8HMK4

Glide glide = Glide.get();

if (!glide.isImageManagerSet()) {

    ImageManager imageManager = new ImageManager.Builder(getContext())
            .disableMemoryCache()
            .disableDiskCache()
            .disableBitmapRecycling()
            .build();

    glide.setImageManager(imageManager);
}


glide.load(optimzedImageUrl)
        .placeholder(R.drawable.thumbnail_small)
        .animate(R.anim.fade_in)
        .into(this);

Let me know If I done incorrectly.

Thanks

lunf avatar Jun 15 '14 16:06 lunf

Everything you've posted looks correct. Can you show any more of your code around the Glide.load call? It looks like you may be sometimes calling setImageResource or setImageDrawable on your view directly? Maybe to clear out the current image? Does the problem go away if you add Glide.cancel(yourView) the line before your Glide.load call?

sjudd avatar Jun 15 '14 17:06 sjudd

The Glide.cancel(myView) correct the issue.

Class structure:

  • CatalogueActivity --- CatalogueFagment ------ CatalogueItemAdapter

In CatalogueItemAdapter

In my code, AsyncImageView extends the ImageView, then

  • Option 1 can be applied
  • Option 2 is used to test (code copied from Option 1)

However, the result is identical in both options.

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    final ProductViewHolder viewHolder;

    ...

    viewHolder = new ProductDetailsViewHolder();

    viewHolder.textDescriptionView = (TextView) convertView
                .findViewById(R.id.product_catalogue_item_description);

    viewHolder.imageView = (AsyncImageView) convertView.findViewById(R.id.product_catalogue_item_image);

    ...

    if (items.get(position).getImage() != null && items.get(position).getImage().length() > 0) {

        // Option 1
        viewHolder.imageView.loadImageFromUrl(itemData.getImage());


        //Option 2
        Glide glide = Glide.get();


        if (!glide.isImageManagerSet()) {
            ImageManager imageManager = new ImageManager.Builder(context)
                    .disableMemoryCache()
                    .disableDiskCache()
                    .disableBitmapRecycling()
                    .build();

            glide.setImageManager(imageManager);
        }


        glide.load(itemData.getImage())
                .placeholder(R.drawable.thumbnail_small)
                .animate(R.anim.fade_in)
                .into(viewHolder.imageView);

    } else {
        // if server return image is null, display no image
        viewHolder.imageView.setImageResource(R.drawable.thumbnail_small);
    }

}

lunf avatar Jun 15 '14 17:06 lunf

Ok makes sense that using Glide.cancel fixes the issue. Basically you need to call Glide.cancel any time you want to set any content on the view yourself. Calling cancel first will make sure you clear out any old metadata which both prevents old loads from unexpectedly replacing whatever you set manually on the image view as well as ensuring that any new request you make will complete successfully.

In your case, either option 1 or option 2 is fine, but in the else statement change

}  else {
     // if server return image is null, display no image
     viewHolder.imageView.setImageResource(R.drawable.thumbnail_small);
}

to:

} else { 
    // if server return image is null, display no image
    Glide.cancel(viewHolder.imageView);
    viewHolder.imageView.setImageResource(R.drawable.thumbnail_small);
}

You can also remove the Glide.setup call, you don't need to disable bitmap recycling or any of the caches.

I'm going to push a new 2.x version that allows null urls and just shows the placeholder when it receives a null url.

sjudd avatar Jun 15 '14 19:06 sjudd

I believe this was fixed here: https://github.com/bumptech/glide/commit/63af4bec9ed53559e4fd1b39d286fe125a69f364

sjudd avatar Jun 19 '14 14:06 sjudd