From 36d1d5288021ef2f458d91a8d43a94a0bc82ec74 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 19 Feb 2019 19:12:58 +0100 Subject: [PATCH] Timeline : handle emote content --- .../detail/timeline/MessageItemFactory.kt | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt index a52659de..fc377798 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt @@ -23,6 +23,7 @@ import im.vector.matrix.android.api.permalinks.MatrixPermalinkSpan import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.toModel import im.vector.matrix.android.api.session.room.model.message.MessageContent +import im.vector.matrix.android.api.session.room.model.message.MessageEmoteContent import im.vector.matrix.android.api.session.room.model.message.MessageImageContent import im.vector.matrix.android.api.session.room.model.message.MessageTextContent import im.vector.matrix.android.api.session.room.timeline.TimelineEvent @@ -67,6 +68,7 @@ class MessageItemFactory(private val timelineMediaSizeProvider: TimelineMediaSiz return when (messageContent) { is MessageTextContent -> buildTextMessageItem(messageContent, informationData, callback) is MessageImageContent -> buildImageMessageItem(messageContent, informationData) + is MessageEmoteContent -> buildEmoteMessageItem(messageContent, informationData, callback) else -> buildNotHandledMessageItem(messageContent) } } @@ -98,20 +100,34 @@ class MessageItemFactory(private val timelineMediaSizeProvider: TimelineMediaSiz informationData: MessageInformationData, callback: TimelineEventController.Callback?): MessageTextItem? { + val message = linkifyBody(messageContent.body, callback) + return MessageTextItem_() + .message(message) + .informationData(informationData) + } + + private fun buildEmoteMessageItem(messageContent: MessageEmoteContent, + informationData: MessageInformationData, + callback: TimelineEventController.Callback?): MessageTextItem? { + val message = messageContent.body.let { - val spannable = SpannableStringBuilder(it) - MatrixLinkify.addLinks(spannable, object : MatrixPermalinkSpan.Callback { - override fun onUrlClicked(url: String) { - callback?.onUrlClicked(url) - } - }) - Linkify.addLinks(spannable, Linkify.ALL) - spannable + val formattedBody = "* ${informationData.memberName} $it" + linkifyBody(formattedBody, callback) } return MessageTextItem_() .message(message) .informationData(informationData) } + private fun linkifyBody(body: String, callback: TimelineEventController.Callback?): CharSequence { + val spannable = SpannableStringBuilder(body) + MatrixLinkify.addLinks(spannable, object : MatrixPermalinkSpan.Callback { + override fun onUrlClicked(url: String) { + callback?.onUrlClicked(url) + } + }) + Linkify.addLinks(spannable, Linkify.ALL) + return spannable + } } \ No newline at end of file