Timeline : handle emote content

This commit is contained in:
ganfra 2019-02-19 19:12:58 +01:00
parent abb44839af
commit 36d1d52880

View file

@ -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.EventType
import im.vector.matrix.android.api.session.events.model.toModel 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.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.MessageImageContent
import im.vector.matrix.android.api.session.room.model.message.MessageTextContent import im.vector.matrix.android.api.session.room.model.message.MessageTextContent
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
@ -67,6 +68,7 @@ class MessageItemFactory(private val timelineMediaSizeProvider: TimelineMediaSiz
return when (messageContent) { return when (messageContent) {
is MessageTextContent -> buildTextMessageItem(messageContent, informationData, callback) is MessageTextContent -> buildTextMessageItem(messageContent, informationData, callback)
is MessageImageContent -> buildImageMessageItem(messageContent, informationData) is MessageImageContent -> buildImageMessageItem(messageContent, informationData)
is MessageEmoteContent -> buildEmoteMessageItem(messageContent, informationData, callback)
else -> buildNotHandledMessageItem(messageContent) else -> buildNotHandledMessageItem(messageContent)
} }
} }
@ -98,20 +100,34 @@ class MessageItemFactory(private val timelineMediaSizeProvider: TimelineMediaSiz
informationData: MessageInformationData, informationData: MessageInformationData,
callback: TimelineEventController.Callback?): MessageTextItem? { 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 message = messageContent.body.let {
val spannable = SpannableStringBuilder(it) val formattedBody = "* ${informationData.memberName} $it"
MatrixLinkify.addLinks(spannable, object : MatrixPermalinkSpan.Callback { linkifyBody(formattedBody, callback)
override fun onUrlClicked(url: String) {
callback?.onUrlClicked(url)
}
})
Linkify.addLinks(spannable, Linkify.ALL)
spannable
} }
return MessageTextItem_() return MessageTextItem_()
.message(message) .message(message)
.informationData(informationData) .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
}
} }