From 9fb0eee532995a0ed9e8d4ad620267feb510df9c Mon Sep 17 00:00:00 2001 From: Alex Maras Date: Sun, 12 Feb 2023 16:42:24 +0800 Subject: [PATCH 1/7] fix: add webp as playable image type --- .../src/main/java/org/matrix/android/sdk/api/util/MimeTypes.kt | 1 + .../home/room/detail/timeline/factory/MessageItemFactory.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/MimeTypes.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/MimeTypes.kt index 5ec0dedadf5..af8ab71a87d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/MimeTypes.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/MimeTypes.kt @@ -30,6 +30,7 @@ object MimeTypes { const val BadJpg = "image/jpg" const val Jpeg = "image/jpeg" const val Gif = "image/gif" + const val Webp = "image/webp" const val Ogg = "audio/ogg" 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 67983fc351a..f84b81c70f8 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 @@ -509,7 +509,7 @@ class MessageItemFactory @Inject constructor( allowNonMxcUrls = informationData.sendState.isSending() ) - val playable = messageContent.mimeType == MimeTypes.Gif + val playable = messageContent.mimeType == MimeTypes.Gif || messageContent.mimeType == MimeTypes.Webp return MessageImageVideoItem_() .attributes(attributes) From 3b7aaf2b811ecb2d19d9e42ec00044da3e671071 Mon Sep 17 00:00:00 2001 From: Alex Maras Date: Sun, 12 Feb 2023 17:03:06 +0800 Subject: [PATCH 2/7] fix: make glide transformations optional to prevent rendering webp throwing exception --- .../im/vector/app/features/media/ImageContentRenderer.kt | 6 +++--- 1 file changed, 3 insertions(+), 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 baad815df24..876812cea04 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 @@ -135,7 +135,7 @@ class ImageContentRenderer @Inject constructor( if (mode == Mode.ANIMATED_THUMBNAIL) it else it.dontAnimate() } - .transform(cornerTransformation) + .optionalTransform(cornerTransformation) .into(imageView) } @@ -167,7 +167,7 @@ class ImageContentRenderer @Inject constructor( } req - .fitCenter() + .optionalFitCenter() .into(target) } @@ -211,7 +211,7 @@ class ImageContentRenderer @Inject constructor( return false } }) - .fitCenter() + .optionalFitCenter() .into(imageView) } From 56f541ccc8600677238fcf0fea5b1c373dcbdcc4 Mon Sep 17 00:00:00 2001 From: Alex Maras Date: Sun, 12 Feb 2023 17:40:46 +0800 Subject: [PATCH 3/7] chore: add changelog.d file --- changelog.d/8120.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/8120.feature diff --git a/changelog.d/8120.feature b/changelog.d/8120.feature new file mode 100644 index 00000000000..906ec2b819f --- /dev/null +++ b/changelog.d/8120.feature @@ -0,0 +1 @@ +Marks WebP files as Animated and allows them to play From 62c35400bb75d50a0e92c70e956c54132f1493bf Mon Sep 17 00:00:00 2001 From: Alex Maras Date: Sun, 12 Feb 2023 17:44:43 +0800 Subject: [PATCH 4/7] sign-off Signed-off-by: Alex Maras From 2a557e2cb11d9f62283f9748d5b53c4ed3a88570 Mon Sep 17 00:00:00 2001 From: Alex Maras Date: Wed, 22 Feb 2023 18:12:05 +0800 Subject: [PATCH 5/7] fix: stop marking webp as playable by default --- .../home/room/detail/timeline/factory/MessageItemFactory.kt | 2 +- 1 file changed, 1 insertion(+), 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 f84b81c70f8..67983fc351a 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 @@ -509,7 +509,7 @@ class MessageItemFactory @Inject constructor( allowNonMxcUrls = informationData.sendState.isSending() ) - val playable = messageContent.mimeType == MimeTypes.Gif || messageContent.mimeType == MimeTypes.Webp + val playable = messageContent.mimeType == MimeTypes.Gif return MessageImageVideoItem_() .attributes(attributes) From 1827038d9e5137a24f023530debc8c14d31b57b8 Mon Sep 17 00:00:00 2001 From: Alex Maras Date: Wed, 22 Feb 2023 21:22:44 +0800 Subject: [PATCH 6/7] fix: play animated Webp in attachment view --- .../im/vector/app/features/media/DataAttachmentRoomProvider.kt | 2 +- .../vector/app/features/media/RoomEventsAttachmentProvider.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/media/DataAttachmentRoomProvider.kt b/vector/src/main/java/im/vector/app/features/media/DataAttachmentRoomProvider.kt index 0924532bc2a..a0354f3d60e 100644 --- a/vector/src/main/java/im/vector/app/features/media/DataAttachmentRoomProvider.kt +++ b/vector/src/main/java/im/vector/app/features/media/DataAttachmentRoomProvider.kt @@ -49,7 +49,7 @@ class DataAttachmentRoomProvider( return getItem(position).let { when (it) { is ImageContentRenderer.Data -> { - if (it.mimeType == MimeTypes.Gif) { + if (it.mimeType == MimeTypes.Gif || it.mimeType == MimeTypes.Webp) { AttachmentInfo.AnimatedImage( uid = it.eventId, url = it.url ?: "", diff --git a/vector/src/main/java/im/vector/app/features/media/RoomEventsAttachmentProvider.kt b/vector/src/main/java/im/vector/app/features/media/RoomEventsAttachmentProvider.kt index e18a13a3e63..f833a33b878 100644 --- a/vector/src/main/java/im/vector/app/features/media/RoomEventsAttachmentProvider.kt +++ b/vector/src/main/java/im/vector/app/features/media/RoomEventsAttachmentProvider.kt @@ -71,7 +71,7 @@ class RoomEventsAttachmentProvider( allowNonMxcUrls = it.root.sendState.isSending() ) - if (content.mimeType == MimeTypes.Gif) { + if (content.mimeType == MimeTypes.Gif || content.mimeType == MimeTypes.Webp) { AttachmentInfo.AnimatedImage( uid = it.eventId, url = content.url ?: "", From b3511e21014b8fe37fde4821b7f5de977745a665 Mon Sep 17 00:00:00 2001 From: Alex Maras Date: Wed, 22 Feb 2023 21:33:46 +0800 Subject: [PATCH 7/7] feat: autoplay webp if autoplay is enabled --- .../home/room/detail/timeline/factory/MessageItemFactory.kt | 4 +++- 1 file changed, 3 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 09b91cc4f15..5f8883fdfe9 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 @@ -528,6 +528,8 @@ class MessageItemFactory @Inject constructor( ) val playable = messageContent.mimeType == MimeTypes.Gif + // don't show play button because detecting animated webp isn't possible via mimetype + val playableIfAutoplay = playable || messageContent.mimeType == MimeTypes.Webp return MessageImageVideoItem_() .attributes(attributes) @@ -549,7 +551,7 @@ class MessageItemFactory @Inject constructor( } } }.apply { - if (playable && vectorPreferences.autoplayAnimatedImages()) { + if (playableIfAutoplay && vectorPreferences.autoplayAnimatedImages()) { mode(ImageContentRenderer.Mode.ANIMATED_THUMBNAIL) } }