Bubble: get LayoutDirection (RTL) from current Locale

This commit is contained in:
ganfra 2022-02-03 17:53:25 +01:00
parent 2e2da16a6b
commit 04234318e5
6 changed files with 14 additions and 15 deletions

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="is_rtl">true</bool>
</resources>

View file

@ -4,6 +4,4 @@
<!-- Created to detect what has to be implemented (especially in the settings) -->
<bool name="false_not_implemented">false</bool>
<bool name="is_rtl">false</bool>
</resources>

View file

@ -17,6 +17,8 @@
package im.vector.app.core.resources
import android.content.res.Resources
import android.text.TextUtils
import android.view.View
import androidx.core.os.ConfigurationCompat
import java.util.Locale
import javax.inject.Inject
@ -29,3 +31,7 @@ class LocaleProvider @Inject constructor(private val resources: Resources) {
}
fun LocaleProvider.isEnglishSpeaking() = current().language.startsWith("en")
fun LocaleProvider.getLayoutDirectionFromCurrentLocale() = TextUtils.getLayoutDirectionFromLocale(current())
fun LocaleProvider.isRTL() = getLayoutDirectionFromCurrentLocale() == View.LAYOUT_DIRECTION_RTL

View file

@ -22,6 +22,7 @@ import android.view.View
import im.vector.app.R
import im.vector.app.core.extensions.localDateTime
import im.vector.app.core.resources.LocaleProvider
import im.vector.app.core.resources.isRTL
import im.vector.app.features.home.room.detail.timeline.factory.TimelineItemFactoryParams
import im.vector.app.features.settings.VectorPreferences
import org.matrix.android.sdk.api.session.Session
@ -71,8 +72,7 @@ class TimelineMessageLayoutFactory @Inject constructor(private val session: Sess
}
private val isRTL: Boolean by lazy {
val currentLocale = localeProvider.current()
TextUtils.getLayoutDirectionFromLocale(currentLocale) == View.LAYOUT_DIRECTION_RTL
localeProvider.isRTL()
}
fun create(params: TimelineItemFactoryParams): TimelineMessageLayout {

View file

@ -21,7 +21,6 @@ import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.RippleDrawable
import android.text.TextUtils
import android.util.AttributeSet
import android.view.View
import android.view.ViewOutlineProvider
@ -35,6 +34,7 @@ import androidx.core.view.updateLayoutParams
import com.google.android.material.shape.MaterialShapeDrawable
import im.vector.app.R
import im.vector.app.core.resources.LocaleProvider
import im.vector.app.core.resources.getLayoutDirectionFromCurrentLocale
import im.vector.app.core.utils.DimensionConverter
import im.vector.app.databinding.ViewMessageBubbleBinding
import im.vector.app.features.home.room.detail.timeline.style.TimelineMessageLayout
@ -65,8 +65,7 @@ class MessageBubbleView @JvmOverloads constructor(context: Context, attrs: Attri
override fun onFinishInflate() {
super.onFinishInflate()
views = ViewMessageBubbleBinding.bind(this)
val currentLocale = LocaleProvider(resources).current()
val currentLayoutDirection = TextUtils.getLayoutDirectionFromLocale(currentLocale)
val currentLayoutDirection = LocaleProvider(resources).getLayoutDirectionFromCurrentLocale()
val layoutDirectionToSet = if (isIncoming) {
currentLayoutDirection
} else {

View file

@ -19,10 +19,12 @@ package im.vector.app.features.location
import android.content.res.Resources
import im.vector.app.BuildConfig
import im.vector.app.R
import im.vector.app.core.resources.LocaleProvider
import im.vector.app.core.resources.isRTL
import javax.inject.Inject
class UrlMapProvider @Inject constructor(
private val resources: Resources
private val localeProvider: LocaleProvider
) {
private val keyParam = "?key=${BuildConfig.mapTilerKey}"
@ -49,7 +51,7 @@ class UrlMapProvider @Inject constructor(
append(height)
append(".png")
append(keyParam)
if (!resources.getBoolean(R.bool.is_rtl)) {
if (!localeProvider.isRTL()) {
// On LTR languages we want the legal mentions to be displayed on the bottom left of the image
append("&attribution=bottomleft")
}