11package com.github.libretube.ui.base
22
3+ import android.content.Context
34import android.content.pm.ActivityInfo
45import android.os.Bundle
56import androidx.appcompat.app.AppCompatActivity
@@ -9,6 +10,7 @@ import com.github.libretube.helpers.LocaleHelper
910import com.github.libretube.helpers.PreferenceHelper
1011import com.github.libretube.helpers.ThemeHelper
1112import com.github.libretube.helpers.WindowHelper
13+ import java.util.Locale
1214
1315/* *
1416 * Activity that applies the LibreTube theme and the in-app language
@@ -39,9 +41,6 @@ open class BaseActivity : AppCompatActivity() {
3941 ThemeHelper .updateTheme(this )
4042 if (isDialogActivity) ThemeHelper .applyDialogActivityTheme(this )
4143
42- // set the apps language
43- LocaleHelper .updateLanguage(this )
44-
4544 requestOrientationChange()
4645
4746 // wait for the window decor view to be drawn before detecting display cutouts
@@ -53,6 +52,24 @@ open class BaseActivity : AppCompatActivity() {
5352 super .onCreate(savedInstanceState)
5453 }
5554
55+ override fun attachBaseContext (newBase : Context ? ) {
56+ if (newBase == null ) {
57+ super .attachBaseContext(null )
58+ return
59+ }
60+
61+ // change the locale according to the user's preference (or system language as fallback)
62+ val locale = LocaleHelper .getAppLocale()
63+ Locale .setDefault(locale)
64+
65+ val configuration = newBase.resources.configuration.apply {
66+ setLocale(locale)
67+ }
68+ val newContext = newBase.createConfigurationContext(configuration)
69+
70+ super .attachBaseContext(newContext)
71+ }
72+
5673 /* *
5774 * Rotate the screen according to the app orientation preference
5875 */
0 commit comments