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) --> <!-- Created to detect what has to be implemented (especially in the settings) -->
<bool name="false_not_implemented">false</bool> <bool name="false_not_implemented">false</bool>
<bool name="is_rtl">false</bool>
</resources> </resources>

View File

@ -17,6 +17,8 @@
package im.vector.app.core.resources package im.vector.app.core.resources
import android.content.res.Resources import android.content.res.Resources
import android.text.TextUtils
import android.view.View
import androidx.core.os.ConfigurationCompat import androidx.core.os.ConfigurationCompat
import java.util.Locale import java.util.Locale
import javax.inject.Inject 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.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.R
import im.vector.app.core.extensions.localDateTime import im.vector.app.core.extensions.localDateTime
import im.vector.app.core.resources.LocaleProvider 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.home.room.detail.timeline.factory.TimelineItemFactoryParams
import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.VectorPreferences
import org.matrix.android.sdk.api.session.Session 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 { private val isRTL: Boolean by lazy {
val currentLocale = localeProvider.current() localeProvider.isRTL()
TextUtils.getLayoutDirectionFromLocale(currentLocale) == View.LAYOUT_DIRECTION_RTL
} }
fun create(params: TimelineItemFactoryParams): TimelineMessageLayout { fun create(params: TimelineItemFactoryParams): TimelineMessageLayout {

View File

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

View File

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