Bubbles: make round style algorithm more accurate

This commit is contained in:
ganfra 2022-01-24 19:31:51 +01:00
parent 608d8a5d54
commit 8f0e1039aa

View File

@ -81,26 +81,25 @@ class TimelineMessageLayoutFactory @Inject constructor(private val session: Sess
buildModernLayout(showInformation) buildModernLayout(showInformation)
} }
TimelineLayoutSettings.BUBBLE -> { TimelineLayoutSettings.BUBBLE -> {
val type = event.root.getClearType() val shouldBuildBubbleLayout = event.shouldBuildBubbleLayout()
if (type in EVENT_TYPES_WITH_BUBBLE_LAYOUT) { if (shouldBuildBubbleLayout) {
val messageContent = event.getLastMessageContent() val isFirstFromThisSender = nextDisplayableEvent == null || !nextDisplayableEvent.shouldBuildBubbleLayout() ||
if (messageContent?.msgType in MSG_TYPES_WITHOUT_BUBBLE_LAYOUT) { nextDisplayableEvent.root.senderId != event.root.senderId || addDaySeparator
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()
TimelineMessageLayout.Bubble( val isLastFromThisSender = prevDisplayableEvent == null || !prevDisplayableEvent.shouldBuildBubbleLayout() ||
showAvatar = showInformation && !isSentByMe, prevDisplayableEvent.root.senderId != event.root.senderId ||
showDisplayName = showInformation && !isSentByMe, prevDisplayableEvent.root.localDateTime().toLocalDate() != date.toLocalDate()
isIncoming = !isSentByMe,
isFirstFromThisSender = isFirstFromThisSender, val messageContent = event.getLastMessageContent()
isLastFromThisSender = isLastFromThisSender, TimelineMessageLayout.Bubble(
isPseudoBubble = messageContent?.msgType in MSG_TYPES_WITH_PSEUDO_BUBBLE_LAYOUT, showAvatar = showInformation && !isSentByMe,
timestampAsOverlay = messageContent?.msgType in MSG_TYPES_WITH_TIMESTAMP_AS_OVERLAY 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 { } else {
buildModernLayout(showInformation) buildModernLayout(showInformation)
} }
@ -109,6 +108,18 @@ class TimelineMessageLayoutFactory @Inject constructor(private val session: Sess
return messageLayout 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 { private fun buildModernLayout(showInformation: Boolean): TimelineMessageLayout.Default {
return TimelineMessageLayout.Default( return TimelineMessageLayout.Default(
showAvatar = showInformation, showAvatar = showInformation,