Skip to content

Commit 5de6771

Browse files
authored
Merge pull request #6166 from networkException/autoplay-animated-images
[Feature] Add the option to autoplay animated images
2 parents bd2cd3a + fedc637 commit 5de6771

File tree

11 files changed

+48
-4
lines changed

11 files changed

+48
-4
lines changed

changelog.d/6166.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add settings switch to allow autoplaying animated images

vector/src/main/java/im/vector/app/core/resources/UserPreferencesProvider.kt

+4
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@ class UserPreferencesProvider @Inject constructor(private val vectorPreferences:
5656
fun showLiveSenderInfo(): Boolean {
5757
return vectorPreferences.showLiveSenderInfo()
5858
}
59+
60+
fun autoplayAnimatedImages(): Boolean {
61+
return vectorPreferences.autoplayAnimatedImages()
62+
}
5963
}

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import org.matrix.android.sdk.api.session.Session
3232
import org.matrix.android.sdk.api.session.crypto.verification.VerificationState
3333
import org.matrix.android.sdk.api.session.events.model.EventType
3434
import org.matrix.android.sdk.api.session.events.model.content.EncryptedEventContent
35+
import org.matrix.android.sdk.api.session.events.model.getMsgType
3536
import org.matrix.android.sdk.api.session.events.model.isAttachmentMessage
3637
import org.matrix.android.sdk.api.session.events.model.toModel
3738
import org.matrix.android.sdk.api.session.room.model.ReferencesAggregatedContent
@@ -119,6 +120,7 @@ class MessageInformationDataFactory @Inject constructor(private val session: Ses
119120
isLastFromThisSender = isLastFromThisSender,
120121
e2eDecoration = e2eDecoration,
121122
sendStateDecoration = sendStateDecoration,
123+
messageType = event.root.getMsgType()
122124
)
123125
}
124126

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ class MessageItemAttributesFactory @Inject constructor(
6767
threadSummaryFormatted = displayableEventFormatter.formatThreadSummary(threadDetails?.threadSummaryLatestEvent).toString(),
6868
threadDetails = threadDetails,
6969
reactionsSummaryEvents = reactionsSummaryEvents,
70-
areThreadMessagesEnabled = preferencesProvider.areThreadMessagesEnabled()
70+
areThreadMessagesEnabled = preferencesProvider.areThreadMessagesEnabled(),
71+
autoplayAnimatedImages = preferencesProvider.autoplayAnimatedImages()
7172
)
7273
}
7374
}

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
188188
val threadSummaryFormatted: String? = null,
189189
val threadDetails: ThreadDetails? = null,
190190
val areThreadMessagesEnabled: Boolean = false,
191+
val autoplayAnimatedImages: Boolean = false,
191192
override val reactionsSummaryEvents: ReactionsSummaryEvents? = null,
192193
) : AbsBaseMessageItem.Attributes {
193194

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt

+12-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import im.vector.app.features.home.room.detail.timeline.helper.ContentUploadStat
3434
import im.vector.app.features.home.room.detail.timeline.style.TimelineMessageLayout
3535
import im.vector.app.features.home.room.detail.timeline.style.granularRoundedCorners
3636
import im.vector.app.features.media.ImageContentRenderer
37+
import org.matrix.android.sdk.api.session.room.model.message.MessageType
3738

3839
@EpoxyModelClass(layout = R.layout.item_timeline_event_base)
3940
abstract class MessageImageVideoItem : AbsMessageItem<MessageImageVideoItem.Holder>() {
@@ -80,7 +81,17 @@ abstract class MessageImageVideoItem : AbsMessageItem<MessageImageVideoItem.Hold
8081
ViewCompat.setTransitionName(holder.imageView, "imagePreview_${id()}")
8182
holder.mediaContentView.onClick(attributes.itemClickListener)
8283
holder.mediaContentView.setOnLongClickListener(attributes.itemLongClickListener)
83-
holder.playContentView.visibility = if (playable) View.VISIBLE else View.GONE
84+
85+
val isImageMessage = attributes.informationData.messageType == MessageType.MSGTYPE_IMAGE
86+
val autoplayAnimatedImages = attributes.autoplayAnimatedImages
87+
88+
holder.playContentView.visibility = if (playable && isImageMessage && autoplayAnimatedImages) {
89+
View.GONE
90+
} else if (playable) {
91+
View.VISIBLE
92+
} else {
93+
View.GONE
94+
}
8495
}
8596

8697
override fun unbind(holder: Holder) {

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageInformationData.kt

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ data class MessageInformationData(
4343
val sendStateDecoration: SendStateDecoration = SendStateDecoration.NONE,
4444
val isFirstFromThisSender: Boolean = false,
4545
val isLastFromThisSender: Boolean = false,
46+
val messageType: String? = null
4647
) : Parcelable {
4748

4849
val matrixItem: MatrixItem

vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt

+7-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import im.vector.app.core.glide.GlideRequest
4141
import im.vector.app.core.glide.GlideRequests
4242
import im.vector.app.core.ui.model.Size
4343
import im.vector.app.core.utils.DimensionConverter
44+
import im.vector.app.features.settings.VectorPreferences
4445
import kotlinx.parcelize.Parcelize
4546
import org.matrix.android.sdk.api.extensions.tryOrNull
4647
import org.matrix.android.sdk.api.session.content.ContentUrlResolver
@@ -67,7 +68,8 @@ private const val URL_PREVIEW_IMAGE_MIN_FULL_HEIGHT_PX = 315
6768

6869
class ImageContentRenderer @Inject constructor(private val localFilesHelper: LocalFilesHelper,
6970
private val activeSessionHolder: ActiveSessionHolder,
70-
private val dimensionConverter: DimensionConverter) {
71+
private val dimensionConverter: DimensionConverter,
72+
private val vectorPreferences: VectorPreferences) {
7173

7274
@Parcelize
7375
data class Data(
@@ -133,7 +135,10 @@ class ImageContentRenderer @Inject constructor(private val localFilesHelper: Loc
133135
imageView.contentDescription = data.filename
134136

135137
createGlideRequest(data, mode, imageView, size)
136-
.dontAnimate()
138+
.let {
139+
if (vectorPreferences.autoplayAnimatedImages()) it
140+
else it.dontAnimate()
141+
}
137142
.transform(cornerTransformation)
138143
// .thumbnail(0.3f)
139144
.into(imageView)

vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt

+10
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class VectorPreferences @Inject constructor(
105105
private const val SETTINGS_SHOW_EMOJI_KEYBOARD = "SETTINGS_SHOW_EMOJI_KEYBOARD"
106106
private const val SETTINGS_LABS_ENABLE_LATEX_MATHS = "SETTINGS_LABS_ENABLE_LATEX_MATHS"
107107
const val SETTINGS_PRESENCE_USER_ALWAYS_APPEARS_OFFLINE = "SETTINGS_PRESENCE_USER_ALWAYS_APPEARS_OFFLINE"
108+
const val SETTINGS_AUTOPLAY_ANIMATED_IMAGES = "SETTINGS_AUTOPLAY_ANIMATED_IMAGES"
108109

109110
// Room directory
110111
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(
773774
return defaultPrefs.getBoolean(SETTINGS_ALWAYS_SHOW_TIMESTAMPS_KEY, false)
774775
}
775776

777+
/**
778+
* Tells if animated image attachments should automatically play their animation in the timeline.
779+
*
780+
* @return true if animated image attachments should automatically play their animation in the timeline
781+
*/
782+
fun autoplayAnimatedImages(): Boolean {
783+
return defaultPrefs.getBoolean(SETTINGS_AUTOPLAY_ANIMATED_IMAGES, false)
784+
}
785+
776786
/**
777787
* Tells if the typing notifications should be sent.
778788
*

vector/src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,8 @@
973973
<string name="settings_show_read_receipts_summary">Click on the read receipts for a detailed list.</string>
974974
<string name="settings_chat_effects_title">Show chat effects</string>
975975
<string name="settings_chat_effects_description">Use /confetti command or send a message containing ❄️ or 🎉</string>
976+
<string name="settings_autoplay_animated_images_title">Autoplay animated images</string>
977+
<string name="settings_autoplay_animated_images_summary">Play animated images in the timeline as soon as they are visible</string>
976978
<string name="settings_show_join_leave_messages">Show join and leave events</string>
977979
<string name="settings_show_join_leave_messages_summary">Invites, removes, and bans are unaffected.</string>
978980
<string name="settings_show_avatar_display_name_changes_messages">Show account events</string>

vector/src/main/res/xml/vector_settings_preferences.xml

+6
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@
140140
android:summary="@string/settings_chat_effects_description"
141141
android:title="@string/settings_chat_effects_title" />
142142

143+
<im.vector.app.core.preference.VectorSwitchPreference
144+
android:defaultValue="false"
145+
android:key="SETTINGS_AUTOPLAY_ANIMATED_IMAGES"
146+
android:summary="@string/settings_autoplay_animated_images_summary"
147+
android:title="@string/settings_autoplay_animated_images_title" />
148+
143149
<im.vector.app.core.preference.VectorSwitchPreference
144150
android:key="SETTINGS_VIBRATE_ON_MENTION_KEY"
145151
android:title="@string/settings_vibrate_on_mention"

0 commit comments

Comments
 (0)