mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-23 13:45:43 +03:00
Minor changes
This commit is contained in:
parent
006d17aac7
commit
77b4de3941
1 changed files with 17 additions and 6 deletions
|
@ -80,16 +80,14 @@ object LocaleHelper {
|
||||||
}
|
}
|
||||||
systemLocale = newLocale
|
systemLocale = newLocale
|
||||||
}
|
}
|
||||||
val newConfig = Configuration(config)
|
val newConfig = updateConfigLocale(config, appLocale ?: systemLocale ?: Locale.getDefault())
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
|
||||||
newConfig.locale = appLocale ?: systemLocale
|
|
||||||
} else {
|
|
||||||
newConfig.locales = LocaleList(appLocale ?: systemLocale)
|
|
||||||
}
|
|
||||||
val resources = app.resources
|
val resources = app.resources
|
||||||
resources.updateConfiguration(newConfig, resources.displayMetrics)
|
resources.updateConfiguration(newConfig, resources.displayMetrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the locale applied in the given configuration.
|
||||||
|
*/
|
||||||
private fun getConfigLocale(config: Configuration): Locale {
|
private fun getConfigLocale(config: Configuration): Locale {
|
||||||
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
||||||
config.locale
|
config.locale
|
||||||
|
@ -98,4 +96,17 @@ object LocaleHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new configuration with the given locale applied.
|
||||||
|
*/
|
||||||
|
private fun updateConfigLocale(config: Configuration, locale: Locale): Configuration {
|
||||||
|
val newConfig = Configuration(config)
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
||||||
|
newConfig.locale = locale
|
||||||
|
} else {
|
||||||
|
newConfig.locales = LocaleList(locale)
|
||||||
|
}
|
||||||
|
return newConfig
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue