From dccc64384c9f59324c45a1e631edff481667c8a7 Mon Sep 17 00:00:00 2001 From: networkException Date: Tue, 31 May 2022 21:53:47 +0200 Subject: [PATCH 1/3] Implement Mode.ANIMATED_THUMBNAIL used for autoplaying animated images This patch introduces a new `ImageContentRenderer` mode used for autoplaying animated images. The mode shares url resolving semantics with `FULL_SIZE` and `STICKER`, as such not just fetching thumbnail data but shares sizing semantics with `THUMBNAIL` (scaling by image height). This change fixes animated images not playing in cases in which only a static thumbnail would be loaded. This new mode will only be chosen if the message content is actually a playable image, as such limiting bandwith usage to the required amount by avoiding to load normal images fully (still fetching animated images will increase bandwith usage as a whole of course). Signed-off-by: networkException --- .../room/detail/timeline/factory/MessageItemFactory.kt | 9 ++++++++- .../im/vector/app/features/media/ImageContentRenderer.kt | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt index 28e256c064..fece5786fe 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -453,12 +453,15 @@ class MessageItemFactory @Inject constructor( maxWidth = maxWidth, allowNonMxcUrls = informationData.sendState.isSending() ) + + val playable = messageContent.mimeType == MimeTypes.Gif + return MessageImageVideoItem_() .attributes(attributes) .leftGuideline(avatarSizeProvider.leftGuideline) .imageContentRenderer(imageContentRenderer) .contentUploadStateTrackerBinder(contentUploadStateTrackerBinder) - .playable(messageContent.mimeType == MimeTypes.Gif) + .playable(playable) .highlighted(highlight) .mediaData(data) .apply { @@ -472,6 +475,10 @@ class MessageItemFactory @Inject constructor( callback?.onImageMessageClicked(messageContent, data, view, emptyList()) } } + }.apply { + if (playable && vectorPreferences.autoplayAnimatedImages()) { + mode(ImageContentRenderer.Mode.ANIMATED_THUMBNAIL) + } } } 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 74c9b5c6b8..65d37b0d0d 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 @@ -85,6 +85,7 @@ class ImageContentRenderer @Inject constructor( enum class Mode { FULL_SIZE, + ANIMATED_THUMBNAIL, THUMBNAIL, STICKER } @@ -231,6 +232,7 @@ class ImageContentRenderer @Inject constructor( val contentUrlResolver = activeSessionHolder.getActiveSession().contentUrlResolver() val resolvedUrl = when (mode) { Mode.FULL_SIZE, + Mode.ANIMATED_THUMBNAIL, Mode.STICKER -> resolveUrl(data) Mode.THUMBNAIL -> contentUrlResolver.resolveThumbnail(data.url, size.width, size.height, ContentUrlResolver.ThumbnailMethod.SCALE) } @@ -269,6 +271,7 @@ class ImageContentRenderer @Inject constructor( finalHeight = height finalWidth = width } + Mode.ANIMATED_THUMBNAIL, Mode.THUMBNAIL -> { finalHeight = min(maxImageWidth * height / width, maxImageHeight) finalWidth = finalHeight * width / height From 5fede491ee9d7bc0ce449d15b00ccca8e484bde9 Mon Sep 17 00:00:00 2001 From: networkException Date: Tue, 31 May 2022 22:05:05 +0200 Subject: [PATCH 2/3] ImageContentRenderer: Only animate images using ANIMATED_THUMBNAIL mode This patch removes the dependency on `VectorSettings` as well as only enable animated rendering if the image is actually playable. Signed-off-by: networkException --- .../java/im/vector/app/features/media/ImageContentRenderer.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 65d37b0d0d..333b1f0eae 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 @@ -38,7 +38,6 @@ import im.vector.app.core.glide.GlideRequest import im.vector.app.core.glide.GlideRequests import im.vector.app.core.ui.model.Size import im.vector.app.core.utils.DimensionConverter -import im.vector.app.features.settings.VectorPreferences import kotlinx.parcelize.Parcelize import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.content.ContentUrlResolver @@ -65,7 +64,6 @@ class ImageContentRenderer @Inject constructor( private val localFilesHelper: LocalFilesHelper, private val activeSessionHolder: ActiveSessionHolder, private val dimensionConverter: DimensionConverter, - private val vectorPreferences: VectorPreferences ) { @Parcelize @@ -134,7 +132,7 @@ class ImageContentRenderer @Inject constructor( createGlideRequest(data, mode, imageView, size) .let { - if (vectorPreferences.autoplayAnimatedImages()) it + if (mode == Mode.ANIMATED_THUMBNAIL) it else it.dontAnimate() } .transform(cornerTransformation) From 2bca94d92b57987cc61b9a3a32ad5a6e1028a841 Mon Sep 17 00:00:00 2001 From: networkException Date: Tue, 31 May 2022 22:48:17 +0200 Subject: [PATCH 3/3] Changelog: Add .bugfix entry for pull request #6215 Signed-off-by: networkException --- changelog.d/6215.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6215.bugfix diff --git a/changelog.d/6215.bugfix b/changelog.d/6215.bugfix new file mode 100644 index 0000000000..5291d7d604 --- /dev/null +++ b/changelog.d/6215.bugfix @@ -0,0 +1 @@ +Fix animated images not autoplaying sometimes if only a thumbnail was fetched from the server