From c3fe782eb539ddc14a784e34b5a71a82ba557bd3 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Mon, 11 Apr 2022 16:37:33 +0200 Subject: [PATCH] Fixing overlay in bubble mode --- .../timeline/style/TimelineMessageLayout.kt | 27 ++++++------ .../style/TimelineMessageLayoutFactory.kt | 17 ++++++-- .../detail/timeline/view/MessageBubbleView.kt | 42 +++++++++---------- 3 files changed, 48 insertions(+), 38 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/style/TimelineMessageLayout.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/style/TimelineMessageLayout.kt index c0e668e013..ae9b004f6c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/style/TimelineMessageLayout.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/style/TimelineMessageLayout.kt @@ -38,19 +38,20 @@ sealed interface TimelineMessageLayout : Parcelable { @Parcelize data class Bubble( - override val showAvatar: Boolean, - override val showDisplayName: Boolean, - override val showTimestamp: Boolean = true, - val addTopMargin: Boolean = false, - val isIncoming: Boolean, - val isPseudoBubble: Boolean, - val cornersRadius: CornersRadius, - val timestampAsOverlay: Boolean, - override val layoutRes: Int = if (isIncoming) { - R.layout.item_timeline_event_bubble_incoming_base - } else { - R.layout.item_timeline_event_bubble_outgoing_base - }, + override val showAvatar: Boolean, + override val showDisplayName: Boolean, + override val showTimestamp: Boolean = true, + val addTopMargin: Boolean = false, + val isIncoming: Boolean, + val isPseudoBubble: Boolean, + val cornersRadius: CornersRadius, + val timestampInsideMessage: Boolean, + val addMessageOverlay: Boolean, + override val layoutRes: Int = if (isIncoming) { + R.layout.item_timeline_event_bubble_incoming_base + } else { + R.layout.item_timeline_event_bubble_outgoing_base + }, ) : TimelineMessageLayout { @Parcelize diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/style/TimelineMessageLayoutFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/style/TimelineMessageLayoutFactory.kt index 00f86a9a28..f2334e5a4f 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/style/TimelineMessageLayoutFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/style/TimelineMessageLayoutFactory.kt @@ -61,7 +61,7 @@ class TimelineMessageLayoutFactory @Inject constructor(private val session: Sess MessageType.MSGTYPE_EMOTE, MessageType.MSGTYPE_LIVE_LOCATION_STATE, ) - private val MSG_TYPES_WITH_TIMESTAMP_AS_OVERLAY = setOf( + private val MSG_TYPES_WITH_TIMESTAMP_INSIDE_MESSAGE = setOf( MessageType.MSGTYPE_IMAGE, MessageType.MSGTYPE_VIDEO, MessageType.MSGTYPE_LIVE_LOCATION_STATE, @@ -126,7 +126,8 @@ class TimelineMessageLayoutFactory @Inject constructor(private val session: Sess isIncoming = !isSentByMe, cornersRadius = cornersRadius, isPseudoBubble = messageContent.isPseudoBubble(), - timestampAsOverlay = messageContent.timestampAsOverlay() + timestampInsideMessage = messageContent.timestampInsideMessage(), + addMessageOverlay = messageContent.shouldAddMessageOverlay(), ) } else { buildModernLayout(showInformation) @@ -142,10 +143,18 @@ class TimelineMessageLayoutFactory @Inject constructor(private val session: Sess return this.msgType in MSG_TYPES_WITH_PSEUDO_BUBBLE_LAYOUT } - private fun MessageContent?.timestampAsOverlay(): Boolean { + private fun MessageContent?.timestampInsideMessage(): Boolean { if (this == null) return false if (msgType == MessageType.MSGTYPE_LOCATION) return vectorPreferences.labsRenderLocationsInTimeline() - return this.msgType in MSG_TYPES_WITH_TIMESTAMP_AS_OVERLAY + return this.msgType in MSG_TYPES_WITH_TIMESTAMP_INSIDE_MESSAGE + } + + private fun MessageContent?.shouldAddMessageOverlay(): Boolean { + return when { + this == null || msgType == MessageType.MSGTYPE_LIVE_LOCATION_STATE -> false + msgType == MessageType.MSGTYPE_LOCATION -> vectorPreferences.labsRenderLocationsInTimeline() + else -> msgType in MSG_TYPES_WITH_TIMESTAMP_INSIDE_MESSAGE + } } private fun TimelineEvent.shouldBuildBubbleLayout(): Boolean { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/view/MessageBubbleView.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/view/MessageBubbleView.kt index 954aa0bf34..87ed9243a5 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/view/MessageBubbleView.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/view/MessageBubbleView.kt @@ -43,9 +43,9 @@ import im.vector.app.features.themes.ThemeUtils import timber.log.Timber class MessageBubbleView @JvmOverloads constructor( - context: Context, - attrs: AttributeSet? = null, - defStyleAttr: Int = 0, + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0, ) : RelativeLayout(context, attrs, defStyleAttr), TimelineMessageLayoutRenderer { private var isIncoming: Boolean = false @@ -89,21 +89,21 @@ class MessageBubbleView @JvmOverloads constructor( outlineProvider = ViewOutlineProvider.BACKGROUND clipToOutline = true background = RippleDrawable( - ContextCompat.getColorStateList(context, R.color.mtrl_btn_ripple_color) ?: ColorStateList.valueOf(Color.TRANSPARENT), - bubbleDrawable, - rippleMaskDrawable) + ContextCompat.getColorStateList(context, R.color.mtrl_btn_ripple_color) ?: ColorStateList.valueOf(Color.TRANSPARENT), + bubbleDrawable, + rippleMaskDrawable) } } override fun renderMessageLayout(messageLayout: TimelineMessageLayout) { (messageLayout as? TimelineMessageLayout.Bubble) - ?.updateDrawables() - ?.setConstraintsAndColor() - ?.toggleMessageOverlay() - ?.setPadding() - ?.setMargins() - ?.setAdditionalTopSpace() - ?: Timber.v("Can't render messageLayout $messageLayout") + ?.updateDrawables() + ?.setConstraints() + ?.toggleMessageOverlay() + ?.setPadding() + ?.setMargins() + ?.setAdditionalTopSpace() + ?: Timber.v("Can't render messageLayout $messageLayout") } private fun TimelineMessageLayout.Bubble.updateDrawables() = apply { @@ -121,17 +121,13 @@ class MessageBubbleView @JvmOverloads constructor( rippleMaskDrawable.shapeAppearanceModel = shapeAppearanceModel } - private fun TimelineMessageLayout.Bubble.setConstraintsAndColor() = apply { + private fun TimelineMessageLayout.Bubble.setConstraints() = apply { ConstraintSet().apply { clone(views.bubbleView) clear(R.id.viewStubContainer, ConstraintSet.END) - if (timestampAsOverlay) { - val timeColor = ContextCompat.getColor(context, R.color.palette_white) - views.messageTimeView.setTextColor(timeColor) + if (timestampInsideMessage) { connect(R.id.viewStubContainer, ConstraintSet.END, R.id.parent, ConstraintSet.END, 0) } else { - val timeColor = ThemeUtils.getColor(context, R.attr.vctr_content_tertiary) - views.messageTimeView.setTextColor(timeColor) connect(R.id.viewStubContainer, ConstraintSet.END, R.id.messageTimeView, ConstraintSet.START, 0) } applyTo(views.bubbleView) @@ -139,16 +135,20 @@ class MessageBubbleView @JvmOverloads constructor( } private fun TimelineMessageLayout.Bubble.toggleMessageOverlay() = apply { - if (timestampAsOverlay) { + if (addMessageOverlay) { + val timeColor = ContextCompat.getColor(context, R.color.palette_white) + views.messageTimeView.setTextColor(timeColor) views.messageOverlayView.isVisible = true (views.messageOverlayView.background as? GradientDrawable)?.cornerRadii = cornersRadius.toFloatArray() } else { + val timeColor = ThemeUtils.getColor(context, R.attr.vctr_content_tertiary) + views.messageTimeView.setTextColor(timeColor) views.messageOverlayView.isVisible = false } } private fun TimelineMessageLayout.Bubble.setPadding() = apply { - if (isPseudoBubble && timestampAsOverlay) { + if (isPseudoBubble && timestampInsideMessage) { views.viewStubContainer.root.setPadding(0, 0, 0, 0) } else { views.viewStubContainer.root.setPadding(horizontalStubPadding, verticalStubPadding, horizontalStubPadding, verticalStubPadding)