From 77b4de3941be34547673573f66499eb5576ecf5b Mon Sep 17 00:00:00 2001 From: len Date: Mon, 26 Dec 2016 17:21:17 +0100 Subject: [PATCH] Minor changes --- .../eu/kanade/tachiyomi/util/LocaleHelper.kt | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/LocaleHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/util/LocaleHelper.kt index 4a2995bb1..1e8568b4d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/LocaleHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/LocaleHelper.kt @@ -80,16 +80,14 @@ object LocaleHelper { } systemLocale = newLocale } - val newConfig = Configuration(config) - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { - newConfig.locale = appLocale ?: systemLocale - } else { - newConfig.locales = LocaleList(appLocale ?: systemLocale) - } + val newConfig = updateConfigLocale(config, appLocale ?: systemLocale ?: Locale.getDefault()) val resources = app.resources resources.updateConfiguration(newConfig, resources.displayMetrics) } + /** + * Returns the locale applied in the given configuration. + */ private fun getConfigLocale(config: Configuration): Locale { return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { 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 + } + }