From 72f37e6481835a3bd47152f0968263bbd33690e6 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 6 Jul 2022 16:07:27 +0200 Subject: [PATCH 1/2] fix color --- .../com/github/libretube/activities/NoInternetActivity.kt | 1 + app/src/main/java/com/github/libretube/util/LocaleHelper.kt | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/activities/NoInternetActivity.kt b/app/src/main/java/com/github/libretube/activities/NoInternetActivity.kt index cc2dcbe5a..0e391328c 100644 --- a/app/src/main/java/com/github/libretube/activities/NoInternetActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/NoInternetActivity.kt @@ -12,6 +12,7 @@ class NoInternetActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { DynamicColors.applyToActivityIfAvailable(this) + ThemeHelper.updateTheme(this) super.onCreate(savedInstanceState) binding = ActivityNointernetBinding.inflate(layoutInflater) binding.retryButton.setOnClickListener { diff --git a/app/src/main/java/com/github/libretube/util/LocaleHelper.kt b/app/src/main/java/com/github/libretube/util/LocaleHelper.kt index ca0fb184c..40293f0ef 100644 --- a/app/src/main/java/com/github/libretube/util/LocaleHelper.kt +++ b/app/src/main/java/com/github/libretube/util/LocaleHelper.kt @@ -15,12 +15,12 @@ object LocaleHelper { } private fun setLanguage(context: Context, languageName: String) { - val locale = if (languageName != "sys" && "$languageName".length < 3) { + val locale : Locale? = if (languageName == "sys" && "$languageName".length < 3) { Locale(languageName) } else if ("$languageName".length > 3) { Locale(languageName?.substring(0, 2), languageName?.substring(4, 6)) } else { - Locale.getDefault() + null } // Change API Language Locale.setDefault(locale) From b511d21fea3600ea75638398289fe0e852773b95 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 6 Jul 2022 16:13:51 +0200 Subject: [PATCH 2/2] fix locales --- .../com/github/libretube/util/LocaleHelper.kt | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/github/libretube/util/LocaleHelper.kt b/app/src/main/java/com/github/libretube/util/LocaleHelper.kt index 40293f0ef..f1b4ac6b7 100644 --- a/app/src/main/java/com/github/libretube/util/LocaleHelper.kt +++ b/app/src/main/java/com/github/libretube/util/LocaleHelper.kt @@ -8,20 +8,21 @@ import java.util.* object LocaleHelper { fun updateLanguage(context: Context) { - val languageName = PreferenceHelper.getString(context, "language", "en") - if (languageName != "") { - setLanguage(context, languageName!!) + val languageName = PreferenceHelper.getString(context, "language", "sys") + if (languageName == "sys") updateLocaleConf(context, Locale.getDefault()) + else if ("$languageName".length < 3) { + val locale = Locale(languageName.toString()) + updateLocaleConf(context, locale) + } else if ("$languageName".length > 3) { + val locale = Locale( + languageName?.substring(0, 2).toString(), + languageName?.substring(4, 6).toString() + ) + updateLocaleConf(context, locale) } } - private fun setLanguage(context: Context, languageName: String) { - val locale : Locale? = if (languageName == "sys" && "$languageName".length < 3) { - Locale(languageName) - } else if ("$languageName".length > 3) { - Locale(languageName?.substring(0, 2), languageName?.substring(4, 6)) - } else { - null - } + private fun updateLocaleConf(context: Context, locale: Locale) { // Change API Language Locale.setDefault(locale)