From 8f0e1039aa8516772e0c60acb666fbe74d5a7e4e Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 24 Jan 2022 19:31:51 +0100 Subject: [PATCH] Bubbles: make round style algorithm more accurate --- .../style/TimelineMessageLayoutFactory.kt | 49 ++++++++++++------- 1 file changed, 30 insertions(+), 19 deletions(-) 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 e12e27472c..952d59e372 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 @@ -81,26 +81,25 @@ class TimelineMessageLayoutFactory @Inject constructor(private val session: Sess buildModernLayout(showInformation) } TimelineLayoutSettings.BUBBLE -> { - val type = event.root.getClearType() - if (type in EVENT_TYPES_WITH_BUBBLE_LAYOUT) { - val messageContent = event.getLastMessageContent() - if (messageContent?.msgType in MSG_TYPES_WITHOUT_BUBBLE_LAYOUT) { - buildModernLayout(showInformation) - } else { - val isFirstFromThisSender = nextDisplayableEvent?.root?.senderId != event.root.senderId || addDaySeparator - val isLastFromThisSender = prevDisplayableEvent?.root?.senderId != event.root.senderId || - prevDisplayableEvent?.root?.localDateTime()?.toLocalDate() != date.toLocalDate() + val shouldBuildBubbleLayout = event.shouldBuildBubbleLayout() + if (shouldBuildBubbleLayout) { + val isFirstFromThisSender = nextDisplayableEvent == null || !nextDisplayableEvent.shouldBuildBubbleLayout() || + nextDisplayableEvent.root.senderId != event.root.senderId || addDaySeparator - TimelineMessageLayout.Bubble( - showAvatar = showInformation && !isSentByMe, - showDisplayName = showInformation && !isSentByMe, - isIncoming = !isSentByMe, - isFirstFromThisSender = isFirstFromThisSender, - isLastFromThisSender = isLastFromThisSender, - isPseudoBubble = messageContent?.msgType in MSG_TYPES_WITH_PSEUDO_BUBBLE_LAYOUT, - timestampAsOverlay = messageContent?.msgType in MSG_TYPES_WITH_TIMESTAMP_AS_OVERLAY - ) - } + val isLastFromThisSender = prevDisplayableEvent == null || !prevDisplayableEvent.shouldBuildBubbleLayout() || + prevDisplayableEvent.root.senderId != event.root.senderId || + prevDisplayableEvent.root.localDateTime().toLocalDate() != date.toLocalDate() + + val messageContent = event.getLastMessageContent() + TimelineMessageLayout.Bubble( + showAvatar = showInformation && !isSentByMe, + showDisplayName = showInformation && !isSentByMe, + isIncoming = !isSentByMe, + isFirstFromThisSender = isFirstFromThisSender, + isLastFromThisSender = isLastFromThisSender, + isPseudoBubble = messageContent?.msgType in MSG_TYPES_WITH_PSEUDO_BUBBLE_LAYOUT, + timestampAsOverlay = messageContent?.msgType in MSG_TYPES_WITH_TIMESTAMP_AS_OVERLAY + ) } else { buildModernLayout(showInformation) } @@ -109,6 +108,18 @@ class TimelineMessageLayoutFactory @Inject constructor(private val session: Sess return messageLayout } + private fun TimelineEvent.shouldBuildBubbleLayout(): Boolean { + val type = root.getClearType() + if (type in EVENT_TYPES_WITH_BUBBLE_LAYOUT) { + val messageContent = getLastMessageContent() + if (messageContent?.msgType in MSG_TYPES_WITHOUT_BUBBLE_LAYOUT) { + return false + } + return true + } + return false + } + private fun buildModernLayout(showInformation: Boolean): TimelineMessageLayout.Default { return TimelineMessageLayout.Default( showAvatar = showInformation,