2019-01-18 10:12:08 +00:00
|
|
|
/*
|
2019-01-25 13:04:59 +00:00
|
|
|
* Copyright 2019 New Vector Ltd
|
2019-01-18 10:12:08 +00:00
|
|
|
*
|
2019-01-25 13:04:59 +00: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 10:12:08 +00:00
|
|
|
*
|
2019-01-25 13:04:59 +00: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 10:12:08 +00:00
|
|
|
*/
|
|
|
|
|
2019-07-02 15:27:08 +00:00
|
|
|
package im.vector.riotx.features.home.room.detail.timeline.factory
|
2018-11-02 16:37:37 +00:00
|
|
|
|
2019-01-07 10:39:26 +00:00
|
|
|
import android.text.SpannableStringBuilder
|
2019-05-20 16:52:48 +00:00
|
|
|
import android.text.Spanned
|
2019-05-21 12:12:18 +00:00
|
|
|
import android.text.TextPaint
|
|
|
|
import android.text.style.ClickableSpan
|
2019-05-20 16:52:48 +00:00
|
|
|
import android.text.style.ForegroundColorSpan
|
2019-05-21 12:12:18 +00:00
|
|
|
import android.text.style.RelativeSizeSpan
|
2019-05-08 13:49:32 +00:00
|
|
|
import android.view.View
|
2019-07-01 18:05:48 +00:00
|
|
|
import dagger.Lazy
|
2019-01-07 10:39:26 +00:00
|
|
|
import im.vector.matrix.android.api.permalinks.MatrixLinkify
|
|
|
|
import im.vector.matrix.android.api.permalinks.MatrixPermalinkSpan
|
2019-05-20 16:52:48 +00:00
|
|
|
import im.vector.matrix.android.api.session.events.model.RelationType
|
2019-07-17 14:20:12 +00:00
|
|
|
import im.vector.matrix.android.api.session.events.model.toModel
|
2019-09-02 12:24:36 +00:00
|
|
|
import im.vector.matrix.android.api.session.room.model.message.*
|
2019-01-25 17:40:02 +00:00
|
|
|
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
2019-07-10 15:37:22 +00:00
|
|
|
import im.vector.matrix.android.api.session.room.timeline.getLastMessageContent
|
2019-06-24 20:33:30 +00:00
|
|
|
import im.vector.matrix.android.internal.crypto.attachments.toElementToDecrypt
|
2019-07-17 14:20:12 +00:00
|
|
|
import im.vector.matrix.android.internal.crypto.model.event.EncryptedEventContent
|
2019-07-02 15:27:08 +00: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-09-02 12:24:36 +00:00
|
|
|
import im.vector.riotx.features.home.room.detail.timeline.item.*
|
2019-07-02 15:27:08 +00:00
|
|
|
import im.vector.riotx.features.home.room.detail.timeline.util.MessageInformationDataFactory
|
|
|
|
import im.vector.riotx.features.html.EventHtmlRenderer
|
|
|
|
import im.vector.riotx.features.media.ImageContentRenderer
|
|
|
|
import im.vector.riotx.features.media.VideoContentRenderer
|
2019-02-20 10:39:25 +00:00
|
|
|
import me.gujun.android.span.span
|
2019-06-18 18:00:20 +00:00
|
|
|
import javax.inject.Inject
|
2018-11-02 16:37:37 +00:00
|
|
|
|
2019-06-18 18:00:20 +00:00
|
|
|
class MessageItemFactory @Inject constructor(
|
2019-06-26 13:22:44 +00:00
|
|
|
private val avatarRenderer: AvatarRenderer,
|
2019-06-18 18:00:20 +00:00
|
|
|
private val colorProvider: ColorProvider,
|
|
|
|
private val timelineMediaSizeProvider: TimelineMediaSizeProvider,
|
2019-07-01 18:05:48 +00:00
|
|
|
private val htmlRenderer: Lazy<EventHtmlRenderer>,
|
2019-06-18 18:00:20 +00:00
|
|
|
private val stringProvider: StringProvider,
|
2019-06-26 13:22:44 +00:00
|
|
|
private val emojiCompatFontProvider: EmojiCompatFontProvider,
|
|
|
|
private val imageContentRenderer: ImageContentRenderer,
|
2019-06-26 18:58:46 +00:00
|
|
|
private val messageInformationDataFactory: MessageInformationDataFactory,
|
2019-07-19 14:13:55 +00:00
|
|
|
private val contentUploadStateTrackerBinder: ContentUploadStateTrackerBinder,
|
2019-08-12 15:59:07 +00:00
|
|
|
private val noticeItemFactory: NoticeItemFactory) {
|
2018-11-02 16:37:37 +00:00
|
|
|
|
|
|
|
|
2019-01-14 15:18:39 +00:00
|
|
|
fun create(event: TimelineEvent,
|
|
|
|
nextEvent: TimelineEvent?,
|
2019-06-20 14:27:43 +00:00
|
|
|
highlight: Boolean,
|
2018-12-19 10:50:44 +00:00
|
|
|
callback: TimelineEventController.Callback?
|
2019-04-05 08:40:59 +00:00
|
|
|
): VectorEpoxyModel<*>? {
|
2019-06-18 10:25:50 +00:00
|
|
|
event.root.eventId ?: return null
|
2018-12-19 10:50:44 +00:00
|
|
|
|
2019-06-18 10:25:50 +00:00
|
|
|
val informationData = messageInformationDataFactory.create(event, nextEvent)
|
2019-01-21 17:16:15 +00:00
|
|
|
|
2019-06-21 10:04:48 +00:00
|
|
|
if (event.root.isRedacted()) {
|
2019-05-17 15:15:44 +00:00
|
|
|
//message is redacted
|
2019-06-20 14:27:43 +00:00
|
|
|
return buildRedactedItem(informationData, highlight, callback)
|
2019-05-17 15:15:44 +00:00
|
|
|
}
|
2019-01-21 17:16:15 +00:00
|
|
|
|
2019-05-20 16:52:48 +00:00
|
|
|
val messageContent: MessageContent =
|
2019-07-10 15:37:22 +00:00
|
|
|
event.getLastMessageContent()
|
2019-09-02 12:24:36 +00:00
|
|
|
?: //Malformed content, we should echo something on screen
|
|
|
|
return buildNotHandledMessageItem(stringProvider.getString(R.string.malformed_message),
|
|
|
|
informationData, highlight, callback)
|
2019-05-14 09:07:53 +00:00
|
|
|
|
2019-07-17 14:20:12 +00:00
|
|
|
if (messageContent.relatesTo?.type == RelationType.REPLACE
|
2019-09-02 12:24:36 +00:00
|
|
|
|| event.isEncrypted() && event.root.content.toModel<EncryptedEventContent>()?.relatesTo?.type == RelationType.REPLACE
|
2019-07-17 14:20:12 +00:00
|
|
|
) {
|
2019-09-02 12:24:36 +00:00
|
|
|
// This is an edit event, we should display it when debugging as a notice event
|
2019-08-12 15:59:07 +00:00
|
|
|
return noticeItemFactory.create(event, highlight, callback)
|
2019-05-20 16:52:48 +00:00
|
|
|
}
|
2019-05-07 12:02:15 +00:00
|
|
|
// val all = event.root.toContent()
|
|
|
|
// val ev = all.toModel<Event>()
|
2019-01-21 17:16:15 +00:00
|
|
|
return when (messageContent) {
|
2019-09-02 12:24:36 +00:00
|
|
|
is MessageEmoteContent -> buildEmoteMessageItem(messageContent, informationData, highlight, callback)
|
|
|
|
is MessageTextContent -> buildTextMessageItem(messageContent, informationData, highlight, callback)
|
2019-06-20 14:27:43 +00:00
|
|
|
is MessageImageContent -> buildImageMessageItem(messageContent, informationData, highlight, callback)
|
|
|
|
is MessageNoticeContent -> buildNoticeMessageItem(messageContent, informationData, highlight, callback)
|
|
|
|
is MessageVideoContent -> buildVideoMessageItem(messageContent, informationData, highlight, callback)
|
|
|
|
is MessageFileContent -> buildFileMessageItem(messageContent, informationData, highlight, callback)
|
|
|
|
is MessageAudioContent -> buildAudioMessageItem(messageContent, informationData, highlight, callback)
|
2019-09-02 12:24:36 +00:00
|
|
|
else -> buildNotHandledMessageItem("${messageContent.type} message events are not yet handled",
|
|
|
|
informationData, highlight, callback)
|
2019-01-21 17:16:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-04 15:36:49 +00:00
|
|
|
private fun buildAudioMessageItem(messageContent: MessageAudioContent,
|
|
|
|
informationData: MessageInformationData,
|
2019-06-20 14:27:43 +00:00
|
|
|
highlight: Boolean,
|
2019-04-12 10:38:02 +00:00
|
|
|
callback: TimelineEventController.Callback?): MessageFileItem? {
|
|
|
|
return MessageFileItem_()
|
2019-06-26 13:22:44 +00:00
|
|
|
.avatarRenderer(avatarRenderer)
|
2019-07-12 08:16:43 +00:00
|
|
|
.colorProvider(colorProvider)
|
2019-04-12 10:38:02 +00:00
|
|
|
.informationData(informationData)
|
2019-06-20 14:27:43 +00:00
|
|
|
.highlighted(highlight)
|
2019-06-05 21:45:46 +00:00
|
|
|
.avatarCallback(callback)
|
2019-08-08 17:59:20 +00:00
|
|
|
.readReceiptsCallback(callback)
|
2019-04-12 10:38:02 +00:00
|
|
|
.filename(messageContent.body)
|
|
|
|
.iconRes(R.drawable.filetype_audio)
|
2019-05-16 16:33:32 +00:00
|
|
|
.reactionPillCallback(callback)
|
2019-06-04 15:16:02 +00:00
|
|
|
.emojiTypeFace(emojiCompatFontProvider.typeface)
|
2019-05-08 13:49:32 +00:00
|
|
|
.cellClickListener(
|
2019-06-04 15:16:02 +00:00
|
|
|
DebouncedClickListener(View.OnClickListener { view: View ->
|
2019-05-10 10:14:40 +00:00
|
|
|
callback?.onEventCellClicked(informationData, messageContent, view)
|
2019-05-08 13:49:32 +00:00
|
|
|
}))
|
|
|
|
.clickListener(
|
2019-06-04 15:16:02 +00:00
|
|
|
DebouncedClickListener(View.OnClickListener {
|
2019-05-08 13:49:32 +00:00
|
|
|
callback?.onAudioMessageClicked(messageContent)
|
|
|
|
}))
|
2019-05-08 08:33:14 +00:00
|
|
|
.longClickListener { view ->
|
2019-05-10 10:14:40 +00:00
|
|
|
return@longClickListener callback?.onEventLongClicked(informationData, messageContent, view)
|
2019-09-02 12:24:36 +00:00
|
|
|
?: false
|
2019-05-08 08:33:14 +00:00
|
|
|
}
|
2019-04-12 10:38:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-04 15:36:49 +00:00
|
|
|
private fun buildFileMessageItem(messageContent: MessageFileContent,
|
|
|
|
informationData: MessageInformationData,
|
2019-06-20 14:27:43 +00:00
|
|
|
highlight: Boolean,
|
2019-04-12 10:38:02 +00:00
|
|
|
callback: TimelineEventController.Callback?): MessageFileItem? {
|
|
|
|
return MessageFileItem_()
|
2019-06-26 13:22:44 +00:00
|
|
|
.avatarRenderer(avatarRenderer)
|
2019-07-12 08:16:43 +00:00
|
|
|
.colorProvider(colorProvider)
|
2019-04-12 10:38:02 +00:00
|
|
|
.informationData(informationData)
|
2019-06-20 14:27:43 +00:00
|
|
|
.highlighted(highlight)
|
2019-06-05 21:45:46 +00:00
|
|
|
.avatarCallback(callback)
|
2019-04-12 10:38:02 +00:00
|
|
|
.filename(messageContent.body)
|
2019-05-16 16:33:32 +00:00
|
|
|
.reactionPillCallback(callback)
|
2019-08-08 17:59:20 +00:00
|
|
|
.readReceiptsCallback(callback)
|
2019-06-04 15:16:02 +00:00
|
|
|
.emojiTypeFace(emojiCompatFontProvider.typeface)
|
2019-04-12 10:38:02 +00:00
|
|
|
.iconRes(R.drawable.filetype_attachment)
|
2019-05-08 13:49:32 +00:00
|
|
|
.cellClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
2019-05-10 10:14:40 +00:00
|
|
|
callback?.onEventCellClicked(informationData, messageContent, view)
|
2019-05-08 13:49:32 +00:00
|
|
|
}))
|
2019-05-10 10:14:40 +00:00
|
|
|
.longClickListener { view ->
|
|
|
|
return@longClickListener callback?.onEventLongClicked(informationData, messageContent, view)
|
2019-09-02 12:24:36 +00:00
|
|
|
?: false
|
2019-05-10 10:14:40 +00:00
|
|
|
}
|
2019-05-08 13:49:32 +00:00
|
|
|
.clickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { _ ->
|
2019-07-08 17:06:17 +00:00
|
|
|
callback?.onFileMessageClicked(informationData.eventId, messageContent)
|
2019-05-08 13:49:32 +00:00
|
|
|
}))
|
2019-04-12 10:38:02 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 12:24:36 +00:00
|
|
|
private fun buildNotHandledMessageItem(text: String,
|
|
|
|
informationData: MessageInformationData,
|
|
|
|
highlight: Boolean,
|
|
|
|
callback: TimelineEventController.Callback?): DefaultItem? {
|
2019-06-20 14:27:43 +00:00
|
|
|
return DefaultItem_()
|
|
|
|
.text(text)
|
2019-09-02 12:24:36 +00:00
|
|
|
.avatarRenderer(avatarRenderer)
|
2019-06-20 14:27:43 +00:00
|
|
|
.highlighted(highlight)
|
2019-09-02 12:24:36 +00:00
|
|
|
.informationData(informationData)
|
|
|
|
.baseCallback(callback)
|
|
|
|
.readReceiptsCallback(callback)
|
2019-02-11 12:47:47 +00:00
|
|
|
}
|
|
|
|
|
2019-06-04 15:36:49 +00:00
|
|
|
private fun buildImageMessageItem(messageContent: MessageImageContent,
|
|
|
|
informationData: MessageInformationData,
|
2019-06-20 14:27:43 +00:00
|
|
|
highlight: Boolean,
|
2019-04-11 17:19:52 +00:00
|
|
|
callback: TimelineEventController.Callback?): MessageImageVideoItem? {
|
2019-01-24 17:04:55 +00:00
|
|
|
|
|
|
|
val (maxWidth, maxHeight) = timelineMediaSizeProvider.getMaxSize()
|
2019-04-11 17:19:52 +00:00
|
|
|
val data = ImageContentRenderer.Data(
|
|
|
|
filename = messageContent.body,
|
2019-07-09 09:20:00 +00:00
|
|
|
url = messageContent.getFileUrl(),
|
2019-06-24 20:33:30 +00:00
|
|
|
elementToDecrypt = messageContent.encryptedFileInfo?.toElementToDecrypt(),
|
2019-01-25 17:40:02 +00:00
|
|
|
height = messageContent.info?.height,
|
2019-01-24 17:04:55 +00:00
|
|
|
maxHeight = maxHeight,
|
2019-01-25 17:40:02 +00:00
|
|
|
width = messageContent.info?.width,
|
2019-01-24 17:04:55 +00:00
|
|
|
maxWidth = maxWidth,
|
2019-04-11 17:19:52 +00:00
|
|
|
orientation = messageContent.info?.orientation,
|
|
|
|
rotation = messageContent.info?.rotation
|
2019-01-23 19:29:47 +00:00
|
|
|
)
|
2019-04-11 17:19:52 +00:00
|
|
|
return MessageImageVideoItem_()
|
2019-06-26 13:22:44 +00:00
|
|
|
.avatarRenderer(avatarRenderer)
|
2019-07-12 08:16:43 +00:00
|
|
|
.colorProvider(colorProvider)
|
2019-06-26 13:22:44 +00:00
|
|
|
.imageContentRenderer(imageContentRenderer)
|
|
|
|
.contentUploadStateTrackerBinder(contentUploadStateTrackerBinder)
|
2019-04-11 17:19:52 +00:00
|
|
|
.playable(messageContent.info?.mimeType == "image/gif")
|
2019-02-19 10:57:17 +00:00
|
|
|
.informationData(informationData)
|
2019-06-20 14:27:43 +00:00
|
|
|
.highlighted(highlight)
|
2019-06-05 21:45:46 +00:00
|
|
|
.avatarCallback(callback)
|
2019-02-19 10:57:17 +00:00
|
|
|
.mediaData(data)
|
2019-05-16 16:33:32 +00:00
|
|
|
.reactionPillCallback(callback)
|
2019-08-08 17:59:20 +00:00
|
|
|
.readReceiptsCallback(callback)
|
2019-06-04 15:16:02 +00:00
|
|
|
.emojiTypeFace(emojiCompatFontProvider.typeface)
|
2019-05-08 13:49:32 +00:00
|
|
|
.clickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onImageMessageClicked(messageContent, data, view)
|
|
|
|
}))
|
|
|
|
.cellClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
2019-05-10 10:14:40 +00:00
|
|
|
callback?.onEventCellClicked(informationData, messageContent, view)
|
2019-05-08 13:49:32 +00:00
|
|
|
}))
|
2019-05-08 08:33:14 +00:00
|
|
|
.longClickListener { view ->
|
2019-05-10 10:14:40 +00:00
|
|
|
return@longClickListener callback?.onEventLongClicked(informationData, messageContent, view)
|
2019-09-02 12:24:36 +00:00
|
|
|
?: false
|
2019-05-08 08:33:14 +00:00
|
|
|
}
|
2019-01-22 17:43:15 +00:00
|
|
|
}
|
|
|
|
|
2019-06-04 15:36:49 +00:00
|
|
|
private fun buildVideoMessageItem(messageContent: MessageVideoContent,
|
|
|
|
informationData: MessageInformationData,
|
2019-06-20 14:27:43 +00:00
|
|
|
highlight: Boolean,
|
2019-04-11 17:19:52 +00:00
|
|
|
callback: TimelineEventController.Callback?): MessageImageVideoItem? {
|
|
|
|
|
|
|
|
val (maxWidth, maxHeight) = timelineMediaSizeProvider.getMaxSize()
|
2019-04-12 11:46:59 +00:00
|
|
|
val thumbnailData = ImageContentRenderer.Data(
|
2019-04-11 17:19:52 +00:00
|
|
|
filename = messageContent.body,
|
2019-07-17 14:20:12 +00:00
|
|
|
url = messageContent.videoInfo?.thumbnailFile?.url
|
2019-09-02 12:24:36 +00:00
|
|
|
?: messageContent.videoInfo?.thumbnailUrl,
|
2019-06-24 20:33:30 +00:00
|
|
|
elementToDecrypt = messageContent.videoInfo?.thumbnailFile?.toElementToDecrypt(),
|
2019-06-21 13:08:09 +00:00
|
|
|
height = messageContent.videoInfo?.height,
|
2019-04-11 17:19:52 +00:00
|
|
|
maxHeight = maxHeight,
|
2019-06-21 13:08:09 +00:00
|
|
|
width = messageContent.videoInfo?.width,
|
2019-04-11 17:19:52 +00:00
|
|
|
maxWidth = maxWidth
|
|
|
|
)
|
2019-04-12 11:46:59 +00:00
|
|
|
|
|
|
|
val videoData = VideoContentRenderer.Data(
|
2019-07-08 15:07:21 +00:00
|
|
|
eventId = informationData.eventId,
|
2019-04-12 11:46:59 +00:00
|
|
|
filename = messageContent.body,
|
2019-07-09 09:20:00 +00:00
|
|
|
url = messageContent.getFileUrl(),
|
2019-07-08 15:07:21 +00:00
|
|
|
elementToDecrypt = messageContent.encryptedFileInfo?.toElementToDecrypt(),
|
2019-04-12 11:46:59 +00:00
|
|
|
thumbnailMediaData = thumbnailData
|
|
|
|
)
|
|
|
|
|
2019-04-11 17:19:52 +00:00
|
|
|
return MessageImageVideoItem_()
|
2019-06-26 13:22:44 +00:00
|
|
|
.imageContentRenderer(imageContentRenderer)
|
|
|
|
.contentUploadStateTrackerBinder(contentUploadStateTrackerBinder)
|
|
|
|
.avatarRenderer(avatarRenderer)
|
2019-07-12 08:16:43 +00:00
|
|
|
.colorProvider(colorProvider)
|
2019-04-11 17:19:52 +00:00
|
|
|
.playable(true)
|
|
|
|
.informationData(informationData)
|
2019-06-20 14:27:43 +00:00
|
|
|
.highlighted(highlight)
|
2019-06-05 21:45:46 +00:00
|
|
|
.avatarCallback(callback)
|
2019-04-12 11:46:59 +00:00
|
|
|
.mediaData(thumbnailData)
|
2019-05-16 16:33:32 +00:00
|
|
|
.reactionPillCallback(callback)
|
2019-08-08 17:59:20 +00:00
|
|
|
.readReceiptsCallback(callback)
|
2019-06-04 15:16:02 +00:00
|
|
|
.emojiTypeFace(emojiCompatFontProvider.typeface)
|
2019-05-08 13:49:32 +00:00
|
|
|
.cellClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
2019-05-10 10:14:40 +00:00
|
|
|
callback?.onEventCellClicked(informationData, messageContent, view)
|
2019-05-08 13:49:32 +00:00
|
|
|
}))
|
2019-04-12 11:46:59 +00:00
|
|
|
.clickListener { view -> callback?.onVideoMessageClicked(messageContent, videoData, view) }
|
2019-05-08 08:33:14 +00:00
|
|
|
.longClickListener { view ->
|
2019-05-10 10:14:40 +00:00
|
|
|
return@longClickListener callback?.onEventLongClicked(informationData, messageContent, view)
|
2019-09-02 12:24:36 +00:00
|
|
|
?: false
|
2019-05-08 08:33:14 +00:00
|
|
|
}
|
2019-04-11 17:19:52 +00:00
|
|
|
}
|
|
|
|
|
2019-08-08 12:32:11 +00:00
|
|
|
private fun buildTextMessageItem(messageContent: MessageTextContent,
|
2019-01-22 17:43:15 +00:00
|
|
|
informationData: MessageInformationData,
|
2019-06-20 14:27:43 +00:00
|
|
|
highlight: Boolean,
|
2019-01-21 17:16:15 +00:00
|
|
|
callback: TimelineEventController.Callback?): MessageTextItem? {
|
|
|
|
|
2019-04-09 17:57:43 +00:00
|
|
|
val bodyToUse = messageContent.formattedBody?.let {
|
2019-07-01 18:05:48 +00:00
|
|
|
htmlRenderer.get().render(it.trim())
|
2019-04-09 17:57:43 +00:00
|
|
|
} ?: messageContent.body
|
2019-02-21 18:21:08 +00:00
|
|
|
|
2019-04-11 17:19:52 +00:00
|
|
|
val linkifiedBody = linkifyBody(bodyToUse, callback)
|
2019-05-20 16:52:48 +00:00
|
|
|
|
2019-02-19 18:12:58 +00:00
|
|
|
return MessageTextItem_()
|
2019-05-20 16:52:48 +00:00
|
|
|
.apply {
|
2019-06-18 10:25:50 +00:00
|
|
|
if (informationData.hasBeenEdited) {
|
2019-08-07 10:57:11 +00:00
|
|
|
val spannable = annotateWithEdited(linkifiedBody, callback, informationData)
|
2019-05-20 16:52:48 +00:00
|
|
|
message(spannable)
|
|
|
|
} else {
|
|
|
|
message(linkifiedBody)
|
|
|
|
}
|
|
|
|
}
|
2019-06-26 13:22:44 +00:00
|
|
|
.avatarRenderer(avatarRenderer)
|
2019-02-19 18:12:58 +00:00
|
|
|
.informationData(informationData)
|
2019-07-12 08:16:43 +00:00
|
|
|
.colorProvider(colorProvider)
|
2019-06-20 14:27:43 +00:00
|
|
|
.highlighted(highlight)
|
2019-06-05 21:45:46 +00:00
|
|
|
.avatarCallback(callback)
|
2019-06-20 14:27:43 +00:00
|
|
|
.urlClickCallback(callback)
|
2019-05-16 16:33:32 +00:00
|
|
|
.reactionPillCallback(callback)
|
2019-08-08 17:59:20 +00:00
|
|
|
.readReceiptsCallback(callback)
|
2019-06-04 15:16:02 +00:00
|
|
|
.emojiTypeFace(emojiCompatFontProvider.typeface)
|
2019-05-08 13:49:32 +00:00
|
|
|
//click on the text
|
|
|
|
.cellClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
2019-05-10 10:14:40 +00:00
|
|
|
callback?.onEventCellClicked(informationData, messageContent, view)
|
2019-05-08 13:49:32 +00:00
|
|
|
}))
|
2019-05-07 12:02:15 +00:00
|
|
|
.longClickListener { view ->
|
2019-05-10 10:14:40 +00:00
|
|
|
return@longClickListener callback?.onEventLongClicked(informationData, messageContent, view)
|
2019-09-02 12:24:36 +00:00
|
|
|
?: false
|
2019-05-07 12:02:15 +00:00
|
|
|
}
|
2019-02-19 18:12:58 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 12:27:57 +00:00
|
|
|
private fun annotateWithEdited(linkifiedBody: CharSequence,
|
|
|
|
callback: TimelineEventController.Callback?,
|
2019-08-07 10:57:11 +00:00
|
|
|
informationData: MessageInformationData): SpannableStringBuilder {
|
2019-05-21 12:26:46 +00:00
|
|
|
val spannable = SpannableStringBuilder()
|
|
|
|
spannable.append(linkifiedBody)
|
2019-07-10 13:29:52 +00:00
|
|
|
val editedSuffix = stringProvider.getString(R.string.edited_suffix)
|
2019-05-21 12:26:46 +00:00
|
|
|
spannable.append(" ").append(editedSuffix)
|
|
|
|
val color = colorProvider.getColorFromAttribute(R.attr.vctr_list_header_secondary_text_color)
|
2019-07-19 07:57:57 +00:00
|
|
|
val editStart = spannable.lastIndexOf(editedSuffix)
|
2019-05-21 12:26:46 +00: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 10:57:11 +00:00
|
|
|
callback?.onEditedDecorationClicked(informationData)
|
2019-05-21 12:26:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun updateDrawState(ds: TextPaint?) {
|
|
|
|
//nop
|
|
|
|
}
|
|
|
|
},
|
2019-09-02 12:24:36 +00:00
|
|
|
editStart,
|
|
|
|
editEnd,
|
|
|
|
Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
|
2019-05-21 12:26:46 +00:00
|
|
|
return spannable
|
|
|
|
}
|
|
|
|
|
2019-06-04 15:36:49 +00:00
|
|
|
private fun buildNoticeMessageItem(messageContent: MessageNoticeContent,
|
|
|
|
informationData: MessageInformationData,
|
2019-06-20 14:27:43 +00:00
|
|
|
highlight: Boolean,
|
2019-02-20 10:39:25 +00:00
|
|
|
callback: TimelineEventController.Callback?): MessageTextItem? {
|
|
|
|
|
|
|
|
val message = messageContent.body.let {
|
|
|
|
val formattedBody = span {
|
|
|
|
text = it
|
2019-06-06 12:37:30 +00:00
|
|
|
textColor = colorProvider.getColorFromAttribute(R.attr.riotx_text_secondary)
|
2019-02-20 10:39:25 +00:00
|
|
|
textStyle = "italic"
|
|
|
|
}
|
|
|
|
linkifyBody(formattedBody, callback)
|
|
|
|
}
|
|
|
|
return MessageTextItem_()
|
2019-06-26 13:22:44 +00:00
|
|
|
.avatarRenderer(avatarRenderer)
|
2019-02-20 10:39:25 +00:00
|
|
|
.message(message)
|
2019-07-12 08:16:43 +00:00
|
|
|
.colorProvider(colorProvider)
|
2019-02-20 10:39:25 +00:00
|
|
|
.informationData(informationData)
|
2019-06-20 14:27:43 +00:00
|
|
|
.highlighted(highlight)
|
2019-06-05 21:45:46 +00:00
|
|
|
.avatarCallback(callback)
|
2019-05-16 16:33:32 +00:00
|
|
|
.reactionPillCallback(callback)
|
2019-06-20 14:27:43 +00:00
|
|
|
.urlClickCallback(callback)
|
2019-08-08 17:59:20 +00:00
|
|
|
.readReceiptsCallback(callback)
|
2019-06-04 15:16:02 +00:00
|
|
|
.emojiTypeFace(emojiCompatFontProvider.typeface)
|
2019-05-14 09:07:53 +00:00
|
|
|
.memberClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onMemberNameClicked(informationData)
|
|
|
|
}))
|
2019-05-08 13:49:32 +00:00
|
|
|
.cellClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
2019-05-10 10:14:40 +00:00
|
|
|
callback?.onEventCellClicked(informationData, messageContent, view)
|
2019-05-08 13:49:32 +00:00
|
|
|
}))
|
2019-05-07 12:02:15 +00:00
|
|
|
.longClickListener { view ->
|
2019-05-10 10:14:40 +00:00
|
|
|
return@longClickListener callback?.onEventLongClicked(informationData, messageContent, view)
|
2019-09-02 12:24:36 +00:00
|
|
|
?: false
|
2019-05-07 12:02:15 +00:00
|
|
|
}
|
2019-02-20 10:39:25 +00:00
|
|
|
}
|
|
|
|
|
2019-06-04 15:36:49 +00:00
|
|
|
private fun buildEmoteMessageItem(messageContent: MessageEmoteContent,
|
|
|
|
informationData: MessageInformationData,
|
2019-06-20 14:27:43 +00:00
|
|
|
highlight: Boolean,
|
2019-02-19 18:12:58 +00:00
|
|
|
callback: TimelineEventController.Callback?): MessageTextItem? {
|
|
|
|
|
2019-01-22 17:43:15 +00:00
|
|
|
val message = messageContent.body.let {
|
2019-02-19 18:12:58 +00:00
|
|
|
val formattedBody = "* ${informationData.memberName} $it"
|
|
|
|
linkifyBody(formattedBody, callback)
|
2019-01-07 10:39:26 +00:00
|
|
|
}
|
2019-02-19 10:57:17 +00:00
|
|
|
return MessageTextItem_()
|
2019-05-21 12:26:46 +00:00
|
|
|
.apply {
|
2019-06-18 10:25:50 +00:00
|
|
|
if (informationData.hasBeenEdited) {
|
2019-08-07 10:57:11 +00:00
|
|
|
val spannable = annotateWithEdited(message, callback, informationData)
|
2019-05-21 12:26:46 +00:00
|
|
|
message(spannable)
|
|
|
|
} else {
|
|
|
|
message(message)
|
|
|
|
}
|
|
|
|
}
|
2019-06-26 13:22:44 +00:00
|
|
|
.avatarRenderer(avatarRenderer)
|
2019-07-12 08:16:43 +00:00
|
|
|
.colorProvider(colorProvider)
|
2019-02-19 10:57:17 +00:00
|
|
|
.informationData(informationData)
|
2019-06-20 14:27:43 +00:00
|
|
|
.highlighted(highlight)
|
2019-06-05 21:45:46 +00:00
|
|
|
.avatarCallback(callback)
|
2019-05-16 16:33:32 +00:00
|
|
|
.reactionPillCallback(callback)
|
2019-08-08 17:59:20 +00:00
|
|
|
.readReceiptsCallback(callback)
|
2019-06-20 14:27:43 +00:00
|
|
|
.urlClickCallback(callback)
|
2019-06-04 15:16:02 +00:00
|
|
|
.emojiTypeFace(emojiCompatFontProvider.typeface)
|
2019-05-08 13:49:32 +00:00
|
|
|
.cellClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
2019-05-10 10:14:40 +00:00
|
|
|
callback?.onEventCellClicked(informationData, messageContent, view)
|
2019-05-08 13:49:32 +00:00
|
|
|
}))
|
2019-05-07 12:02:15 +00:00
|
|
|
.longClickListener { view ->
|
2019-05-10 10:14:40 +00:00
|
|
|
return@longClickListener callback?.onEventLongClicked(informationData, messageContent, view)
|
2019-09-02 12:24:36 +00:00
|
|
|
?: false
|
2019-05-07 12:02:15 +00:00
|
|
|
}
|
2018-11-02 16:37:37 +00:00
|
|
|
}
|
|
|
|
|
2019-06-04 15:36:49 +00:00
|
|
|
private fun buildRedactedItem(informationData: MessageInformationData,
|
2019-06-20 14:27:43 +00:00
|
|
|
highlight: Boolean,
|
2019-06-04 15:36:49 +00:00
|
|
|
callback: TimelineEventController.Callback?): RedactedMessageItem? {
|
2019-05-17 15:15:44 +00:00
|
|
|
return RedactedMessageItem_()
|
2019-06-26 13:22:44 +00:00
|
|
|
.avatarRenderer(avatarRenderer)
|
2019-07-12 08:16:43 +00:00
|
|
|
.colorProvider(colorProvider)
|
2019-05-17 15:15:44 +00:00
|
|
|
.informationData(informationData)
|
2019-06-20 14:27:43 +00:00
|
|
|
.highlighted(highlight)
|
2019-06-05 21:45:46 +00:00
|
|
|
.avatarCallback(callback)
|
2019-08-08 17:59:20 +00:00
|
|
|
.readReceiptsCallback(callback)
|
2019-07-12 11:51:05 +00:00
|
|
|
.cellClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onEventCellClicked(informationData, null, view)
|
|
|
|
}))
|
|
|
|
.longClickListener { view ->
|
|
|
|
return@longClickListener callback?.onEventLongClicked(informationData, null, view)
|
2019-09-02 12:24:36 +00:00
|
|
|
?: false
|
2019-07-12 11:51:05 +00:00
|
|
|
}
|
2019-05-17 15:15:44 +00:00
|
|
|
}
|
|
|
|
|
2019-05-08 08:33:14 +00:00
|
|
|
private fun linkifyBody(body: CharSequence, callback: TimelineEventController.Callback?): CharSequence {
|
2019-02-19 18:12:58 +00:00
|
|
|
val spannable = SpannableStringBuilder(body)
|
|
|
|
MatrixLinkify.addLinks(spannable, object : MatrixPermalinkSpan.Callback {
|
|
|
|
override fun onUrlClicked(url: String) {
|
|
|
|
callback?.onUrlClicked(url)
|
|
|
|
}
|
|
|
|
})
|
2019-04-09 15:33:47 +00:00
|
|
|
VectorLinkify.addLinks(spannable, true)
|
2019-02-19 18:12:58 +00:00
|
|
|
return spannable
|
|
|
|
}
|
2018-11-02 16:37:37 +00:00
|
|
|
}
|