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
This commit is contained in:
SpiritCroc 2020-12-24 12:07:54 +01:00
parent b6f2ca85f7
commit 1a6d8398aa
2 changed files with 40 additions and 20 deletions

View file

@ -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<H : AbsBaseMessageItem.Holder> : 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<ViewGroup>(R.id.reactionsContainer)
val informationBottom by bind<ViewGroup>(R.id.informationBottom)

View file

@ -329,8 +329,6 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
// 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<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
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<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
*/
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<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
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<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
shortPaddingDp,
shortPaddingDp
)
// Align reactions container to bubble
holder.informationBottom.setPaddingRelative(
alignPaddingDp,
0,
0,
0
)
}
if (contentInBubble) {
@ -472,7 +453,6 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
(bubbleView.layoutParams as RelativeLayout.LayoutParams).bottomMargin = 0
*/
bubbleView.setPadding(0, 0, 0, 0)
holder.informationBottom.setPadding(0, 0, 0, 0)
}
}