mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
Merge pull request #7078 from Bnyro/master
fix: app language doesn't change on main activity
This commit is contained in:
commit
e73fb55cc9
@ -1,7 +1,6 @@
|
|||||||
package com.github.libretube.helpers
|
package com.github.libretube.helpers
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.Configuration
|
|
||||||
import android.telephony.TelephonyManager
|
import android.telephony.TelephonyManager
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import androidx.core.os.ConfigurationCompat
|
import androidx.core.os.ConfigurationCompat
|
||||||
@ -26,18 +25,6 @@ object LocaleHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateLanguage(context: Context) {
|
|
||||||
val locale = getAppLocale()
|
|
||||||
updateResources(context, locale)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateResources(context: Context, locale: Locale) {
|
|
||||||
Locale.setDefault(locale)
|
|
||||||
val configuration: Configuration = context.resources.configuration
|
|
||||||
configuration.setLocale(locale)
|
|
||||||
context.createConfigurationContext(configuration)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getDetectedCountry(context: Context): String {
|
private fun getDetectedCountry(context: Context): String {
|
||||||
return detectSIMCountry(context)
|
return detectSIMCountry(context)
|
||||||
?: detectNetworkCountry(context)
|
?: detectNetworkCountry(context)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.github.libretube.ui.base
|
package com.github.libretube.ui.base
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
@ -9,6 +10,7 @@ import com.github.libretube.helpers.LocaleHelper
|
|||||||
import com.github.libretube.helpers.PreferenceHelper
|
import com.github.libretube.helpers.PreferenceHelper
|
||||||
import com.github.libretube.helpers.ThemeHelper
|
import com.github.libretube.helpers.ThemeHelper
|
||||||
import com.github.libretube.helpers.WindowHelper
|
import com.github.libretube.helpers.WindowHelper
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activity that applies the LibreTube theme and the in-app language
|
* Activity that applies the LibreTube theme and the in-app language
|
||||||
@ -39,9 +41,6 @@ open class BaseActivity : AppCompatActivity() {
|
|||||||
ThemeHelper.updateTheme(this)
|
ThemeHelper.updateTheme(this)
|
||||||
if (isDialogActivity) ThemeHelper.applyDialogActivityTheme(this)
|
if (isDialogActivity) ThemeHelper.applyDialogActivityTheme(this)
|
||||||
|
|
||||||
// set the apps language
|
|
||||||
LocaleHelper.updateLanguage(this)
|
|
||||||
|
|
||||||
requestOrientationChange()
|
requestOrientationChange()
|
||||||
|
|
||||||
// wait for the window decor view to be drawn before detecting display cutouts
|
// wait for the window decor view to be drawn before detecting display cutouts
|
||||||
@ -53,6 +52,24 @@ open class BaseActivity : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
|
if (newBase == null) {
|
||||||
|
super.attachBaseContext(null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// change the locale according to the user's preference (or system language as fallback)
|
||||||
|
val locale = LocaleHelper.getAppLocale()
|
||||||
|
Locale.setDefault(locale)
|
||||||
|
|
||||||
|
val configuration = newBase.resources.configuration.apply {
|
||||||
|
setLocale(locale)
|
||||||
|
}
|
||||||
|
val newContext = newBase.createConfigurationContext(configuration)
|
||||||
|
|
||||||
|
super.attachBaseContext(newContext)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotate the screen according to the app orientation preference
|
* Rotate the screen according to the app orientation preference
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user