Optimize: try to optimize a text message items
This commit is contained in:
parent
ff7856c535
commit
c763635845
|
@ -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)
|
||||
|
|
|
@ -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,23 +67,23 @@ 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)
|
||||
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) {
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
|
|
Loading…
Reference in New Issue