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

Commit 685374da authored by cketti's avatar cketti
Browse files

Explicitly set the layout direction on Android 12+

parent 49160cb1
Loading
Loading
Loading
Loading
+10 −0
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,9 +36,18 @@ 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) {