From d49007538b5a791d3bd574316ea0405ff70c486f Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 21 May 2019 14:26:46 +0200 Subject: [PATCH] Fix / Annotate emote also --- .../timeline/factory/MessageItemFactory.kt | 79 ++++++++++++------- 1 file changed, 50 insertions(+), 29 deletions(-) diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/factory/MessageItemFactory.kt index 8b5ecf89..7a68937c 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -110,8 +110,15 @@ class MessageItemFactory(private val colorProvider: ColorProvider, // val all = event.root.toContent() // val ev = all.toModel() return when (messageContent) { - is MessageEmoteContent -> buildEmoteMessageItem(messageContent, informationData, callback) - is MessageTextContent -> buildTextMessageItem(event.sendState, messageContent, informationData, hasBeenEdited, + is MessageEmoteContent -> buildEmoteMessageItem(messageContent, + informationData, + hasBeenEdited, + event.annotations?.editSummary, + callback) + is MessageTextContent -> buildTextMessageItem(event.sendState, + messageContent, + informationData, + hasBeenEdited, event.annotations?.editSummary, callback ) @@ -287,32 +294,7 @@ class MessageItemFactory(private val colorProvider: ColorProvider, return MessageTextItem_() .apply { if (hasBeenEdited) { - val spannable = SpannableStringBuilder() - spannable.append(linkifiedBody) - val editedSuffix = "(edited)" - spannable.append(" ").append(editedSuffix) - val color = colorProvider.getColorFromAttribute(R.attr.vctr_list_header_secondary_text_color) - val editStart = spannable.indexOf(editedSuffix) - val editEnd = editStart + editedSuffix.length - spannable.setSpan( - ForegroundColorSpan(color), - editStart, - editEnd, - Spanned.SPAN_INCLUSIVE_EXCLUSIVE) - - spannable.setSpan(RelativeSizeSpan(.9f), editStart, editEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE) - spannable.setSpan(object : ClickableSpan() { - override fun onClick(widget: View?) { - callback?.onEditedDecorationClicked(informationData, editSummary) - } - - override fun updateDrawState(ds: TextPaint?) { - //nop - } - }, - editStart, - editEnd, - Spanned.SPAN_INCLUSIVE_EXCLUSIVE) + val spannable = annotateWithEdited(linkifiedBody, callback, informationData, editSummary) message(spannable) } else { message(linkifiedBody) @@ -343,6 +325,36 @@ class MessageItemFactory(private val colorProvider: ColorProvider, } } + private fun annotateWithEdited(linkifiedBody: CharSequence, callback: TimelineEventController.Callback?, informationData: MessageInformationData, editSummary: EditAggregatedSummary?): SpannableStringBuilder { + val spannable = SpannableStringBuilder() + spannable.append(linkifiedBody) + val editedSuffix = "(edited)" + spannable.append(" ").append(editedSuffix) + val color = colorProvider.getColorFromAttribute(R.attr.vctr_list_header_secondary_text_color) + val editStart = spannable.indexOf(editedSuffix) + val editEnd = editStart + editedSuffix.length + spannable.setSpan( + ForegroundColorSpan(color), + editStart, + editEnd, + Spanned.SPAN_INCLUSIVE_EXCLUSIVE) + + spannable.setSpan(RelativeSizeSpan(.9f), editStart, editEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE) + spannable.setSpan(object : ClickableSpan() { + override fun onClick(widget: View?) { + callback?.onEditedDecorationClicked(informationData, editSummary) + } + + override fun updateDrawState(ds: TextPaint?) { + //nop + } + }, + editStart, + editEnd, + Spanned.SPAN_INCLUSIVE_EXCLUSIVE) + return spannable + } + private fun buildNoticeMessageItem(messageContent: MessageNoticeContent, informationData: MessageInformationData, callback: TimelineEventController.Callback?): MessageTextItem? { @@ -377,6 +389,8 @@ class MessageItemFactory(private val colorProvider: ColorProvider, } private fun buildEmoteMessageItem(messageContent: MessageEmoteContent, informationData: MessageInformationData, + hasBeenEdited: Boolean, + editSummary: EditAggregatedSummary?, callback: TimelineEventController.Callback?): MessageTextItem? { val message = messageContent.body.let { @@ -384,7 +398,14 @@ class MessageItemFactory(private val colorProvider: ColorProvider, linkifyBody(formattedBody, callback) } return MessageTextItem_() - .message(message) + .apply { + if (hasBeenEdited) { + val spannable = annotateWithEdited(message, callback, informationData, editSummary) + message(spannable) + } else { + message(message) + } + } .informationData(informationData) .reactionPillCallback(callback) .avatarClickListener(