Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 0c381c2b authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #6002 from k9mail/Issue-5961

Fix issues when switching between LTR and RTL languages
parents d6f218b3 685374da
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
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 {
+2 −2
Original line number Diff line number Diff line
@@ -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() {