Glide Version:
Verson 4.4.0
Integration libraries:
No
Device/Android Version:
Galaxy tab A
Issue details / Repro steps / Use case background:
so im rendering the images in a recyclerView.
but when scrolling down instead of only showing the progress dialog to wait the image to load, it is showing the previous loaded imagens. sometimes it takes a few seconds till the new image shows. Therefore staying with the wrong image for the wrong product.
Glide load line / GlideModule (if any) / list Adapter code (if any):
protected void handleImage(final ProductsViewHolder viewHolder, Product item) {
final String coverImage = item.getCoverImage();
boolean loadImage = false;
if (viewHolder.lastImageLoaded == null) {
loadImage = true;
} else if (!viewHolder.lastImageLoaded.equalsIgnoreCase(coverImage)) {
loadImage = true;
}
if (loadImage) {
if (viewHolder.imageProgress != null) {
viewHolder.imageProgress.setVisibility(View.VISIBLE);
}
if (viewHolder.image != null) {
GlideApp.with(UbookApp.getInstance())
.asBitmap()
.load(UiUtils.getImageUrlFromNameAndSize(coverImage, context.getResources().getInteger(R.integer.product_list_cover_image_size), context.getResources().getInteger(R.integer.product_list_cover_image_size)))
.error(R.drawable.ic_image_not_available)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition transition) {
viewHolder.image.setImageBitmap(resource);
viewHolder.imageProgress.setVisibility(View.GONE);
viewHolder.image.setVisibility(View.VISIBLE);
viewHolder.lastImageLoaded = coverImage;
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
viewHolder.image.setImageDrawable(null);
viewHolder.imageProgress.setVisibility(View.GONE);
viewHolder.image.setVisibility(View.VISIBLE);
viewHolder.lastImageLoaded = "";
}
});
}
}
}
Glide.with...
GlideApp.with(UbookApp.getInstance())
.asBitmap()
.load(UiUtils.getImageUrlFromNameAndSize(coverImage, context.getResources().getInteger(R.integer.product_list_cover_image_size), context.getResources().getInteger(R.integer.product_list_cover_image_size)))
.error(R.drawable.ic_image_not_available)
.into(new SimpleTarget
@Override
public void onResourceReady(Bitmap resource, Transition transition) {
viewHolder.image.setImageBitmap(resource);
viewHolder.imageProgress.setVisibility(View.GONE);
viewHolder.image.setVisibility(View.VISIBLE);
viewHolder.lastImageLoaded = coverImage;
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
viewHolder.image.setImageDrawable(null);
viewHolder.imageProgress.setVisibility(View.GONE);
viewHolder.image.setVisibility(View.VISIBLE);
viewHolder.lastImageLoaded = "";
}
});
}
Layout XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.rey.material.widget.ProgressView
android:id="@+id/imageProgress"
android:layout_width="30dp"
android:layout_height="30dp"
app:pv_autostart="true"
app:pv_progressStyle="@style/Widget.Ubook.ProgressView.Image"
app:pv_circular="true"
app:pv_progressMode="indeterminate"
android:layout_gravity="center" />
<ImageView
android:id="@+id/image"
android:layout_width="60dp"
android:layout_height="60dp"
android:visibility="gone" />
</FrameLayout>```
<!--
What is the error message that you got in the log?
You can find some help on diagnosing issues here: https://github.com/bumptech/glide/wiki/Debugging-and-Error-Handling
-->
**Stack trace / LogCat**:
```ruby
no error msg
See http://bumptech.github.io/glide/doc/getting-started.html#listview-and-recyclerview. You're not clearing previous loads in a number of cases.
You're also not clearing out the view in onLoadCleared in SimpleTarget. Why aren't you using a normal ViewTarget?
Hi @sjudd,
We work together, and we show a loading animation when the image start load, set the placeholder on image and when load finish or error happens we need hide the animation and show the error image.
With the default target we cant access other componentes to hide/show it, so, we need use the SimpleTarget.
Thanks.
This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.
Can be closed. It was solved. Thanks.
Glad it was fixed. Just FYI, you can subclass ViewTarget or any of the existing ViewTargets and get access to exactly the same set of methods that you can on SimpleTarget.
@prsolucoes how did you resolve this issue, I'm currently having same problem and tried all the Stackoverflow thread I could find but still no solution.
Can be closed. It was solved. Thanks.
How did you solved?
Most helpful comment
@prsolucoes how did you resolve this issue, I'm currently having same problem and tried all the Stackoverflow thread I could find but still no solution.