diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt index dea628fe46..1e53819c60 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -72,6 +72,7 @@ import org.commonmark.node.Document import org.matrix.android.sdk.api.MatrixUrls.isMxcUrl import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.events.model.RelationType +import org.matrix.android.sdk.api.session.events.model.toContent import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.room.model.message.MessageAudioContent import org.matrix.android.sdk.api.session.room.model.message.MessageContent @@ -95,6 +96,7 @@ import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent import org.matrix.android.sdk.api.util.MimeTypes import org.matrix.android.sdk.internal.crypto.attachments.toElementToDecrypt import org.matrix.android.sdk.internal.crypto.model.event.EncryptedEventContent +import timber.log.Timber import javax.inject.Inject class MessageItemFactory @Inject constructor( @@ -557,13 +559,36 @@ class MessageItemFactory @Inject constructor( informationData: MessageInformationData, highlight: Boolean, callback: TimelineEventController.Callback?, - attributes: AbsMessageItem.Attributes): MessageTextItem? { + attrs: AbsMessageItem.Attributes): VectorEpoxyModel<*>? { + val attributes = attrs.copy(isNotice = true) + + // We might want to use the normal text rendering in the future as following (but need to + // ensure that notices are easily told apart also from code, ... formatted messages). + // Maybe, instead of text coloring, we can come up with some other indicator that catches all cases automatically? + /* + val noticeAsTextContent = messageContent.toContent().toModel() + if (noticeAsTextContent != null && false) { + return buildItemForTextContent( + noticeAsTextContent, + informationData, + highlight, + callback, + attributes + ) + } + Timber.w("Could not parse notice as text item, using legacy fallback") + */ + val htmlBody = messageContent.getHtmlBody() + // SchildiChat likes to not overwrite message formatting for notices, compared to upstream + val formattedBody = htmlBody + /* val formattedBody = span { text = htmlBody textColor = colorProvider.getColorFromAttribute(R.attr.vctr_content_secondary) textStyle = "italic" } + */ val canUseTextFuture = spanUtils.canUseTextFuture(htmlBody) val message = formattedBody.linkify(callback) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt index b7da5a43a9..3e3448b718 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt @@ -268,6 +268,7 @@ abstract class AbsMessageItem : AbsBaseMessageItem override val reactionPillCallback: TimelineEventController.ReactionPillCallback? = null, val avatarCallback: TimelineEventController.AvatarCallback? = null, override val readReceiptsCallback: TimelineEventController.ReadReceiptsCallback? = null, + val isNotice: Boolean = false, val emojiTypeFace: Typeface? = null ) : AbsBaseMessageItem.Attributes { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageTextItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageTextItem.kt index 6c76b1584d..365670f3fc 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageTextItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageTextItem.kt @@ -17,6 +17,7 @@ package im.vector.app.features.home.room.detail.timeline.item import android.content.Context +import android.graphics.Color import android.text.TextUtils import android.text.method.MovementMethod import android.widget.LinearLayout @@ -27,6 +28,7 @@ import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass import im.vector.app.R import im.vector.app.core.epoxy.onClick +import im.vector.app.core.resources.ColorProvider import im.vector.app.core.ui.views.FooteredTextView import im.vector.app.features.home.room.detail.timeline.TimelineEventController import im.vector.app.features.home.room.detail.timeline.tools.findPillsAndProcess @@ -118,6 +120,9 @@ abstract class MessageTextItem : AbsMessageItem() { renderSendState(holder.messageView, holder.messageView) holder.messageView.onClick(attributes.itemClickListener) holder.messageView.setOnLongClickListener(attributes.itemLongClickListener) + holder.messageView.setTextColor(ColorProvider(holder.messageView.context).getColorFromAttribute( + if (attributes.isNotice) R.attr.vctr_content_secondary else R.attr.vctr_content_primary + )) if (canUseTextFuture) { holder.messageView.setTextFuture(textFuture) diff --git a/vector/src/main/res/layout/item_timeline_event_text_message_stub.xml b/vector/src/main/res/layout/item_timeline_event_text_message_stub.xml index 7408ca00ac..d37d22327b 100644 --- a/vector/src/main/res/layout/item_timeline_event_text_message_stub.xml +++ b/vector/src/main/res/layout/item_timeline_event_text_message_stub.xml @@ -19,8 +19,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="0dp" - android:textColor="?vctr_content_primary" android:layout_gravity="left" + tools:textColor="?vctr_content_primary" tools:text="@sample/messages.json/data/message" tools:ignore="RtlHardcoded" />