Fix regression after merge conflict: big font for messages with only big emoji

This commit is contained in:
Benoit Marty 2019-10-11 14:35:37 +02:00
parent 82fc97f619
commit 116d569fa8
3 changed files with 18 additions and 4 deletions

View file

@ -19,9 +19,9 @@ package im.vector.riotx.features.home.room.detail.timeline.factory
import android.text.SpannableStringBuilder import android.text.SpannableStringBuilder
import android.text.Spanned import android.text.Spanned
import android.text.TextPaint import android.text.TextPaint
import android.text.style.AbsoluteSizeSpan
import android.text.style.ClickableSpan import android.text.style.ClickableSpan
import android.text.style.ForegroundColorSpan import android.text.style.ForegroundColorSpan
import android.text.style.RelativeSizeSpan
import android.view.View import android.view.View
import dagger.Lazy import dagger.Lazy
import im.vector.matrix.android.api.permalinks.MatrixLinkify import im.vector.matrix.android.api.permalinks.MatrixLinkify
@ -39,6 +39,8 @@ import im.vector.riotx.core.linkify.VectorLinkify
import im.vector.riotx.core.resources.ColorProvider import im.vector.riotx.core.resources.ColorProvider
import im.vector.riotx.core.resources.StringProvider import im.vector.riotx.core.resources.StringProvider
import im.vector.riotx.core.utils.DebouncedClickListener import im.vector.riotx.core.utils.DebouncedClickListener
import im.vector.riotx.core.utils.DimensionConverter
import im.vector.riotx.core.utils.containsOnlyEmojis
import im.vector.riotx.core.utils.isLocalFile import im.vector.riotx.core.utils.isLocalFile
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
import im.vector.riotx.features.home.room.detail.timeline.helper.* import im.vector.riotx.features.home.room.detail.timeline.helper.*
@ -241,12 +243,13 @@ class MessageItemFactory @Inject constructor(
return MessageTextItem_() return MessageTextItem_()
.apply { .apply {
if (informationData.hasBeenEdited) { if (informationData.hasBeenEdited) {
val spannable = annotateWithEdited(linkifiedBody, callback, informationData) val spannable = annotateWithEdited(linkifiedBody, callback, attributes.dimensionConverter, informationData)
message(spannable) message(spannable)
} else { } else {
message(linkifiedBody) message(linkifiedBody)
} }
} }
.useBigFont(linkifiedBody.length <= MAX_NUMBER_OF_EMOJI_FOR_BIG_FONT * 2 && containsOnlyEmojis(linkifiedBody.toString()))
.searchForPills(isFormatted) .searchForPills(isFormatted)
.leftGuideline(avatarSizeProvider.leftGuideline) .leftGuideline(avatarSizeProvider.leftGuideline)
.attributes(attributes) .attributes(attributes)
@ -257,6 +260,7 @@ class MessageItemFactory @Inject constructor(
private fun annotateWithEdited(linkifiedBody: CharSequence, private fun annotateWithEdited(linkifiedBody: CharSequence,
callback: TimelineEventController.Callback?, callback: TimelineEventController.Callback?,
dimensionConverter: DimensionConverter,
informationData: MessageInformationData): SpannableStringBuilder { informationData: MessageInformationData): SpannableStringBuilder {
val spannable = SpannableStringBuilder() val spannable = SpannableStringBuilder()
spannable.append(linkifiedBody) spannable.append(linkifiedBody)
@ -271,7 +275,8 @@ class MessageItemFactory @Inject constructor(
editEnd, editEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE) Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
spannable.setSpan(RelativeSizeSpan(.9f), editStart, editEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE) // Note: text size is set to 14sp
spannable.setSpan(AbsoluteSizeSpan(dimensionConverter.spToPx(13)), editStart, editEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
spannable.setSpan(object : ClickableSpan() { spannable.setSpan(object : ClickableSpan() {
override fun onClick(widget: View?) { override fun onClick(widget: View?) {
callback?.onEditedDecorationClicked(informationData) callback?.onEditedDecorationClicked(informationData)
@ -321,7 +326,7 @@ class MessageItemFactory @Inject constructor(
return MessageTextItem_() return MessageTextItem_()
.apply { .apply {
if (informationData.hasBeenEdited) { if (informationData.hasBeenEdited) {
val spannable = annotateWithEdited(message, callback, informationData) val spannable = annotateWithEdited(message, callback, attributes.dimensionConverter, informationData)
message(spannable) message(spannable)
} else { } else {
message(message) message(message)
@ -351,4 +356,8 @@ class MessageItemFactory @Inject constructor(
VectorLinkify.addLinks(spannable, true) VectorLinkify.addLinks(spannable, true)
return spannable return spannable
} }
companion object {
private const val MAX_NUMBER_OF_EMOJI_FOR_BIG_FONT = 5
}
} }

View file

@ -22,6 +22,7 @@ import im.vector.matrix.android.api.session.room.model.message.MessageContent
import im.vector.riotx.EmojiCompatFontProvider import im.vector.riotx.EmojiCompatFontProvider
import im.vector.riotx.core.resources.ColorProvider import im.vector.riotx.core.resources.ColorProvider
import im.vector.riotx.core.utils.DebouncedClickListener import im.vector.riotx.core.utils.DebouncedClickListener
import im.vector.riotx.core.utils.DimensionConverter
import im.vector.riotx.features.home.AvatarRenderer 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.TimelineEventController
import im.vector.riotx.features.home.room.detail.timeline.item.AbsMessageItem import im.vector.riotx.features.home.room.detail.timeline.item.AbsMessageItem
@ -32,6 +33,7 @@ class MessageItemAttributesFactory @Inject constructor(
private val avatarRenderer: AvatarRenderer, private val avatarRenderer: AvatarRenderer,
private val colorProvider: ColorProvider, private val colorProvider: ColorProvider,
private val avatarSizeProvider: AvatarSizeProvider, private val avatarSizeProvider: AvatarSizeProvider,
private val dimensionConverter: DimensionConverter,
private val emojiCompatFontProvider: EmojiCompatFontProvider) { private val emojiCompatFontProvider: EmojiCompatFontProvider) {
fun create(messageContent: MessageContent?, fun create(messageContent: MessageContent?,
@ -42,6 +44,7 @@ class MessageItemAttributesFactory @Inject constructor(
informationData = informationData, informationData = informationData,
avatarRenderer = avatarRenderer, avatarRenderer = avatarRenderer,
colorProvider = colorProvider, colorProvider = colorProvider,
dimensionConverter = dimensionConverter,
itemLongClickListener = View.OnLongClickListener { view -> itemLongClickListener = View.OnLongClickListener { view ->
callback?.onEventLongClicked(informationData, messageContent, view) ?: false callback?.onEventLongClicked(informationData, messageContent, view) ?: false
}, },

View file

@ -29,6 +29,7 @@ import im.vector.riotx.R
import im.vector.riotx.core.resources.ColorProvider import im.vector.riotx.core.resources.ColorProvider
import im.vector.riotx.core.ui.views.ReadMarkerView import im.vector.riotx.core.ui.views.ReadMarkerView
import im.vector.riotx.core.utils.DebouncedClickListener import im.vector.riotx.core.utils.DebouncedClickListener
import im.vector.riotx.core.utils.DimensionConverter
import im.vector.riotx.features.home.AvatarRenderer 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.TimelineEventController
import im.vector.riotx.features.reactions.widget.ReactionButton import im.vector.riotx.features.reactions.widget.ReactionButton
@ -172,6 +173,7 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : BaseEventItem<H>() {
val informationData: MessageInformationData, val informationData: MessageInformationData,
val avatarRenderer: AvatarRenderer, val avatarRenderer: AvatarRenderer,
val colorProvider: ColorProvider, val colorProvider: ColorProvider,
val dimensionConverter: DimensionConverter,
val itemLongClickListener: View.OnLongClickListener? = null, val itemLongClickListener: View.OnLongClickListener? = null,
val itemClickListener: View.OnClickListener? = null, val itemClickListener: View.OnClickListener? = null,
val memberClickListener: View.OnClickListener? = null, val memberClickListener: View.OnClickListener? = null,