Optimize: try to optimize a text message items

This commit is contained in:
ganfra 2019-10-02 20:36:52 +02:00
parent ff7856c535
commit c763635845
2 changed files with 14 additions and 8 deletions

View File

@ -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)

View File

@ -35,6 +35,8 @@ import me.saket.bettermovementmethod.BetterLinkMovementMethod
@EpoxyModelClass(layout = R.layout.item_timeline_event_base)
abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
@EpoxyAttribute
var searchForPills: Boolean = false
@EpoxyAttribute
var message: CharSequence? = null
@EpoxyAttribute
@ -65,22 +67,22 @@ abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
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) {