Bubbles: fix types using wrong layout

This commit is contained in:
ganfra 2022-01-13 12:33:58 +01:00
parent b9cc795996
commit baee076e41
3 changed files with 49 additions and 21 deletions

View File

@ -172,9 +172,7 @@ class MessageItemFactory @Inject constructor(
is MessagePollContent -> buildPollContent(messageContent, informationData, highlight, callback, attributes) is MessagePollContent -> buildPollContent(messageContent, informationData, highlight, callback, attributes)
else -> buildNotHandledMessageItem(messageContent, informationData, highlight, callback, attributes) else -> buildNotHandledMessageItem(messageContent, informationData, highlight, callback, attributes)
} }
return messageItem?.takeIf { return messageItem?.apply {
it.layout == R.layout.item_timeline_event_base
}?.apply {
layout(informationData.messageLayout.layoutRes) layout(informationData.messageLayout.layoutRes)
} }
} }
@ -650,6 +648,7 @@ class MessageItemFactory @Inject constructor(
private fun buildRedactedItem(attributes: AbsMessageItem.Attributes, private fun buildRedactedItem(attributes: AbsMessageItem.Attributes,
highlight: Boolean): RedactedMessageItem? { highlight: Boolean): RedactedMessageItem? {
return RedactedMessageItem_() return RedactedMessageItem_()
.layout(attributes.informationData.messageLayout.layoutRes)
.leftGuideline(avatarSizeProvider.leftGuideline) .leftGuideline(avatarSizeProvider.leftGuideline)
.attributes(attributes) .attributes(attributes)
.highlighted(highlight) .highlighted(highlight)

View File

@ -27,10 +27,11 @@ sealed interface TimelineMessageLayout : Parcelable {
val showTimestamp: Boolean val showTimestamp: Boolean
@Parcelize @Parcelize
data class Modern(override val showAvatar: Boolean, data class Default(override val showAvatar: Boolean,
override val showDisplayName: Boolean, override val showDisplayName: Boolean,
override val showTimestamp: Boolean, override val showTimestamp: Boolean,
override val layoutRes: Int = R.layout.item_timeline_event_base) : TimelineMessageLayout // Keep defaultLayout generated on epoxy items
override val layoutRes: Int = 0) : TimelineMessageLayout
@Parcelize @Parcelize
data class Bubble(override val showAvatar: Boolean, data class Bubble(override val showAvatar: Boolean,

View File

@ -21,6 +21,7 @@ import im.vector.app.features.home.room.detail.timeline.factory.TimelineItemFact
import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.VectorPreferences
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.room.model.message.MessageType
import org.matrix.android.sdk.api.session.room.model.message.MessageVerificationRequestContent import org.matrix.android.sdk.api.session.room.model.message.MessageVerificationRequestContent
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent
@ -31,6 +32,18 @@ class TimelineMessageLayoutFactory @Inject constructor(private val session: Sess
private val layoutSettingsProvider: TimelineLayoutSettingsProvider, private val layoutSettingsProvider: TimelineLayoutSettingsProvider,
private val vectorPreferences: VectorPreferences) { private val vectorPreferences: VectorPreferences) {
companion object {
private val EVENT_TYPES_WITH_BUBBLE_LAYOUT = setOf(
EventType.MESSAGE,
EventType.ENCRYPTED,
EventType.STICKER
)
private val MSG_TYPES_WITHOUT_BUBBLE_LAYOUT = setOf(
MessageType.MSGTYPE_POLL_START,
MessageType.MSGTYPE_VERIFICATION_REQUEST
)
}
fun create(params: TimelineItemFactoryParams): TimelineMessageLayout { fun create(params: TimelineItemFactoryParams): TimelineMessageLayout {
val event = params.event val event = params.event
@ -55,27 +68,42 @@ class TimelineMessageLayoutFactory @Inject constructor(private val session: Sess
val messageLayout = when (layoutSettingsProvider.getLayoutSettings()) { val messageLayout = when (layoutSettingsProvider.getLayoutSettings()) {
TimelineLayoutSettings.MODERN -> { TimelineLayoutSettings.MODERN -> {
TimelineMessageLayout.Modern( buildModernLayout(showInformation)
showAvatar = showInformation,
showDisplayName = showInformation,
showTimestamp = showInformation || vectorPreferences.alwaysShowTimeStamps()
)
} }
TimelineLayoutSettings.BUBBLE -> { TimelineLayoutSettings.BUBBLE -> {
val isFirstFromThisSender = nextDisplayableEvent?.root?.senderId != event.root.senderId || addDaySeparator val type = event.root.getClearType()
val isLastFromThisSender = prevDisplayableEvent?.root?.senderId != event.root.senderId || prevDisplayableEvent?.root?.localDateTime()?.toLocalDate() != date.toLocalDate() if (type in EVENT_TYPES_WITH_BUBBLE_LAYOUT) {
TimelineMessageLayout.Bubble( val messageContent = if (type == EventType.MESSAGE) params.event.getLastMessageContent() else null
showAvatar = showInformation && !isSentByMe, if (messageContent?.msgType in MSG_TYPES_WITHOUT_BUBBLE_LAYOUT) {
showDisplayName = showInformation && !isSentByMe, buildModernLayout(showInformation)
isIncoming = !isSentByMe, }
isFirstFromThisSender = isFirstFromThisSender, val isFirstFromThisSender = nextDisplayableEvent?.root?.senderId != event.root.senderId || addDaySeparator
isLastFromThisSender = isLastFromThisSender val isLastFromThisSender = prevDisplayableEvent?.root?.senderId != event.root.senderId
) || prevDisplayableEvent?.root?.localDateTime()?.toLocalDate() != date.toLocalDate()
TimelineMessageLayout.Bubble(
showAvatar = showInformation && !isSentByMe,
showDisplayName = showInformation && !isSentByMe,
isIncoming = !isSentByMe,
isFirstFromThisSender = isFirstFromThisSender,
isLastFromThisSender = isLastFromThisSender
)
} else {
buildModernLayout(showInformation)
}
} }
} }
return messageLayout return messageLayout
} }
private fun buildModernLayout(showInformation: Boolean): TimelineMessageLayout.Default {
return TimelineMessageLayout.Default(
showAvatar = showInformation,
showDisplayName = showInformation,
showTimestamp = showInformation || vectorPreferences.alwaysShowTimeStamps()
)
}
/** /**
* Tiles type message never show the sender information (like verification request), so we should repeat it for next message * Tiles type message never show the sender information (like verification request), so we should repeat it for next message
* even if same sender * even if same sender