2019-01-18 11:12:08 +01:00
|
|
|
/*
|
2019-01-25 14:04:59 +01:00
|
|
|
* Copyright 2019 New Vector Ltd
|
2019-01-18 11:12:08 +01:00
|
|
|
*
|
2019-01-25 14:04:59 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2019-01-18 11:12:08 +01:00
|
|
|
*
|
2019-01-25 14:04:59 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2019-01-18 11:12:08 +01:00
|
|
|
*/
|
|
|
|
|
2019-07-02 17:27:08 +02:00
|
|
|
package im.vector.riotx.features.home.room.detail.timeline.factory
|
2018-11-02 17:37:37 +01:00
|
|
|
|
2019-01-07 11:39:26 +01:00
|
|
|
import android.text.SpannableStringBuilder
|
2019-05-20 18:52:48 +02:00
|
|
|
import android.text.Spanned
|
2019-05-21 14:12:18 +02:00
|
|
|
import android.text.TextPaint
|
|
|
|
import android.text.style.ClickableSpan
|
2019-05-20 18:52:48 +02:00
|
|
|
import android.text.style.ForegroundColorSpan
|
2019-05-21 14:12:18 +02:00
|
|
|
import android.text.style.RelativeSizeSpan
|
2019-05-08 15:49:32 +02:00
|
|
|
import android.view.View
|
2019-07-01 20:05:48 +02:00
|
|
|
import dagger.Lazy
|
2019-01-07 11:39:26 +01:00
|
|
|
import im.vector.matrix.android.api.permalinks.MatrixLinkify
|
|
|
|
import im.vector.matrix.android.api.permalinks.MatrixPermalinkSpan
|
2019-05-20 18:52:48 +02:00
|
|
|
import im.vector.matrix.android.api.session.events.model.RelationType
|
2019-07-17 16:20:12 +02:00
|
|
|
import im.vector.matrix.android.api.session.events.model.toModel
|
2019-08-08 14:32:11 +02:00
|
|
|
import im.vector.matrix.android.api.session.room.model.message.MessageAudioContent
|
|
|
|
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.MessageFileContent
|
|
|
|
import im.vector.matrix.android.api.session.room.model.message.MessageImageContent
|
|
|
|
import im.vector.matrix.android.api.session.room.model.message.MessageNoticeContent
|
|
|
|
import im.vector.matrix.android.api.session.room.model.message.MessageTextContent
|
|
|
|
import im.vector.matrix.android.api.session.room.model.message.MessageVideoContent
|
|
|
|
import im.vector.matrix.android.api.session.room.model.message.getFileUrl
|
2019-01-25 18:40:02 +01:00
|
|
|
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
2019-07-10 17:37:22 +02:00
|
|
|
import im.vector.matrix.android.api.session.room.timeline.getLastMessageContent
|
2019-06-24 22:33:30 +02:00
|
|
|
import im.vector.matrix.android.internal.crypto.attachments.toElementToDecrypt
|
2019-07-17 16:20:12 +02:00
|
|
|
import im.vector.matrix.android.internal.crypto.model.event.EncryptedEventContent
|
2019-07-02 17:27:08 +02:00
|
|
|
import im.vector.riotx.EmojiCompatFontProvider
|
|
|
|
import im.vector.riotx.R
|
|
|
|
import im.vector.riotx.core.epoxy.VectorEpoxyModel
|
|
|
|
import im.vector.riotx.core.linkify.VectorLinkify
|
|
|
|
import im.vector.riotx.core.resources.ColorProvider
|
|
|
|
import im.vector.riotx.core.resources.StringProvider
|
|
|
|
import im.vector.riotx.core.utils.DebouncedClickListener
|
|
|
|
import im.vector.riotx.features.home.AvatarRenderer
|
|
|
|
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
|
|
|
|
import im.vector.riotx.features.home.room.detail.timeline.helper.ContentUploadStateTrackerBinder
|
|
|
|
import im.vector.riotx.features.home.room.detail.timeline.helper.TimelineMediaSizeProvider
|
2019-08-20 19:12:22 +02:00
|
|
|
import im.vector.riotx.features.home.room.detail.timeline.item.*
|
|
|
|
import im.vector.riotx.features.home.room.detail.timeline.helper.MessageInformationDataFactory
|
|
|
|
import im.vector.riotx.features.home.room.detail.timeline.helper.MessageItemAttributesFactory
|
2019-07-02 17:27:08 +02:00
|
|
|
import im.vector.riotx.features.html.EventHtmlRenderer
|
|
|
|
import im.vector.riotx.features.media.ImageContentRenderer
|
|
|
|
import im.vector.riotx.features.media.VideoContentRenderer
|
2019-02-20 11:39:25 +01:00
|
|
|
import me.gujun.android.span.span
|
2019-06-18 20:00:20 +02:00
|
|
|
import javax.inject.Inject
|
2018-11-02 17:37:37 +01:00
|
|
|
|
2019-06-18 20:00:20 +02:00
|
|
|
class MessageItemFactory @Inject constructor(
|
|
|
|
private val colorProvider: ColorProvider,
|
|
|
|
private val timelineMediaSizeProvider: TimelineMediaSizeProvider,
|
2019-07-01 20:05:48 +02:00
|
|
|
private val htmlRenderer: Lazy<EventHtmlRenderer>,
|
2019-06-18 20:00:20 +02:00
|
|
|
private val stringProvider: StringProvider,
|
2019-06-26 15:22:44 +02:00
|
|
|
private val imageContentRenderer: ImageContentRenderer,
|
2019-06-26 20:58:46 +02:00
|
|
|
private val messageInformationDataFactory: MessageInformationDataFactory,
|
2019-08-20 19:12:22 +02:00
|
|
|
private val messageItemAttributesFactory: MessageItemAttributesFactory,
|
2019-07-19 16:13:55 +02:00
|
|
|
private val contentUploadStateTrackerBinder: ContentUploadStateTrackerBinder,
|
2019-08-12 17:59:07 +02:00
|
|
|
private val noticeItemFactory: NoticeItemFactory) {
|
2018-11-02 17:37:37 +01:00
|
|
|
|
|
|
|
|
2019-01-14 16:18:39 +01:00
|
|
|
fun create(event: TimelineEvent,
|
|
|
|
nextEvent: TimelineEvent?,
|
2019-06-20 16:27:43 +02:00
|
|
|
highlight: Boolean,
|
2018-12-19 11:50:44 +01:00
|
|
|
callback: TimelineEventController.Callback?
|
2019-04-05 10:40:59 +02:00
|
|
|
): VectorEpoxyModel<*>? {
|
2019-06-18 12:25:50 +02:00
|
|
|
event.root.eventId ?: return null
|
2018-12-19 11:50:44 +01:00
|
|
|
|
2019-06-18 12:25:50 +02:00
|
|
|
val informationData = messageInformationDataFactory.create(event, nextEvent)
|
2019-01-21 18:16:15 +01:00
|
|
|
|
2019-06-21 12:04:48 +02:00
|
|
|
if (event.root.isRedacted()) {
|
2019-05-17 17:15:44 +02:00
|
|
|
//message is redacted
|
2019-08-20 19:12:22 +02:00
|
|
|
val attributes = messageItemAttributesFactory.create(null, informationData, callback)
|
|
|
|
return buildRedactedItem(attributes, highlight)
|
2019-05-17 17:15:44 +02:00
|
|
|
}
|
2019-01-21 18:16:15 +01:00
|
|
|
|
2019-05-20 18:52:48 +02:00
|
|
|
val messageContent: MessageContent =
|
2019-07-10 17:37:22 +02:00
|
|
|
event.getLastMessageContent()
|
2019-08-20 19:12:22 +02:00
|
|
|
?: //Malformed content, we should echo something on screen
|
|
|
|
return DefaultItem_().text(stringProvider.getString(R.string.malformed_message))
|
2019-05-14 11:07:53 +02:00
|
|
|
|
2019-07-17 16:20:12 +02:00
|
|
|
if (messageContent.relatesTo?.type == RelationType.REPLACE
|
2019-08-20 19:12:22 +02:00
|
|
|
|| event.isEncrypted() && event.root.content.toModel<EncryptedEventContent>()?.relatesTo?.type == RelationType.REPLACE
|
2019-07-17 16:20:12 +02:00
|
|
|
) {
|
2019-08-12 17:59:07 +02:00
|
|
|
// This is an edit event, we should it when debugging as a notice event
|
|
|
|
return noticeItemFactory.create(event, highlight, callback)
|
2019-05-20 18:52:48 +02:00
|
|
|
}
|
2019-08-20 19:12:22 +02:00
|
|
|
val attributes = messageItemAttributesFactory.create(messageContent, informationData, callback)
|
|
|
|
|
2019-05-07 14:02:15 +02:00
|
|
|
// val all = event.root.toContent()
|
|
|
|
// val ev = all.toModel<Event>()
|
2019-01-21 18:16:15 +01:00
|
|
|
return when (messageContent) {
|
2019-06-04 17:16:02 +02:00
|
|
|
is MessageEmoteContent -> buildEmoteMessageItem(messageContent,
|
2019-08-20 19:12:22 +02:00
|
|
|
informationData,
|
|
|
|
highlight,
|
|
|
|
callback,
|
|
|
|
attributes)
|
2019-08-08 14:32:11 +02:00
|
|
|
is MessageTextContent -> buildTextMessageItem(messageContent,
|
2019-08-20 19:12:22 +02:00
|
|
|
informationData,
|
|
|
|
highlight,
|
|
|
|
callback,
|
|
|
|
attributes)
|
|
|
|
is MessageImageContent -> buildImageMessageItem(messageContent, informationData, highlight, callback, attributes)
|
|
|
|
is MessageNoticeContent -> buildNoticeMessageItem(messageContent, informationData, highlight, callback, attributes)
|
|
|
|
is MessageVideoContent -> buildVideoMessageItem(messageContent, informationData, highlight, callback, attributes)
|
|
|
|
is MessageFileContent -> buildFileMessageItem(messageContent, informationData, highlight, callback, attributes)
|
|
|
|
is MessageAudioContent -> buildAudioMessageItem(messageContent, informationData, highlight, callback, attributes)
|
2019-06-20 16:27:43 +02:00
|
|
|
else -> buildNotHandledMessageItem(messageContent, highlight)
|
2019-01-21 18:16:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-04 17:36:49 +02:00
|
|
|
private fun buildAudioMessageItem(messageContent: MessageAudioContent,
|
|
|
|
informationData: MessageInformationData,
|
2019-06-20 16:27:43 +02:00
|
|
|
highlight: Boolean,
|
2019-08-20 19:12:22 +02:00
|
|
|
callback: TimelineEventController.Callback?,
|
|
|
|
attributes: AbsMessageItem.Attributes): MessageFileItem? {
|
2019-04-12 12:38:02 +02:00
|
|
|
return MessageFileItem_()
|
2019-08-20 19:12:22 +02:00
|
|
|
.attributes(attributes)
|
2019-06-20 16:27:43 +02:00
|
|
|
.highlighted(highlight)
|
2019-04-12 12:38:02 +02:00
|
|
|
.filename(messageContent.body)
|
|
|
|
.iconRes(R.drawable.filetype_audio)
|
2019-05-08 15:49:32 +02:00
|
|
|
.clickListener(
|
2019-06-04 17:16:02 +02:00
|
|
|
DebouncedClickListener(View.OnClickListener {
|
2019-05-08 15:49:32 +02:00
|
|
|
callback?.onAudioMessageClicked(messageContent)
|
|
|
|
}))
|
2019-04-12 12:38:02 +02:00
|
|
|
}
|
|
|
|
|
2019-06-04 17:36:49 +02:00
|
|
|
private fun buildFileMessageItem(messageContent: MessageFileContent,
|
|
|
|
informationData: MessageInformationData,
|
2019-06-20 16:27:43 +02:00
|
|
|
highlight: Boolean,
|
2019-08-20 19:12:22 +02:00
|
|
|
callback: TimelineEventController.Callback?,
|
|
|
|
attributes: AbsMessageItem.Attributes): MessageFileItem? {
|
2019-04-12 12:38:02 +02:00
|
|
|
return MessageFileItem_()
|
2019-08-20 19:12:22 +02:00
|
|
|
.attributes(attributes)
|
2019-06-20 16:27:43 +02:00
|
|
|
.highlighted(highlight)
|
2019-04-12 12:38:02 +02:00
|
|
|
.filename(messageContent.body)
|
|
|
|
.iconRes(R.drawable.filetype_attachment)
|
2019-05-08 15:49:32 +02:00
|
|
|
.clickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { _ ->
|
2019-07-08 19:06:17 +02:00
|
|
|
callback?.onFileMessageClicked(informationData.eventId, messageContent)
|
2019-05-08 15:49:32 +02:00
|
|
|
}))
|
2019-04-12 12:38:02 +02:00
|
|
|
}
|
|
|
|
|
2019-06-20 16:27:43 +02:00
|
|
|
private fun buildNotHandledMessageItem(messageContent: MessageContent, highlight: Boolean): DefaultItem? {
|
2019-02-11 13:47:47 +01:00
|
|
|
val text = "${messageContent.type} message events are not yet handled"
|
2019-06-20 16:27:43 +02:00
|
|
|
return DefaultItem_()
|
|
|
|
.text(text)
|
|
|
|
.highlighted(highlight)
|
2019-02-11 13:47:47 +01:00
|
|
|
}
|
|
|
|
|
2019-06-04 17:36:49 +02:00
|
|
|
private fun buildImageMessageItem(messageContent: MessageImageContent,
|
|
|
|
informationData: MessageInformationData,
|
2019-06-20 16:27:43 +02:00
|
|
|
highlight: Boolean,
|
2019-08-20 19:12:22 +02:00
|
|
|
callback: TimelineEventController.Callback?,
|
|
|
|
attributes: AbsMessageItem.Attributes): MessageImageVideoItem? {
|
2019-01-24 18:04:55 +01:00
|
|
|
|
|
|
|
val (maxWidth, maxHeight) = timelineMediaSizeProvider.getMaxSize()
|
2019-04-11 19:19:52 +02:00
|
|
|
val data = ImageContentRenderer.Data(
|
|
|
|
filename = messageContent.body,
|
2019-07-09 11:20:00 +02:00
|
|
|
url = messageContent.getFileUrl(),
|
2019-06-24 22:33:30 +02:00
|
|
|
elementToDecrypt = messageContent.encryptedFileInfo?.toElementToDecrypt(),
|
2019-01-25 18:40:02 +01:00
|
|
|
height = messageContent.info?.height,
|
2019-01-24 18:04:55 +01:00
|
|
|
maxHeight = maxHeight,
|
2019-01-25 18:40:02 +01:00
|
|
|
width = messageContent.info?.width,
|
2019-01-24 18:04:55 +01:00
|
|
|
maxWidth = maxWidth,
|
2019-04-11 19:19:52 +02:00
|
|
|
orientation = messageContent.info?.orientation,
|
|
|
|
rotation = messageContent.info?.rotation
|
2019-01-23 20:29:47 +01:00
|
|
|
)
|
2019-04-11 19:19:52 +02:00
|
|
|
return MessageImageVideoItem_()
|
2019-08-20 19:12:22 +02:00
|
|
|
.attributes(attributes)
|
2019-06-26 15:22:44 +02:00
|
|
|
.imageContentRenderer(imageContentRenderer)
|
|
|
|
.contentUploadStateTrackerBinder(contentUploadStateTrackerBinder)
|
2019-04-11 19:19:52 +02:00
|
|
|
.playable(messageContent.info?.mimeType == "image/gif")
|
2019-06-20 16:27:43 +02:00
|
|
|
.highlighted(highlight)
|
2019-02-19 11:57:17 +01:00
|
|
|
.mediaData(data)
|
2019-05-08 15:49:32 +02:00
|
|
|
.clickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onImageMessageClicked(messageContent, data, view)
|
|
|
|
}))
|
2019-01-22 18:43:15 +01:00
|
|
|
}
|
|
|
|
|
2019-06-04 17:36:49 +02:00
|
|
|
private fun buildVideoMessageItem(messageContent: MessageVideoContent,
|
|
|
|
informationData: MessageInformationData,
|
2019-06-20 16:27:43 +02:00
|
|
|
highlight: Boolean,
|
2019-08-20 19:12:22 +02:00
|
|
|
callback: TimelineEventController.Callback?,
|
|
|
|
attributes: AbsMessageItem.Attributes): MessageImageVideoItem? {
|
2019-04-11 19:19:52 +02:00
|
|
|
|
|
|
|
val (maxWidth, maxHeight) = timelineMediaSizeProvider.getMaxSize()
|
2019-04-12 13:46:59 +02:00
|
|
|
val thumbnailData = ImageContentRenderer.Data(
|
2019-04-11 19:19:52 +02:00
|
|
|
filename = messageContent.body,
|
2019-07-17 16:20:12 +02:00
|
|
|
url = messageContent.videoInfo?.thumbnailFile?.url
|
2019-08-20 19:12:22 +02:00
|
|
|
?: messageContent.videoInfo?.thumbnailUrl,
|
2019-06-24 22:33:30 +02:00
|
|
|
elementToDecrypt = messageContent.videoInfo?.thumbnailFile?.toElementToDecrypt(),
|
2019-06-21 15:08:09 +02:00
|
|
|
height = messageContent.videoInfo?.height,
|
2019-04-11 19:19:52 +02:00
|
|
|
maxHeight = maxHeight,
|
2019-06-21 15:08:09 +02:00
|
|
|
width = messageContent.videoInfo?.width,
|
2019-04-11 19:19:52 +02:00
|
|
|
maxWidth = maxWidth
|
|
|
|
)
|
2019-04-12 13:46:59 +02:00
|
|
|
|
|
|
|
val videoData = VideoContentRenderer.Data(
|
2019-07-08 17:07:21 +02:00
|
|
|
eventId = informationData.eventId,
|
2019-04-12 13:46:59 +02:00
|
|
|
filename = messageContent.body,
|
2019-07-09 11:20:00 +02:00
|
|
|
url = messageContent.getFileUrl(),
|
2019-07-08 17:07:21 +02:00
|
|
|
elementToDecrypt = messageContent.encryptedFileInfo?.toElementToDecrypt(),
|
2019-04-12 13:46:59 +02:00
|
|
|
thumbnailMediaData = thumbnailData
|
|
|
|
)
|
|
|
|
|
2019-04-11 19:19:52 +02:00
|
|
|
return MessageImageVideoItem_()
|
2019-08-20 19:12:22 +02:00
|
|
|
.attributes(attributes)
|
2019-06-26 15:22:44 +02:00
|
|
|
.imageContentRenderer(imageContentRenderer)
|
|
|
|
.contentUploadStateTrackerBinder(contentUploadStateTrackerBinder)
|
2019-04-11 19:19:52 +02:00
|
|
|
.playable(true)
|
2019-06-20 16:27:43 +02:00
|
|
|
.highlighted(highlight)
|
2019-04-12 13:46:59 +02:00
|
|
|
.mediaData(thumbnailData)
|
|
|
|
.clickListener { view -> callback?.onVideoMessageClicked(messageContent, videoData, view) }
|
2019-04-11 19:19:52 +02:00
|
|
|
}
|
|
|
|
|
2019-08-08 14:32:11 +02:00
|
|
|
private fun buildTextMessageItem(messageContent: MessageTextContent,
|
2019-01-22 18:43:15 +01:00
|
|
|
informationData: MessageInformationData,
|
2019-06-20 16:27:43 +02:00
|
|
|
highlight: Boolean,
|
2019-08-20 19:12:22 +02:00
|
|
|
callback: TimelineEventController.Callback?,
|
|
|
|
attributes: AbsMessageItem.Attributes): MessageTextItem? {
|
2019-01-21 18:16:15 +01:00
|
|
|
|
2019-04-09 19:57:43 +02:00
|
|
|
val bodyToUse = messageContent.formattedBody?.let {
|
2019-07-01 20:05:48 +02:00
|
|
|
htmlRenderer.get().render(it.trim())
|
2019-04-09 19:57:43 +02:00
|
|
|
} ?: messageContent.body
|
2019-02-21 19:21:08 +01:00
|
|
|
|
2019-04-11 19:19:52 +02:00
|
|
|
val linkifiedBody = linkifyBody(bodyToUse, callback)
|
2019-05-20 18:52:48 +02:00
|
|
|
|
2019-02-19 19:12:58 +01:00
|
|
|
return MessageTextItem_()
|
2019-05-20 18:52:48 +02:00
|
|
|
.apply {
|
2019-06-18 12:25:50 +02:00
|
|
|
if (informationData.hasBeenEdited) {
|
2019-08-07 12:57:11 +02:00
|
|
|
val spannable = annotateWithEdited(linkifiedBody, callback, informationData)
|
2019-05-20 18:52:48 +02:00
|
|
|
message(spannable)
|
|
|
|
} else {
|
|
|
|
message(linkifiedBody)
|
|
|
|
}
|
|
|
|
}
|
2019-08-20 19:12:22 +02:00
|
|
|
.attributes(attributes)
|
2019-06-20 16:27:43 +02:00
|
|
|
.highlighted(highlight)
|
|
|
|
.urlClickCallback(callback)
|
2019-08-20 19:12:22 +02:00
|
|
|
//click on the text
|
2019-02-19 19:12:58 +01:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:27:57 +02:00
|
|
|
private fun annotateWithEdited(linkifiedBody: CharSequence,
|
|
|
|
callback: TimelineEventController.Callback?,
|
2019-08-07 12:57:11 +02:00
|
|
|
informationData: MessageInformationData): SpannableStringBuilder {
|
2019-05-21 14:26:46 +02:00
|
|
|
val spannable = SpannableStringBuilder()
|
|
|
|
spannable.append(linkifiedBody)
|
2019-07-10 15:29:52 +02:00
|
|
|
val editedSuffix = stringProvider.getString(R.string.edited_suffix)
|
2019-05-21 14:26:46 +02:00
|
|
|
spannable.append(" ").append(editedSuffix)
|
|
|
|
val color = colorProvider.getColorFromAttribute(R.attr.vctr_list_header_secondary_text_color)
|
2019-07-19 09:57:57 +02:00
|
|
|
val editStart = spannable.lastIndexOf(editedSuffix)
|
2019-05-21 14:26:46 +02:00
|
|
|
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?) {
|
2019-08-07 12:57:11 +02:00
|
|
|
callback?.onEditedDecorationClicked(informationData)
|
2019-05-21 14:26:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun updateDrawState(ds: TextPaint?) {
|
|
|
|
//nop
|
|
|
|
}
|
|
|
|
},
|
2019-08-20 19:12:22 +02:00
|
|
|
editStart,
|
|
|
|
editEnd,
|
|
|
|
Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
|
2019-05-21 14:26:46 +02:00
|
|
|
return spannable
|
|
|
|
}
|
|
|
|
|
2019-06-04 17:36:49 +02:00
|
|
|
private fun buildNoticeMessageItem(messageContent: MessageNoticeContent,
|
|
|
|
informationData: MessageInformationData,
|
2019-06-20 16:27:43 +02:00
|
|
|
highlight: Boolean,
|
2019-08-20 19:12:22 +02:00
|
|
|
callback: TimelineEventController.Callback?,
|
|
|
|
attributes: AbsMessageItem.Attributes): MessageTextItem? {
|
2019-02-20 11:39:25 +01:00
|
|
|
|
|
|
|
val message = messageContent.body.let {
|
|
|
|
val formattedBody = span {
|
|
|
|
text = it
|
2019-06-06 14:37:30 +02:00
|
|
|
textColor = colorProvider.getColorFromAttribute(R.attr.riotx_text_secondary)
|
2019-02-20 11:39:25 +01:00
|
|
|
textStyle = "italic"
|
|
|
|
}
|
|
|
|
linkifyBody(formattedBody, callback)
|
|
|
|
}
|
|
|
|
return MessageTextItem_()
|
2019-08-20 19:12:22 +02:00
|
|
|
.attributes(attributes)
|
2019-02-20 11:39:25 +01:00
|
|
|
.message(message)
|
2019-06-20 16:27:43 +02:00
|
|
|
.highlighted(highlight)
|
|
|
|
.urlClickCallback(callback)
|
2019-02-20 11:39:25 +01:00
|
|
|
}
|
|
|
|
|
2019-06-04 17:36:49 +02:00
|
|
|
private fun buildEmoteMessageItem(messageContent: MessageEmoteContent,
|
|
|
|
informationData: MessageInformationData,
|
2019-06-20 16:27:43 +02:00
|
|
|
highlight: Boolean,
|
2019-08-20 19:12:22 +02:00
|
|
|
callback: TimelineEventController.Callback?,
|
|
|
|
attributes: AbsMessageItem.Attributes): MessageTextItem? {
|
2019-02-19 19:12:58 +01:00
|
|
|
|
2019-01-22 18:43:15 +01:00
|
|
|
val message = messageContent.body.let {
|
2019-02-19 19:12:58 +01:00
|
|
|
val formattedBody = "* ${informationData.memberName} $it"
|
|
|
|
linkifyBody(formattedBody, callback)
|
2019-01-07 11:39:26 +01:00
|
|
|
}
|
2019-02-19 11:57:17 +01:00
|
|
|
return MessageTextItem_()
|
2019-05-21 14:26:46 +02:00
|
|
|
.apply {
|
2019-06-18 12:25:50 +02:00
|
|
|
if (informationData.hasBeenEdited) {
|
2019-08-07 12:57:11 +02:00
|
|
|
val spannable = annotateWithEdited(message, callback, informationData)
|
2019-05-21 14:26:46 +02:00
|
|
|
message(spannable)
|
|
|
|
} else {
|
|
|
|
message(message)
|
|
|
|
}
|
|
|
|
}
|
2019-08-20 19:12:22 +02:00
|
|
|
.attributes(attributes)
|
2019-06-20 16:27:43 +02:00
|
|
|
.highlighted(highlight)
|
|
|
|
.urlClickCallback(callback)
|
2018-11-02 17:37:37 +01:00
|
|
|
}
|
|
|
|
|
2019-08-20 19:12:22 +02:00
|
|
|
private fun buildRedactedItem(attributes: AbsMessageItem.Attributes,
|
|
|
|
highlight: Boolean): RedactedMessageItem? {
|
2019-05-17 17:15:44 +02:00
|
|
|
return RedactedMessageItem_()
|
2019-08-20 19:12:22 +02:00
|
|
|
.attributes(attributes)
|
2019-06-20 16:27:43 +02:00
|
|
|
.highlighted(highlight)
|
2019-05-17 17:15:44 +02:00
|
|
|
}
|
|
|
|
|
2019-05-08 10:33:14 +02:00
|
|
|
private fun linkifyBody(body: CharSequence, callback: TimelineEventController.Callback?): CharSequence {
|
2019-02-19 19:12:58 +01:00
|
|
|
val spannable = SpannableStringBuilder(body)
|
|
|
|
MatrixLinkify.addLinks(spannable, object : MatrixPermalinkSpan.Callback {
|
|
|
|
override fun onUrlClicked(url: String) {
|
|
|
|
callback?.onUrlClicked(url)
|
|
|
|
}
|
|
|
|
})
|
2019-04-09 17:33:47 +02:00
|
|
|
VectorLinkify.addLinks(spannable, true)
|
2019-02-19 19:12:58 +01:00
|
|
|
return spannable
|
|
|
|
}
|
2018-11-02 17:37:37 +01:00
|
|
|
}
|