Locale fix. Kotlin update to 1.0.6
This commit is contained in:
parent
dc882b4dce
commit
a7192e866f
2 changed files with 13 additions and 6 deletions
|
@ -204,7 +204,7 @@ dependencies {
|
||||||
}
|
}
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = '1.0.5-2'
|
ext.kotlin_version = '1.0.6'
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,12 @@ object LocaleHelper {
|
||||||
*/
|
*/
|
||||||
private var appLocale = getLocaleFromString(preferences.lang())
|
private var appLocale = getLocaleFromString(preferences.lang())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The currently applied locale. Used to avoid losing the selected language after a non locale
|
||||||
|
* configuration change to the application.
|
||||||
|
*/
|
||||||
|
private var currentLocale: Locale? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the locale for the value stored in preferences, or null if it's system language.
|
* Returns the locale for the value stored in preferences, or null if it's system language.
|
||||||
*
|
*
|
||||||
|
@ -72,15 +78,16 @@ object LocaleHelper {
|
||||||
if (systemLocale == null) {
|
if (systemLocale == null) {
|
||||||
systemLocale = getConfigLocale(config)
|
systemLocale = getConfigLocale(config)
|
||||||
}
|
}
|
||||||
// In API 16 and lower the system locale can't be changed.
|
// In API 16 and lower [systemLocale] can't be changed.
|
||||||
if (configChange && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
if (configChange && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||||
val newLocale = getConfigLocale(config)
|
val configLocale = getConfigLocale(config)
|
||||||
if (systemLocale == newLocale) {
|
if (currentLocale == configLocale) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
systemLocale = newLocale
|
systemLocale = configLocale
|
||||||
}
|
}
|
||||||
val newConfig = updateConfigLocale(config, appLocale ?: systemLocale ?: Locale.getDefault())
|
currentLocale = appLocale ?: systemLocale ?: Locale.getDefault()
|
||||||
|
val newConfig = updateConfigLocale(config, currentLocale!!)
|
||||||
val resources = app.resources
|
val resources = app.resources
|
||||||
resources.updateConfiguration(newConfig, resources.displayMetrics)
|
resources.updateConfiguration(newConfig, resources.displayMetrics)
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue