mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Fix / Annotate emote also
This commit is contained in:
parent
6f103101b6
commit
d49007538b
@ -110,8 +110,15 @@ class MessageItemFactory(private val colorProvider: ColorProvider,
|
|||||||
// val all = event.root.toContent()
|
// val all = event.root.toContent()
|
||||||
// val ev = all.toModel<Event>()
|
// val ev = all.toModel<Event>()
|
||||||
return when (messageContent) {
|
return when (messageContent) {
|
||||||
is MessageEmoteContent -> buildEmoteMessageItem(messageContent, informationData, callback)
|
is MessageEmoteContent -> buildEmoteMessageItem(messageContent,
|
||||||
is MessageTextContent -> buildTextMessageItem(event.sendState, messageContent, informationData, hasBeenEdited,
|
informationData,
|
||||||
|
hasBeenEdited,
|
||||||
|
event.annotations?.editSummary,
|
||||||
|
callback)
|
||||||
|
is MessageTextContent -> buildTextMessageItem(event.sendState,
|
||||||
|
messageContent,
|
||||||
|
informationData,
|
||||||
|
hasBeenEdited,
|
||||||
event.annotations?.editSummary,
|
event.annotations?.editSummary,
|
||||||
callback
|
callback
|
||||||
)
|
)
|
||||||
@ -287,32 +294,7 @@ class MessageItemFactory(private val colorProvider: ColorProvider,
|
|||||||
return MessageTextItem_()
|
return MessageTextItem_()
|
||||||
.apply {
|
.apply {
|
||||||
if (hasBeenEdited) {
|
if (hasBeenEdited) {
|
||||||
val spannable = SpannableStringBuilder()
|
val spannable = annotateWithEdited(linkifiedBody, callback, informationData, editSummary)
|
||||||
spannable.append(linkifiedBody)
|
|
||||||
val editedSuffix = "(edited)"
|
|
||||||
spannable.append(" ").append(editedSuffix)
|
|
||||||
val color = colorProvider.getColorFromAttribute(R.attr.vctr_list_header_secondary_text_color)
|
|
||||||
val editStart = spannable.indexOf(editedSuffix)
|
|
||||||
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?) {
|
|
||||||
callback?.onEditedDecorationClicked(informationData, editSummary)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun updateDrawState(ds: TextPaint?) {
|
|
||||||
//nop
|
|
||||||
}
|
|
||||||
},
|
|
||||||
editStart,
|
|
||||||
editEnd,
|
|
||||||
Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
|
|
||||||
message(spannable)
|
message(spannable)
|
||||||
} else {
|
} else {
|
||||||
message(linkifiedBody)
|
message(linkifiedBody)
|
||||||
@ -343,6 +325,36 @@ class MessageItemFactory(private val colorProvider: ColorProvider,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun annotateWithEdited(linkifiedBody: CharSequence, callback: TimelineEventController.Callback?, informationData: MessageInformationData, editSummary: EditAggregatedSummary?): SpannableStringBuilder {
|
||||||
|
val spannable = SpannableStringBuilder()
|
||||||
|
spannable.append(linkifiedBody)
|
||||||
|
val editedSuffix = "(edited)"
|
||||||
|
spannable.append(" ").append(editedSuffix)
|
||||||
|
val color = colorProvider.getColorFromAttribute(R.attr.vctr_list_header_secondary_text_color)
|
||||||
|
val editStart = spannable.indexOf(editedSuffix)
|
||||||
|
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?) {
|
||||||
|
callback?.onEditedDecorationClicked(informationData, editSummary)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updateDrawState(ds: TextPaint?) {
|
||||||
|
//nop
|
||||||
|
}
|
||||||
|
},
|
||||||
|
editStart,
|
||||||
|
editEnd,
|
||||||
|
Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
|
||||||
|
return spannable
|
||||||
|
}
|
||||||
|
|
||||||
private fun buildNoticeMessageItem(messageContent: MessageNoticeContent, informationData: MessageInformationData,
|
private fun buildNoticeMessageItem(messageContent: MessageNoticeContent, informationData: MessageInformationData,
|
||||||
callback: TimelineEventController.Callback?): MessageTextItem? {
|
callback: TimelineEventController.Callback?): MessageTextItem? {
|
||||||
|
|
||||||
@ -377,6 +389,8 @@ class MessageItemFactory(private val colorProvider: ColorProvider,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun buildEmoteMessageItem(messageContent: MessageEmoteContent, informationData: MessageInformationData,
|
private fun buildEmoteMessageItem(messageContent: MessageEmoteContent, informationData: MessageInformationData,
|
||||||
|
hasBeenEdited: Boolean,
|
||||||
|
editSummary: EditAggregatedSummary?,
|
||||||
callback: TimelineEventController.Callback?): MessageTextItem? {
|
callback: TimelineEventController.Callback?): MessageTextItem? {
|
||||||
|
|
||||||
val message = messageContent.body.let {
|
val message = messageContent.body.let {
|
||||||
@ -384,7 +398,14 @@ class MessageItemFactory(private val colorProvider: ColorProvider,
|
|||||||
linkifyBody(formattedBody, callback)
|
linkifyBody(formattedBody, callback)
|
||||||
}
|
}
|
||||||
return MessageTextItem_()
|
return MessageTextItem_()
|
||||||
.message(message)
|
.apply {
|
||||||
|
if (hasBeenEdited) {
|
||||||
|
val spannable = annotateWithEdited(message, callback, informationData, editSummary)
|
||||||
|
message(spannable)
|
||||||
|
} else {
|
||||||
|
message(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
.informationData(informationData)
|
.informationData(informationData)
|
||||||
.reactionPillCallback(callback)
|
.reactionPillCallback(callback)
|
||||||
.avatarClickListener(
|
.avatarClickListener(
|
||||||
|
Loading…
Reference in New Issue
Block a user