Merge pull request #6002 from k9mail/Issue-5961
Fix issues when switching between LTR and RTL languages
This commit is contained in:
commit
0c381c2bcd
2 changed files with 17 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
package com.fsck.k9.ui.base
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
@ -35,13 +36,22 @@ abstract class K9Activity(private val themeType: ThemeType) : AppCompatActivity(
|
|||
initializePushController()
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setLayoutDirection()
|
||||
listenForAppLanguageChanges()
|
||||
}
|
||||
|
||||
// On Android 12+ the layout direction doesn't seem to be updated when recreating the activity. This is a problem
|
||||
// when switching from an LTR to an RTL language (or the other way around) using the language picker in the app.
|
||||
private fun setLayoutDirection() {
|
||||
if (Build.VERSION.SDK_INT >= 31) {
|
||||
window.decorView.layoutDirection = resources.configuration.layoutDirection
|
||||
}
|
||||
}
|
||||
|
||||
private fun listenForAppLanguageChanges() {
|
||||
appLanguageManager.overrideLocale.asLiveData().observe(this) { overrideLocale ->
|
||||
if (overrideLocale != overrideLocaleOnLaunch) {
|
||||
ActivityCompat.recreate(this)
|
||||
recreateCompat()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +75,10 @@ abstract class K9Activity(private val themeType: ThemeType) : AppCompatActivity(
|
|||
|
||||
setSupportActionBar(toolbar)
|
||||
}
|
||||
|
||||
protected fun recreateCompat() {
|
||||
ActivityCompat.recreate(this)
|
||||
}
|
||||
}
|
||||
|
||||
enum class ThemeType {
|
||||
|
|
|
@ -539,7 +539,7 @@ open class MessageList :
|
|||
if (messageListActivityAppearance == null) {
|
||||
messageListActivityAppearance = MessageListActivityAppearance.create(generalSettingsManager)
|
||||
} else if (messageListActivityAppearance != MessageListActivityAppearance.create(generalSettingsManager)) {
|
||||
recreate()
|
||||
recreateCompat()
|
||||
}
|
||||
|
||||
if (displayMode != DisplayMode.MESSAGE_VIEW) {
|
||||
|
@ -1509,7 +1509,7 @@ open class MessageList :
|
|||
|
||||
private fun onToggleTheme() {
|
||||
themeManager.toggleMessageViewTheme()
|
||||
recreate()
|
||||
recreateCompat()
|
||||
}
|
||||
|
||||
private fun showDefaultTitleView() {
|
||||
|
|
Loading…
Reference in a new issue