mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-17 02:15:17 +08:00
Bubbles: fix types using wrong layout
This commit is contained in:
parent
b9cc795996
commit
baee076e41
@ -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)
|
||||||
|
@ -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,
|
||||||
|
@ -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,15 +68,19 @@ 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 type = event.root.getClearType()
|
||||||
|
if (type in EVENT_TYPES_WITH_BUBBLE_LAYOUT) {
|
||||||
|
val messageContent = if (type == EventType.MESSAGE) params.event.getLastMessageContent() else null
|
||||||
|
if (messageContent?.msgType in MSG_TYPES_WITHOUT_BUBBLE_LAYOUT) {
|
||||||
|
buildModernLayout(showInformation)
|
||||||
|
}
|
||||||
val isFirstFromThisSender = nextDisplayableEvent?.root?.senderId != event.root.senderId || addDaySeparator
|
val isFirstFromThisSender = nextDisplayableEvent?.root?.senderId != event.root.senderId || addDaySeparator
|
||||||
val isLastFromThisSender = prevDisplayableEvent?.root?.senderId != event.root.senderId || prevDisplayableEvent?.root?.localDateTime()?.toLocalDate() != date.toLocalDate()
|
val isLastFromThisSender = prevDisplayableEvent?.root?.senderId != event.root.senderId
|
||||||
|
|| prevDisplayableEvent?.root?.localDateTime()?.toLocalDate() != date.toLocalDate()
|
||||||
|
|
||||||
TimelineMessageLayout.Bubble(
|
TimelineMessageLayout.Bubble(
|
||||||
showAvatar = showInformation && !isSentByMe,
|
showAvatar = showInformation && !isSentByMe,
|
||||||
showDisplayName = showInformation && !isSentByMe,
|
showDisplayName = showInformation && !isSentByMe,
|
||||||
@ -71,11 +88,22 @@ class TimelineMessageLayoutFactory @Inject constructor(private val session: Sess
|
|||||||
isFirstFromThisSender = isFirstFromThisSender,
|
isFirstFromThisSender = isFirstFromThisSender,
|
||||||
isLastFromThisSender = isLastFromThisSender
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user