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-03-05 18:31:03 +01:00
|
|
|
package im.vector.riotredesign.features.home.room.detail.timeline.factory
|
2018-11-02 17:37:37 +01:00
|
|
|
|
2019-05-20 18:52:48 +02:00
|
|
|
import android.graphics.Color
|
2019-01-07 11:39:26 +01:00
|
|
|
import android.text.SpannableStringBuilder
|
2019-05-20 18:52:48 +02:00
|
|
|
import android.text.Spanned
|
|
|
|
import android.text.style.ForegroundColorSpan
|
2019-05-08 15:49:32 +02:00
|
|
|
import android.view.View
|
2019-04-11 15:40:07 +02:00
|
|
|
import androidx.annotation.ColorRes
|
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-01-16 10:41:32 +01:00
|
|
|
import im.vector.matrix.android.api.session.events.model.EventType
|
2019-05-20 18:52:48 +02:00
|
|
|
import im.vector.matrix.android.api.session.events.model.RelationType
|
2018-12-18 12:13:46 +01:00
|
|
|
import im.vector.matrix.android.api.session.events.model.toModel
|
2019-05-07 14:02:15 +02:00
|
|
|
import im.vector.matrix.android.api.session.room.model.message.*
|
|
|
|
import im.vector.matrix.android.api.session.room.send.SendState
|
2019-01-25 18:40:02 +01:00
|
|
|
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
2019-02-20 11:39:25 +01:00
|
|
|
import im.vector.riotredesign.R
|
2019-04-05 10:40:59 +02:00
|
|
|
import im.vector.riotredesign.core.epoxy.VectorEpoxyModel
|
2019-01-16 10:41:32 +01:00
|
|
|
import im.vector.riotredesign.core.extensions.localDateTime
|
2019-04-09 17:33:47 +02:00
|
|
|
import im.vector.riotredesign.core.linkify.VectorLinkify
|
2019-02-20 11:39:25 +01:00
|
|
|
import im.vector.riotredesign.core.resources.ColorProvider
|
2019-05-08 15:49:32 +02:00
|
|
|
import im.vector.riotredesign.core.utils.DebouncedClickListener
|
2019-05-10 18:12:35 +02:00
|
|
|
import im.vector.riotredesign.features.home.AvatarRenderer
|
2019-03-05 18:31:03 +01:00
|
|
|
import im.vector.riotredesign.features.home.room.detail.timeline.TimelineEventController
|
2019-03-12 08:29:49 +01:00
|
|
|
import im.vector.riotredesign.features.home.room.detail.timeline.helper.TimelineDateFormatter
|
2019-01-24 18:04:55 +01:00
|
|
|
import im.vector.riotredesign.features.home.room.detail.timeline.helper.TimelineMediaSizeProvider
|
2019-05-07 14:02:15 +02:00
|
|
|
import im.vector.riotredesign.features.home.room.detail.timeline.item.*
|
2019-02-26 19:35:47 +01:00
|
|
|
import im.vector.riotredesign.features.html.EventHtmlRenderer
|
2019-04-11 19:19:52 +02:00
|
|
|
import im.vector.riotredesign.features.media.ImageContentRenderer
|
2019-04-12 13:46:59 +02:00
|
|
|
import im.vector.riotredesign.features.media.VideoContentRenderer
|
2019-02-20 11:39:25 +01:00
|
|
|
import me.gujun.android.span.span
|
2018-11-02 17:37:37 +01:00
|
|
|
|
2019-02-20 11:39:25 +01:00
|
|
|
class MessageItemFactory(private val colorProvider: ColorProvider,
|
|
|
|
private val timelineMediaSizeProvider: TimelineMediaSizeProvider,
|
2019-02-21 19:21:08 +01:00
|
|
|
private val timelineDateFormatter: TimelineDateFormatter,
|
2019-02-25 15:18:36 +01:00
|
|
|
private val htmlRenderer: EventHtmlRenderer) {
|
2018-11-02 17:37:37 +01:00
|
|
|
|
2019-01-14 16:18:39 +01:00
|
|
|
fun create(event: TimelineEvent,
|
|
|
|
nextEvent: TimelineEvent?,
|
2018-12-19 11:50:44 +01:00
|
|
|
callback: TimelineEventController.Callback?
|
2019-04-05 10:40:59 +02:00
|
|
|
): VectorEpoxyModel<*>? {
|
2018-12-19 11:50:44 +01:00
|
|
|
|
2019-04-05 18:21:45 +02:00
|
|
|
val eventId = event.root.eventId ?: return null
|
2019-01-16 10:41:32 +01:00
|
|
|
|
|
|
|
val date = event.root.localDateTime()
|
|
|
|
val nextDate = nextEvent?.root?.localDateTime()
|
|
|
|
val addDaySeparator = date.toLocalDate() != nextDate?.toLocalDate()
|
|
|
|
val isNextMessageReceivedMoreThanOneHourAgo = nextDate?.isBefore(date.minusMinutes(60))
|
2019-05-07 14:02:15 +02:00
|
|
|
?: false
|
2019-01-16 10:41:32 +01:00
|
|
|
|
2019-03-21 20:21:45 +01:00
|
|
|
val showInformation = addDaySeparator
|
2019-05-07 14:02:15 +02:00
|
|
|
|| event.senderAvatar != nextEvent?.senderAvatar
|
|
|
|
|| event.senderName != nextEvent?.senderName
|
|
|
|
|| nextEvent?.root?.type != EventType.MESSAGE
|
|
|
|
|| isNextMessageReceivedMoreThanOneHourAgo
|
2019-01-07 11:39:26 +01:00
|
|
|
|
2019-01-21 18:16:15 +01:00
|
|
|
val time = timelineDateFormatter.formatMessageHour(date)
|
2019-04-30 19:55:55 +02:00
|
|
|
val avatarUrl = event.senderAvatar
|
|
|
|
val memberName = event.senderName ?: event.root.sender ?: ""
|
2019-04-11 15:40:07 +02:00
|
|
|
val formattedMemberName = span(memberName) {
|
2019-05-16 09:21:10 +02:00
|
|
|
textColor = colorProvider.getColor(AvatarRenderer.getColorFromUserId(event.root.sender
|
|
|
|
?: ""))
|
2019-04-11 15:40:07 +02:00
|
|
|
}
|
2019-05-20 18:52:48 +02:00
|
|
|
val hasBeenEdited = event.annotations?.editSummary != null
|
2019-04-11 19:19:52 +02:00
|
|
|
val informationData = MessageInformationData(eventId = eventId,
|
2019-05-07 14:02:15 +02:00
|
|
|
senderId = event.root.sender ?: "",
|
|
|
|
sendState = event.sendState,
|
|
|
|
time = time,
|
|
|
|
avatarUrl = avatarUrl,
|
|
|
|
memberName = formattedMemberName,
|
2019-05-16 09:21:10 +02:00
|
|
|
showInformation = showInformation,
|
2019-05-20 18:52:48 +02:00
|
|
|
orderedReactionList = event.annotations?.reactionsSummary?.map { Triple(it.key, it.count, it.addedByMe) },
|
|
|
|
hasBeenEdited = hasBeenEdited
|
2019-05-16 09:21:10 +02:00
|
|
|
)
|
2019-01-21 18:16:15 +01:00
|
|
|
|
2019-05-17 17:15:44 +02:00
|
|
|
if (event.root.unsignedData?.redactedEvent != null) {
|
|
|
|
//message is redacted
|
2019-05-19 12:07:40 +02:00
|
|
|
return buildRedactedItem(informationData, callback)
|
2019-05-17 17:15:44 +02:00
|
|
|
}
|
|
|
|
|
2019-05-20 18:52:48 +02:00
|
|
|
val messageContent: MessageContent =
|
|
|
|
event.annotations?.editSummary?.aggregatedContent?.toModel()
|
|
|
|
?: event.root.content.toModel()
|
|
|
|
?: return null
|
2019-05-14 11:07:53 +02:00
|
|
|
|
2019-05-20 18:52:48 +02:00
|
|
|
if (messageContent.relatesTo?.type == RelationType.REPLACE) {
|
|
|
|
//TODO blank item or ignore??
|
|
|
|
// ignore this event
|
|
|
|
return BlankItem_()
|
|
|
|
}
|
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-05-10 12:14:40 +02:00
|
|
|
is MessageEmoteContent -> buildEmoteMessageItem(messageContent, informationData, callback)
|
2019-05-20 18:52:48 +02:00
|
|
|
is MessageTextContent -> buildTextMessageItem(event.sendState, messageContent, informationData, hasBeenEdited, callback)
|
2019-05-10 12:14:40 +02:00
|
|
|
is MessageImageContent -> buildImageMessageItem(messageContent, informationData, callback)
|
|
|
|
is MessageNoticeContent -> buildNoticeMessageItem(messageContent, informationData, callback)
|
|
|
|
is MessageVideoContent -> buildVideoMessageItem(messageContent, informationData, callback)
|
|
|
|
is MessageFileContent -> buildFileMessageItem(messageContent, informationData, callback)
|
|
|
|
is MessageAudioContent -> buildAudioMessageItem(messageContent, informationData, callback)
|
2019-05-07 14:02:15 +02:00
|
|
|
else -> buildNotHandledMessageItem(messageContent)
|
2019-01-21 18:16:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 12:14:40 +02:00
|
|
|
private fun buildAudioMessageItem(messageContent: MessageAudioContent, informationData: MessageInformationData,
|
2019-04-12 12:38:02 +02:00
|
|
|
callback: TimelineEventController.Callback?): MessageFileItem? {
|
|
|
|
return MessageFileItem_()
|
|
|
|
.informationData(informationData)
|
|
|
|
.filename(messageContent.body)
|
|
|
|
.iconRes(R.drawable.filetype_audio)
|
2019-05-16 18:33:32 +02:00
|
|
|
.reactionPillCallback(callback)
|
2019-05-08 15:49:32 +02:00
|
|
|
.avatarClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onAvatarClicked(informationData)
|
|
|
|
}))
|
2019-05-14 11:07:53 +02:00
|
|
|
.memberClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onMemberNameClicked(informationData)
|
|
|
|
}))
|
2019-05-08 15:49:32 +02:00
|
|
|
.cellClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
2019-05-10 12:14:40 +02:00
|
|
|
callback?.onEventCellClicked(informationData, messageContent, view)
|
2019-05-08 15:49:32 +02:00
|
|
|
}))
|
|
|
|
.clickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { _ ->
|
|
|
|
callback?.onAudioMessageClicked(messageContent)
|
|
|
|
}))
|
2019-05-08 10:33:14 +02:00
|
|
|
.longClickListener { view ->
|
2019-05-10 12:14:40 +02:00
|
|
|
return@longClickListener callback?.onEventLongClicked(informationData, messageContent, view)
|
2019-05-08 10:33:14 +02:00
|
|
|
?: false
|
|
|
|
}
|
2019-04-12 12:38:02 +02:00
|
|
|
}
|
|
|
|
|
2019-05-10 12:14:40 +02:00
|
|
|
private fun buildFileMessageItem(messageContent: MessageFileContent, informationData: MessageInformationData,
|
2019-04-12 12:38:02 +02:00
|
|
|
callback: TimelineEventController.Callback?): MessageFileItem? {
|
|
|
|
return MessageFileItem_()
|
|
|
|
.informationData(informationData)
|
|
|
|
.filename(messageContent.body)
|
2019-05-16 18:33:32 +02:00
|
|
|
.reactionPillCallback(callback)
|
2019-04-12 12:38:02 +02:00
|
|
|
.iconRes(R.drawable.filetype_attachment)
|
2019-05-08 15:49:32 +02:00
|
|
|
.avatarClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onAvatarClicked(informationData)
|
|
|
|
}))
|
2019-05-14 11:07:53 +02:00
|
|
|
.memberClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onMemberNameClicked(informationData)
|
|
|
|
}))
|
2019-05-08 15:49:32 +02:00
|
|
|
.cellClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
2019-05-10 12:14:40 +02:00
|
|
|
callback?.onEventCellClicked(informationData, messageContent, view)
|
2019-05-08 15:49:32 +02:00
|
|
|
}))
|
2019-05-10 12:14:40 +02:00
|
|
|
.longClickListener { view ->
|
|
|
|
return@longClickListener callback?.onEventLongClicked(informationData, messageContent, view)
|
|
|
|
?: false
|
|
|
|
}
|
2019-05-08 15:49:32 +02:00
|
|
|
.clickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { _ ->
|
|
|
|
callback?.onFileMessageClicked(messageContent)
|
|
|
|
}))
|
2019-04-12 12:38:02 +02:00
|
|
|
}
|
|
|
|
|
2019-02-19 15:47:50 +01:00
|
|
|
private fun buildNotHandledMessageItem(messageContent: MessageContent): DefaultItem? {
|
2019-02-11 13:47:47 +01:00
|
|
|
val text = "${messageContent.type} message events are not yet handled"
|
2019-02-19 15:47:50 +01:00
|
|
|
return DefaultItem_().text(text)
|
2019-02-11 13:47:47 +01:00
|
|
|
}
|
|
|
|
|
2019-05-10 12:14:40 +02:00
|
|
|
private fun buildImageMessageItem(messageContent: MessageImageContent, informationData: MessageInformationData,
|
2019-04-11 19:19:52 +02:00
|
|
|
callback: TimelineEventController.Callback?): 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-01-23 20:29:47 +01:00
|
|
|
url = messageContent.url,
|
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_()
|
|
|
|
.playable(messageContent.info?.mimeType == "image/gif")
|
2019-02-19 11:57:17 +01:00
|
|
|
.informationData(informationData)
|
|
|
|
.mediaData(data)
|
2019-05-16 18:33:32 +02:00
|
|
|
.reactionPillCallback(callback)
|
2019-05-08 15:49:32 +02:00
|
|
|
.avatarClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onAvatarClicked(informationData)
|
|
|
|
}))
|
2019-05-14 11:07:53 +02:00
|
|
|
.memberClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onMemberNameClicked(informationData)
|
|
|
|
}))
|
2019-05-08 15:49:32 +02:00
|
|
|
.clickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onImageMessageClicked(messageContent, data, view)
|
|
|
|
}))
|
|
|
|
.cellClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
2019-05-10 12:14:40 +02:00
|
|
|
callback?.onEventCellClicked(informationData, messageContent, view)
|
2019-05-08 15:49:32 +02:00
|
|
|
}))
|
|
|
|
|
2019-05-08 10:33:14 +02:00
|
|
|
.longClickListener { view ->
|
2019-05-10 12:14:40 +02:00
|
|
|
return@longClickListener callback?.onEventLongClicked(informationData, messageContent, view)
|
2019-05-08 10:33:14 +02:00
|
|
|
?: false
|
|
|
|
}
|
2019-01-22 18:43:15 +01:00
|
|
|
}
|
|
|
|
|
2019-05-10 12:14:40 +02:00
|
|
|
private fun buildVideoMessageItem(messageContent: MessageVideoContent, informationData: MessageInformationData,
|
2019-04-11 19:19:52 +02:00
|
|
|
callback: TimelineEventController.Callback?): MessageImageVideoItem? {
|
|
|
|
|
|
|
|
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,
|
|
|
|
url = messageContent.info?.thumbnailUrl,
|
|
|
|
height = messageContent.info?.height,
|
|
|
|
maxHeight = maxHeight,
|
|
|
|
width = messageContent.info?.width,
|
|
|
|
maxWidth = maxWidth
|
|
|
|
)
|
2019-04-12 13:46:59 +02:00
|
|
|
|
|
|
|
val videoData = VideoContentRenderer.Data(
|
|
|
|
filename = messageContent.body,
|
|
|
|
videoUrl = messageContent.url,
|
|
|
|
thumbnailMediaData = thumbnailData
|
|
|
|
)
|
|
|
|
|
2019-04-11 19:19:52 +02:00
|
|
|
return MessageImageVideoItem_()
|
|
|
|
.playable(true)
|
|
|
|
.informationData(informationData)
|
2019-04-12 13:46:59 +02:00
|
|
|
.mediaData(thumbnailData)
|
2019-05-16 18:33:32 +02:00
|
|
|
.reactionPillCallback(callback)
|
2019-05-08 15:49:32 +02:00
|
|
|
.avatarClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onAvatarClicked(informationData)
|
|
|
|
}))
|
2019-05-14 11:07:53 +02:00
|
|
|
.memberClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onMemberNameClicked(informationData)
|
|
|
|
}))
|
2019-05-08 15:49:32 +02:00
|
|
|
.cellClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
2019-05-10 12:14:40 +02:00
|
|
|
callback?.onEventCellClicked(informationData, messageContent, view)
|
2019-05-08 15:49:32 +02:00
|
|
|
}))
|
2019-04-12 13:46:59 +02:00
|
|
|
.clickListener { view -> callback?.onVideoMessageClicked(messageContent, videoData, view) }
|
2019-05-08 10:33:14 +02:00
|
|
|
.longClickListener { view ->
|
2019-05-10 12:14:40 +02:00
|
|
|
return@longClickListener callback?.onEventLongClicked(informationData, messageContent, view)
|
2019-05-08 10:33:14 +02:00
|
|
|
?: false
|
|
|
|
}
|
2019-04-11 19:19:52 +02:00
|
|
|
}
|
|
|
|
|
2019-05-10 12:14:40 +02:00
|
|
|
private fun buildTextMessageItem(sendState: SendState, messageContent: MessageTextContent,
|
2019-01-22 18:43:15 +01:00
|
|
|
informationData: MessageInformationData,
|
2019-05-20 18:52:48 +02:00
|
|
|
hasBeenEdited: Boolean,
|
2019-01-21 18:16:15 +01:00
|
|
|
callback: TimelineEventController.Callback?): MessageTextItem? {
|
|
|
|
|
2019-04-09 19:57:43 +02:00
|
|
|
val bodyToUse = messageContent.formattedBody?.let {
|
|
|
|
htmlRenderer.render(it)
|
|
|
|
} ?: 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 {
|
|
|
|
if (hasBeenEdited) {
|
|
|
|
val spannable = SpannableStringBuilder()
|
|
|
|
spannable.append(linkifiedBody)
|
|
|
|
val editedSuffix = "(edited)"
|
|
|
|
spannable.append(" ").append(editedSuffix)
|
|
|
|
spannable.setSpan(ForegroundColorSpan(Color.LTGRAY), spannable.indexOf(editedSuffix), spannable.indexOf(editedSuffix) + editedSuffix.length, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
|
|
|
|
message(spannable)
|
|
|
|
} else {
|
|
|
|
message(linkifiedBody)
|
|
|
|
}
|
|
|
|
}
|
2019-02-19 19:12:58 +01:00
|
|
|
.informationData(informationData)
|
2019-05-16 18:33:32 +02:00
|
|
|
.reactionPillCallback(callback)
|
2019-05-08 15:49:32 +02:00
|
|
|
.avatarClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onAvatarClicked(informationData)
|
|
|
|
}))
|
2019-05-14 11:07:53 +02:00
|
|
|
.memberClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onMemberNameClicked(informationData)
|
|
|
|
}))
|
2019-05-08 15:49:32 +02:00
|
|
|
//click on the text
|
|
|
|
.clickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
2019-05-10 12:14:40 +02:00
|
|
|
callback?.onEventCellClicked(informationData, messageContent, view)
|
2019-05-08 15:49:32 +02:00
|
|
|
}))
|
|
|
|
.cellClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
2019-05-10 12:14:40 +02:00
|
|
|
callback?.onEventCellClicked(informationData, messageContent, view)
|
2019-05-08 15:49:32 +02:00
|
|
|
}))
|
2019-05-07 14:02:15 +02:00
|
|
|
.longClickListener { view ->
|
2019-05-10 12:14:40 +02:00
|
|
|
return@longClickListener callback?.onEventLongClicked(informationData, messageContent, view)
|
2019-05-07 14:02:15 +02:00
|
|
|
?: false
|
|
|
|
}
|
2019-02-19 19:12:58 +01:00
|
|
|
}
|
|
|
|
|
2019-05-10 12:14:40 +02:00
|
|
|
private fun buildNoticeMessageItem(messageContent: MessageNoticeContent, informationData: MessageInformationData,
|
2019-02-20 11:39:25 +01:00
|
|
|
callback: TimelineEventController.Callback?): MessageTextItem? {
|
|
|
|
|
|
|
|
val message = messageContent.body.let {
|
|
|
|
val formattedBody = span {
|
|
|
|
text = it
|
|
|
|
textColor = colorProvider.getColor(R.color.slate_grey)
|
|
|
|
textStyle = "italic"
|
|
|
|
}
|
|
|
|
linkifyBody(formattedBody, callback)
|
|
|
|
}
|
|
|
|
return MessageTextItem_()
|
|
|
|
.message(message)
|
|
|
|
.informationData(informationData)
|
2019-05-16 18:33:32 +02:00
|
|
|
.reactionPillCallback(callback)
|
2019-05-08 15:49:32 +02:00
|
|
|
.avatarClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onAvatarClicked(informationData)
|
|
|
|
}))
|
2019-05-14 11:07:53 +02:00
|
|
|
.memberClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onMemberNameClicked(informationData)
|
|
|
|
}))
|
2019-05-08 15:49:32 +02:00
|
|
|
.cellClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
2019-05-10 12:14:40 +02:00
|
|
|
callback?.onEventCellClicked(informationData, messageContent, view)
|
2019-05-08 15:49:32 +02:00
|
|
|
}))
|
2019-05-07 14:02:15 +02:00
|
|
|
.longClickListener { view ->
|
2019-05-10 12:14:40 +02:00
|
|
|
return@longClickListener callback?.onEventLongClicked(informationData, messageContent, view)
|
2019-05-07 14:02:15 +02:00
|
|
|
?: false
|
|
|
|
}
|
2019-02-20 11:39:25 +01:00
|
|
|
}
|
|
|
|
|
2019-05-10 12:14:40 +02:00
|
|
|
private fun buildEmoteMessageItem(messageContent: MessageEmoteContent, informationData: MessageInformationData,
|
2019-02-19 19:12:58 +01:00
|
|
|
callback: TimelineEventController.Callback?): MessageTextItem? {
|
|
|
|
|
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_()
|
|
|
|
.message(message)
|
|
|
|
.informationData(informationData)
|
2019-05-16 18:33:32 +02:00
|
|
|
.reactionPillCallback(callback)
|
2019-05-08 15:49:32 +02:00
|
|
|
.avatarClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onAvatarClicked(informationData)
|
|
|
|
}))
|
2019-05-14 11:07:53 +02:00
|
|
|
.memberClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onMemberNameClicked(informationData)
|
|
|
|
}))
|
2019-05-08 15:49:32 +02:00
|
|
|
.cellClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
2019-05-10 12:14:40 +02:00
|
|
|
callback?.onEventCellClicked(informationData, messageContent, view)
|
2019-05-08 15:49:32 +02:00
|
|
|
}))
|
2019-05-07 14:02:15 +02:00
|
|
|
.longClickListener { view ->
|
2019-05-10 12:14:40 +02:00
|
|
|
return@longClickListener callback?.onEventLongClicked(informationData, messageContent, view)
|
2019-05-07 14:02:15 +02:00
|
|
|
?: false
|
|
|
|
}
|
2018-11-02 17:37:37 +01:00
|
|
|
}
|
|
|
|
|
2019-05-19 12:07:40 +02:00
|
|
|
private fun buildRedactedItem(informationData: MessageInformationData, callback: TimelineEventController.Callback?): RedactedMessageItem? {
|
2019-05-17 17:15:44 +02:00
|
|
|
return RedactedMessageItem_()
|
|
|
|
.informationData(informationData)
|
2019-05-19 12:07:40 +02:00
|
|
|
.avatarClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onAvatarClicked(informationData)
|
|
|
|
}))
|
|
|
|
.memberClickListener(
|
|
|
|
DebouncedClickListener(View.OnClickListener { view ->
|
|
|
|
callback?.onMemberNameClicked(informationData)
|
|
|
|
}))
|
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
|
|
|
|
2019-04-11 19:19:52 +02:00
|
|
|
//Based on riot-web implementation
|
2019-04-11 15:40:07 +02:00
|
|
|
@ColorRes
|
2019-04-11 19:19:52 +02:00
|
|
|
private fun getColorFor(sender: String): Int {
|
2019-04-11 15:40:07 +02:00
|
|
|
var hash = 0
|
|
|
|
var i = 0
|
|
|
|
var chr: Char
|
|
|
|
if (sender.isEmpty()) {
|
|
|
|
return R.color.username_1
|
|
|
|
}
|
|
|
|
while (i < sender.length) {
|
|
|
|
chr = sender[i]
|
|
|
|
hash = (hash shl 5) - hash + chr.toInt()
|
|
|
|
hash = hash or 0
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
val cI = Math.abs(hash) % 8 + 1
|
|
|
|
return when (cI) {
|
2019-05-07 14:02:15 +02:00
|
|
|
1 -> R.color.username_1
|
|
|
|
2 -> R.color.username_2
|
|
|
|
3 -> R.color.username_3
|
|
|
|
4 -> R.color.username_4
|
|
|
|
5 -> R.color.username_5
|
|
|
|
6 -> R.color.username_6
|
|
|
|
7 -> R.color.username_7
|
2019-04-11 15:40:07 +02:00
|
|
|
else -> R.color.username_8
|
|
|
|
}
|
|
|
|
}
|
2018-11-02 17:37:37 +01:00
|
|
|
}
|