From f86362f0651dbea9b82c759fa221ace78ef4ba9a Mon Sep 17 00:00:00 2001 From: networkException Date: Thu, 26 May 2022 17:26:27 +0200 Subject: [PATCH] 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" /> + +