From f86362f0651dbea9b82c759fa221ace78ef4ba9a Mon Sep 17 00:00:00 2001 From: networkException Date: Thu, 26 May 2022 17:26:27 +0200 Subject: [PATCH 1/5] VectorPreferences: Add switch for autoplaying animated images This patch adds a new switch to VectorPreferences, the vector settings preferences view and various classes propergating the set value of the switch into parts of the application touched by the following patches. Signed-off-by: networkException --- .../app/core/resources/UserPreferencesProvider.kt | 4 ++++ .../timeline/helper/MessageItemAttributesFactory.kt | 3 ++- .../home/room/detail/timeline/item/AbsMessageItem.kt | 1 + .../vector/app/features/settings/VectorPreferences.kt | 10 ++++++++++ vector/src/main/res/values/strings.xml | 2 ++ .../src/main/res/xml/vector_settings_preferences.xml | 6 ++++++ 6 files changed, 25 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/core/resources/UserPreferencesProvider.kt b/vector/src/main/java/im/vector/app/core/resources/UserPreferencesProvider.kt index d39dcbe318..09bb78c926 100644 --- a/vector/src/main/java/im/vector/app/core/resources/UserPreferencesProvider.kt +++ b/vector/src/main/java/im/vector/app/core/resources/UserPreferencesProvider.kt @@ -56,4 +56,8 @@ class UserPreferencesProvider @Inject constructor(private val vectorPreferences: fun showLiveSenderInfo(): Boolean { return vectorPreferences.showLiveSenderInfo() } + + fun autoplayAnimatedImages(): Boolean { + return vectorPreferences.autoplayAnimatedImages() + } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt index 737b0dc85d..dad0e3e4ed 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt @@ -67,7 +67,8 @@ class MessageItemAttributesFactory @Inject constructor( threadSummaryFormatted = displayableEventFormatter.formatThreadSummary(threadDetails?.threadSummaryLatestEvent).toString(), threadDetails = threadDetails, reactionsSummaryEvents = reactionsSummaryEvents, - areThreadMessagesEnabled = preferencesProvider.areThreadMessagesEnabled() + areThreadMessagesEnabled = preferencesProvider.areThreadMessagesEnabled(), + autoplayAnimatedImages = preferencesProvider.autoplayAnimatedImages() ) } } 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 b9d79d5818..24a148885f 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 @@ -188,6 +188,7 @@ abstract class AbsMessageItem : AbsBaseMessageItem val threadSummaryFormatted: String? = null, val threadDetails: ThreadDetails? = null, val areThreadMessagesEnabled: Boolean = false, + val autoplayAnimatedImages: Boolean = false, override val reactionsSummaryEvents: ReactionsSummaryEvents? = null, ) : AbsBaseMessageItem.Attributes { diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt index 72f6080417..5d5e07ee6b 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt @@ -105,6 +105,7 @@ class VectorPreferences @Inject constructor( private const val SETTINGS_SHOW_EMOJI_KEYBOARD = "SETTINGS_SHOW_EMOJI_KEYBOARD" private const val SETTINGS_LABS_ENABLE_LATEX_MATHS = "SETTINGS_LABS_ENABLE_LATEX_MATHS" const val SETTINGS_PRESENCE_USER_ALWAYS_APPEARS_OFFLINE = "SETTINGS_PRESENCE_USER_ALWAYS_APPEARS_OFFLINE" + const val SETTINGS_AUTOPLAY_ANIMATED_IMAGES = "SETTINGS_AUTOPLAY_ANIMATED_IMAGES" // Room directory private const val SETTINGS_ROOM_DIRECTORY_SHOW_ALL_PUBLIC_ROOMS = "SETTINGS_ROOM_DIRECTORY_SHOW_ALL_PUBLIC_ROOMS" @@ -773,6 +774,15 @@ class VectorPreferences @Inject constructor( return defaultPrefs.getBoolean(SETTINGS_ALWAYS_SHOW_TIMESTAMPS_KEY, false) } + /** + * Tells if animated image attachments should automatically play their animation in the timeline. + * + * @return true if animated image attachments should automatically play their animation in the timeline + */ + fun autoplayAnimatedImages(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_AUTOPLAY_ANIMATED_IMAGES, false) + } + /** * Tells if the typing notifications should be sent. * diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 63d4730dc5..a48d602fbb 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -973,6 +973,8 @@ Click on the read receipts for a detailed list. Show chat effects Use /confetti command or send a message containing ❄️ or 🎉 + Autoplay animated images + Play animated images in the timeline as soon as they are visible Show join and leave events Invites, removes, and bans are unaffected. Show account events diff --git a/vector/src/main/res/xml/vector_settings_preferences.xml b/vector/src/main/res/xml/vector_settings_preferences.xml index 7ff588ca76..1a3c62e0e8 100644 --- a/vector/src/main/res/xml/vector_settings_preferences.xml +++ b/vector/src/main/res/xml/vector_settings_preferences.xml @@ -140,6 +140,12 @@ android:summary="@string/settings_chat_effects_description" android:title="@string/settings_chat_effects_title" /> + + Date: Thu, 26 May 2022 17:27:27 +0200 Subject: [PATCH 2/5] MessageInformationData: Add messageType field This patch adds the messageType field to MessageInformationData, containing a nullable string representation of the message event's type. Signed-off-by: networkException --- .../detail/timeline/helper/MessageInformationDataFactory.kt | 2 ++ .../home/room/detail/timeline/item/MessageInformationData.kt | 1 + 2 files changed, 3 insertions(+) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt index 7874f843e1..7e4ec75783 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt @@ -32,6 +32,7 @@ import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.crypto.verification.VerificationState import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.content.EncryptedEventContent +import org.matrix.android.sdk.api.session.events.model.getMsgType import org.matrix.android.sdk.api.session.events.model.isAttachmentMessage import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.room.model.ReferencesAggregatedContent @@ -119,6 +120,7 @@ class MessageInformationDataFactory @Inject constructor(private val session: Ses isLastFromThisSender = isLastFromThisSender, e2eDecoration = e2eDecoration, sendStateDecoration = sendStateDecoration, + messageType = event.root.getMsgType() ) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageInformationData.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageInformationData.kt index 258424c7de..554dd0ada8 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageInformationData.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageInformationData.kt @@ -43,6 +43,7 @@ data class MessageInformationData( val sendStateDecoration: SendStateDecoration = SendStateDecoration.NONE, val isFirstFromThisSender: Boolean = false, val isLastFromThisSender: Boolean = false, + val messageType: String? = null ) : Parcelable { val matrixItem: MatrixItem From 9d0fe46723f52650859813f91409c32761252d20 Mon Sep 17 00:00:00 2001 From: networkException Date: Thu, 26 May 2022 17:28:42 +0200 Subject: [PATCH 3/5] ImageContentRenderer: Enable image animation if enabled in preferences This patch removes dontAnimate() in the createGlideRequest() builder conditionally depending on the user's animated image autoplay preferences. Resolves #1160, #5094 Signed-off-by: networkException --- .../im/vector/app/features/media/ImageContentRenderer.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 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 49bced7e81..0cd469fa66 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 @@ -41,6 +41,7 @@ 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 @@ -67,7 +68,8 @@ private const val URL_PREVIEW_IMAGE_MIN_FULL_HEIGHT_PX = 315 class ImageContentRenderer @Inject constructor(private val localFilesHelper: LocalFilesHelper, private val activeSessionHolder: ActiveSessionHolder, - private val dimensionConverter: DimensionConverter) { + private val dimensionConverter: DimensionConverter, + private val vectorPreferences: VectorPreferences) { @Parcelize data class Data( @@ -133,7 +135,10 @@ class ImageContentRenderer @Inject constructor(private val localFilesHelper: Loc imageView.contentDescription = data.filename createGlideRequest(data, mode, imageView, size) - .dontAnimate() + .let { + if (vectorPreferences.autoplayAnimatedImages()) it + else it.dontAnimate() + } .transform(cornerTransformation) // .thumbnail(0.3f) .into(imageView) From b138ac8601e9ddc2c20adf2b7b508459e4f9e9e8 Mon Sep 17 00:00:00 2001 From: networkException Date: Thu, 26 May 2022 17:32:16 +0200 Subject: [PATCH 4/5] MessageImageVideoItem: Hide play button for autoplaying animated images This patch updates the logic checking whether to show the playContentView to not show it when an animated image message would autoplay its animation. Signed-off-by: networkException --- .../detail/timeline/item/MessageImageVideoItem.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 8485c40ef9..f3ab0e838b 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 @@ -34,6 +34,7 @@ import im.vector.app.features.home.room.detail.timeline.helper.ContentUploadStat import im.vector.app.features.home.room.detail.timeline.style.TimelineMessageLayout import im.vector.app.features.home.room.detail.timeline.style.granularRoundedCorners import im.vector.app.features.media.ImageContentRenderer +import org.matrix.android.sdk.api.session.room.model.message.MessageType @EpoxyModelClass(layout = R.layout.item_timeline_event_base) abstract class MessageImageVideoItem : AbsMessageItem() { @@ -80,7 +81,17 @@ abstract class MessageImageVideoItem : AbsMessageItem Date: Thu, 26 May 2022 20:08:01 +0200 Subject: [PATCH 5/5] Changelog: Add .feature entry for pull request #6166 Signed-off-by: networkException --- changelog.d/6166.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6166.feature diff --git a/changelog.d/6166.feature b/changelog.d/6166.feature new file mode 100644 index 0000000000..024794bcb3 --- /dev/null +++ b/changelog.d/6166.feature @@ -0,0 +1 @@ +Add settings switch to allow autoplaying animated images