From c76363584540b80a8f303e58e98567fb166d5831 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 2 Oct 2019 20:36:52 +0200 Subject: [PATCH] Optimize: try to optimize a text message items --- .../timeline/factory/MessageItemFactory.kt | 4 ++++ .../detail/timeline/item/MessageTextItem.kt | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt index 35ca7d7b9a..7b749ec5b7 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -249,6 +249,7 @@ class MessageItemFactory @Inject constructor( callback: TimelineEventController.Callback?, attributes: AbsMessageItem.Attributes): MessageTextItem? { + val isFormatted = messageContent.formattedBody.isNullOrBlank().not() val bodyToUse = messageContent.formattedBody?.let { htmlRenderer.get().render(it.trim()) } ?: messageContent.body @@ -264,6 +265,7 @@ class MessageItemFactory @Inject constructor( message(linkifiedBody) } } + .searchForPills(isFormatted) .leftGuideline(avatarSizeProvider.leftGuideline) .attributes(attributes) .highlighted(highlight) @@ -318,6 +320,7 @@ class MessageItemFactory @Inject constructor( linkifyBody(formattedBody, callback) } return MessageTextItem_() + .searchForPills(false) .leftGuideline(avatarSizeProvider.leftGuideline) .attributes(attributes) .message(message) @@ -344,6 +347,7 @@ class MessageItemFactory @Inject constructor( message(message) } } + .searchForPills(false) .leftGuideline(avatarSizeProvider.leftGuideline) .attributes(attributes) .highlighted(highlight) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageTextItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageTextItem.kt index 2ba2337242..a19a335937 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageTextItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageTextItem.kt @@ -35,6 +35,8 @@ import me.saket.bettermovementmethod.BetterLinkMovementMethod @EpoxyModelClass(layout = R.layout.item_timeline_event_base) abstract class MessageTextItem : AbsMessageItem() { + @EpoxyAttribute + var searchForPills: Boolean = false @EpoxyAttribute var message: CharSequence? = null @EpoxyAttribute @@ -65,22 +67,22 @@ abstract class MessageTextItem : AbsMessageItem() { override fun bind(holder: Holder) { super.bind(holder) holder.messageView.movementMethod = mvmtMethod - if (useBigFont) { holder.messageView.textSize = 44F } else { holder.messageView.textSize = 14F } - - val textFuture = PrecomputedTextCompat.getTextFuture(message ?: "", - TextViewCompat.getTextMetricsParams(holder.messageView), - null) - - holder.messageView.setTextFuture(textFuture) renderSendState(holder.messageView, holder.messageView) holder.messageView.setOnClickListener(attributes.itemClickListener) holder.messageView.setOnLongClickListener(attributes.itemLongClickListener) - findPillsAndProcess { it.bind(holder.messageView) } + if (searchForPills) { + findPillsAndProcess { it.bind(holder.messageView) } + } + val textFuture = PrecomputedTextCompat.getTextFuture( + message ?: "", + TextViewCompat.getTextMetricsParams(holder.messageView), + null) + holder.messageView.setTextFuture(textFuture) } private fun findPillsAndProcess(processBlock: (span: PillImageSpan) -> Unit) {