From 6a96b50b84c6937175161bcdf84ea9b3fceb6f16 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Sun, 31 Oct 2021 11:01:30 +0100 Subject: [PATCH] Improve room previews for RTL/LTR mixes of name and message Change-Id: Ic8634ca41cef1c052e8f5769cf40f08e7e4e140c --- .../im/vector/app/core/resources/StringProvider.kt | 3 +++ .../timeline/format/DisplayableEventFormatter.kt | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/resources/StringProvider.kt b/vector/src/main/java/im/vector/app/core/resources/StringProvider.kt index 7e322daaae..8a78461f65 100644 --- a/vector/src/main/java/im/vector/app/core/resources/StringProvider.kt +++ b/vector/src/main/java/im/vector/app/core/resources/StringProvider.kt @@ -17,6 +17,7 @@ package im.vector.app.core.resources import android.content.res.Resources +import android.view.View import androidx.annotation.NonNull import androidx.annotation.PluralsRes import androidx.annotation.StringRes @@ -57,4 +58,6 @@ class StringProvider @Inject constructor(private val resources: Resources) { fun getQuantityString(@PluralsRes resId: Int, quantity: Int, vararg formatArgs: Any?): String { return resources.getQuantityString(resId, quantity, *formatArgs) } + + fun preferRTL(): Boolean = resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/DisplayableEventFormatter.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/DisplayableEventFormatter.kt index b5831b33b8..7363d07d01 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/DisplayableEventFormatter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/DisplayableEventFormatter.kt @@ -146,14 +146,18 @@ class DisplayableEventFormatter @Inject constructor( private fun simpleFormat(senderName: String, body: CharSequence, appendAuthor: Boolean): CharSequence { return if (appendAuthor) { + val forceDirectionChar = if (stringProvider.preferRTL()) "\u200f" else "\u200e" span { - text = senderName - textColor = colorProvider.getColorFromAttribute(R.attr.vctr_content_primary) - } - .append(": ") + text = forceDirectionChar + }.append( + span { + text = senderName + textColor = colorProvider.getColorFromAttribute(R.attr.vctr_content_primary) + }) + .append(": $forceDirectionChar") .append(body) } else { - body + "\u2068$body" } } }