From 1a6d8398aaf9f226dc1fc16004db225ea4ef2f28 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Thu, 24 Dec 2020 12:07:54 +0100 Subject: [PATCH] Fix incomplete reactions bubble alignment Related to: fa5acb49c Align reactions better with message bubbles We do not want to change the alignment for views that draw actual bubbles, but also pseudo-bubbles, such as media items. Change-Id: Ie6e0e8d9145239d284ee4e35987459a9184e48ff --- .../timeline/item/AbsBaseMessageItem.kt | 40 +++++++++++++++++++ .../detail/timeline/item/AbsMessageItem.kt | 20 ---------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt index 99dd884a02..209b328eaa 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt @@ -28,7 +28,9 @@ import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.timeline.MessageColorProvider import im.vector.app.features.home.room.detail.timeline.TimelineEventController import im.vector.app.features.reactions.widget.ReactionButton +import im.vector.app.features.themes.BubbleThemeUtils import org.matrix.android.sdk.api.session.room.send.SendState +import kotlin.math.round /** * Base timeline item with reactions and read receipts. @@ -121,6 +123,44 @@ abstract class AbsBaseMessageItem : BaseEventItem failureIndicator?.isVisible = baseAttributes.informationData.sendState.hasFailed() } + override fun setBubbleLayout(holder: H, bubbleStyle: String, bubbleStyleSetting: String, reverseBubble: Boolean) { + super.setBubbleLayout(holder, bubbleStyle, bubbleStyleSetting, reverseBubble) + + // ATTENTION: we go over the bubbleStyleSetting here: this might differ from the effective bubbleStyle + // for this view class! We want to use the setting to do some uniform alignments for all views though. + when (bubbleStyleSetting) { + BubbleThemeUtils.BUBBLE_STYLE_START, + BubbleThemeUtils.BUBBLE_STYLE_BOTH, + BubbleThemeUtils.BUBBLE_STYLE_BOTH_HIDDEN, + BubbleThemeUtils.BUBBLE_STYLE_START_HIDDEN -> { + val density = holder.informationBottom.resources.displayMetrics.density + // Padding for views that align with the bubble (should be roughly the bubble tail width) + val bubbleStartAlignWidth = round(12 * density).toInt() + if (reverseBubble) { + // Align reactions container to bubble + holder.informationBottom.setPaddingRelative( + 0, + 0, + bubbleStartAlignWidth, + 0 + ) + } else { + // Align reactions container to bubble + holder.informationBottom.setPaddingRelative( + bubbleStartAlignWidth, + 0, + 0, + 0 + ) + } + } + else -> { + // No alignment padding for reactions required + holder.informationBottom.setPaddingRelative(0, 0, 0, 0) + } + } + } + abstract class Holder(@IdRes stubId: Int) : BaseEventItem.BaseHolder(stubId) { val reactionsContainer by bind(R.id.reactionsContainer) val informationBottom by bind(R.id.informationBottom) 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 7558c2cecf..1aa87c3f56 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 @@ -329,8 +329,6 @@ abstract class AbsMessageItem : AbsBaseMessageItem // Padding for bubble content: long for side with tail, short for other sides val longPadding: Int val shortPadding: Int - // Padding for other views that align with the bubble (should be roughly the bubble tail width - var alignPadding: Int if (BubbleThemeUtils.drawsActualBubbles(bubbleStyle)) { if (attributes.informationData.showInformation) { bubbleView.setBackgroundResource(if (reverseBubble) R.drawable.msg_bubble_outgoing else R.drawable.msg_bubble_incoming) @@ -346,11 +344,9 @@ abstract class AbsMessageItem : AbsBaseMessageItem bubbleView.backgroundTintList = tintColor longPadding = 20 shortPadding = 8 - alignPadding = 12 } else { longPadding = 10 shortPadding = 0//if (attributes.informationData.showInformation && !hideSenderInformation()) { 8 } else { 0 } - alignPadding = 0 } val density = bubbleView.resources.displayMetrics.density if (reverseBubble) { @@ -367,7 +363,6 @@ abstract class AbsMessageItem : AbsBaseMessageItem */ val shortPaddingDp = round(shortPadding * density).toInt() val longPaddingDp = round(longPadding * density).toInt() - val alignPaddingDp = round(alignPadding * density).toInt() if (reverseBubble) { bubbleView.setPaddingRelative( shortPaddingDp, @@ -375,13 +370,6 @@ abstract class AbsMessageItem : AbsBaseMessageItem longPaddingDp, shortPaddingDp ) - // Align reactions container to bubble - holder.informationBottom.setPaddingRelative( - 0, - 0, - alignPaddingDp, - 0 - ) } else { bubbleView.setPaddingRelative( longPaddingDp, @@ -389,13 +377,6 @@ abstract class AbsMessageItem : AbsBaseMessageItem shortPaddingDp, shortPaddingDp ) - // Align reactions container to bubble - holder.informationBottom.setPaddingRelative( - alignPaddingDp, - 0, - 0, - 0 - ) } if (contentInBubble) { @@ -472,7 +453,6 @@ abstract class AbsMessageItem : AbsBaseMessageItem (bubbleView.layoutParams as RelativeLayout.LayoutParams).bottomMargin = 0 */ bubbleView.setPadding(0, 0, 0, 0) - holder.informationBottom.setPadding(0, 0, 0, 0) } }