diff --git a/vector/src/main/java/im/vector/app/core/ui/views/ReadReceiptsView.kt b/vector/src/main/java/im/vector/app/core/ui/views/ReadReceiptsView.kt index 2ce3396d0c..b1ef746ee7 100644 --- a/vector/src/main/java/im/vector/app/core/ui/views/ReadReceiptsView.kt +++ b/vector/src/main/java/im/vector/app/core/ui/views/ReadReceiptsView.kt @@ -23,7 +23,6 @@ import android.widget.ImageView import android.widget.LinearLayout import androidx.core.view.isVisible import im.vector.app.R -import im.vector.app.core.glide.GlideApp import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.timeline.item.ReadReceiptData import im.vector.app.features.home.room.detail.timeline.item.toMatrixItem @@ -113,9 +112,9 @@ class ReadReceiptsView @JvmOverloads constructor( } } - fun unbind() { + fun unbind(avatarRenderer: AvatarRenderer?) { receiptAvatars.forEach { - GlideApp.with(context.applicationContext).clear(it) + avatarRenderer?.clear(it) } isVisible = false } diff --git a/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt b/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt index f53fa77791..5e1433a6fa 100644 --- a/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt @@ -56,6 +56,11 @@ class AvatarRenderer @Inject constructor(private val activeSessionHolder: Active DrawableImageViewTarget(imageView)) } + fun clear(imageView: ImageView) { + // It can be called after recycler view is destroyed, just silently catch + tryThis { GlideApp.with(imageView).clear(imageView) } + } + @UiThread fun render(matrixItem: MatrixItem, imageView: ImageView, glideRequests: GlideRequests) { render(imageView.context, diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt index 1aec2db9a4..631cd9ff66 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt @@ -110,7 +110,7 @@ abstract class AbsBaseMessageItem : BaseEventItem override fun unbind(holder: H) { holder.reactionsContainer.setOnLongClickListener(null) - holder.readReceiptsView.unbind() + holder.readReceiptsView.unbind(baseAttributes.avatarRenderer) super.unbind(holder) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt index fa216c15a4..7c2a6286b9 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt @@ -77,6 +77,7 @@ abstract class AbsMessageItem : AbsBaseMessageItem } override fun unbind(holder: H) { + attributes.avatarRenderer.clear(holder.avatarImageView) holder.avatarImageView.setOnClickListener(null) holder.avatarImageView.setOnLongClickListener(null) holder.memberNameView.setOnClickListener(null) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/DefaultItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/DefaultItem.kt index e82c4191b9..8cd3c95141 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/DefaultItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/DefaultItem.kt @@ -44,6 +44,12 @@ abstract class DefaultItem : BaseEventItem() { holder.readReceiptsView.render(attributes.informationData.readReceipts, attributes.avatarRenderer, _readReceiptsClickListener) } + override fun unbind(holder: Holder) { + attributes.avatarRenderer.clear(holder.avatarImageView) + holder.readReceiptsView.unbind(attributes.avatarRenderer) + super.unbind(holder) + } + override fun getEventIds(): List { return listOf(attributes.informationData.eventId) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt index 0ad61ce874..be3d276037 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt @@ -68,6 +68,7 @@ abstract class MessageImageVideoItem : AbsMessageItem() { } } + override fun unbind(holder: Holder) { + attributes.avatarRenderer.clear(holder.avatarImageView) + holder.readReceiptsView.unbind(attributes.avatarRenderer) + super.unbind(holder) + } + override fun getEventIds(): List { return listOf(attributes.informationData.eventId) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItem.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItem.kt index ce572ed96d..4cac11af21 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItem.kt @@ -82,6 +82,7 @@ abstract class RoomSummaryItem : VectorEpoxyModel() { override fun unbind(holder: Holder) { holder.rootView.setOnClickListener(null) holder.rootView.setOnLongClickListener(null) + avatarRenderer.clear(holder.avatarImageView) super.unbind(holder) } diff --git a/vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt b/vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt index 2976f4b4b1..a7d666184d 100644 --- a/vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt @@ -103,6 +103,15 @@ class ImageContentRenderer @Inject constructor(private val activeSessionHolder: .into(imageView) } + fun clear(imageView: ImageView) { + // It can be called after recycler view is destroyed, just silently catch + // We'd better keep ref to requestManager, but we don't have it + tryThis { + GlideApp + .with(imageView).clear(imageView) + } + } + fun render(data: Data, contextView: View, target: CustomViewTarget<*, Drawable>) { val req = if (data.elementToDecrypt != null) { // Encrypted image