Improve room previews for RTL/LTR mixes of name and message

Change-Id: Ic8634ca41cef1c052e8f5769cf40f08e7e4e140c
This commit is contained in:
SpiritCroc 2021-10-31 11:01:30 +01:00
parent 983b71dc4b
commit 6a96b50b84
2 changed files with 12 additions and 5 deletions

View File

@ -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
}

View File

@ -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"
}
}
}