From 04234318e5bb52f3ec0e95ff87826229d41d2ba9 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 3 Feb 2022 17:53:25 +0100 Subject: [PATCH] Bubble: get LayoutDirection (RTL) from current Locale --- library/ui-styles/src/main/res/values-ldrtl/bools.xml | 6 ------ library/ui-styles/src/main/res/values/bools.xml | 2 -- .../java/im/vector/app/core/resources/LocaleProvider.kt | 6 ++++++ .../detail/timeline/style/TimelineMessageLayoutFactory.kt | 4 ++-- .../home/room/detail/timeline/view/MessageBubbleView.kt | 5 ++--- .../java/im/vector/app/features/location/UrlMapProvider.kt | 6 ++++-- 6 files changed, 14 insertions(+), 15 deletions(-) delete mode 100644 library/ui-styles/src/main/res/values-ldrtl/bools.xml diff --git a/library/ui-styles/src/main/res/values-ldrtl/bools.xml b/library/ui-styles/src/main/res/values-ldrtl/bools.xml deleted file mode 100644 index 27b280985f..0000000000 --- a/library/ui-styles/src/main/res/values-ldrtl/bools.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - true - - \ No newline at end of file diff --git a/library/ui-styles/src/main/res/values/bools.xml b/library/ui-styles/src/main/res/values/bools.xml index 9966999f28..93d5f925af 100644 --- a/library/ui-styles/src/main/res/values/bools.xml +++ b/library/ui-styles/src/main/res/values/bools.xml @@ -4,6 +4,4 @@ false - false - \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/core/resources/LocaleProvider.kt b/vector/src/main/java/im/vector/app/core/resources/LocaleProvider.kt index 6a9d434aea..fdb5f21b61 100644 --- a/vector/src/main/java/im/vector/app/core/resources/LocaleProvider.kt +++ b/vector/src/main/java/im/vector/app/core/resources/LocaleProvider.kt @@ -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 diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/style/TimelineMessageLayoutFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/style/TimelineMessageLayoutFactory.kt index bded4505b5..b24ab81997 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/style/TimelineMessageLayoutFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/style/TimelineMessageLayoutFactory.kt @@ -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 { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/view/MessageBubbleView.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/view/MessageBubbleView.kt index de40a681b3..422dfb0dbd 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/view/MessageBubbleView.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/view/MessageBubbleView.kt @@ -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 { diff --git a/vector/src/main/java/im/vector/app/features/location/UrlMapProvider.kt b/vector/src/main/java/im/vector/app/features/location/UrlMapProvider.kt index 76d44f5ece..8e64dc959e 100644 --- a/vector/src/main/java/im/vector/app/features/location/UrlMapProvider.kt +++ b/vector/src/main/java/im/vector/app/features/location/UrlMapProvider.kt @@ -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") }