Merge pull request #704 from Bnyro/master

fixes
This commit is contained in:
Bnyro 2022-07-06 16:15:20 +02:00 committed by GitHub
commit 2aa68ecab9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 11 deletions

View File

@ -12,6 +12,7 @@ class NoInternetActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
DynamicColors.applyToActivityIfAvailable(this) DynamicColors.applyToActivityIfAvailable(this)
ThemeHelper.updateTheme(this)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = ActivityNointernetBinding.inflate(layoutInflater) binding = ActivityNointernetBinding.inflate(layoutInflater)
binding.retryButton.setOnClickListener { binding.retryButton.setOnClickListener {

View File

@ -8,20 +8,21 @@ import java.util.*
object LocaleHelper { object LocaleHelper {
fun updateLanguage(context: Context) { fun updateLanguage(context: Context) {
val languageName = PreferenceHelper.getString(context, "language", "en") val languageName = PreferenceHelper.getString(context, "language", "sys")
if (languageName != "") { if (languageName == "sys") updateLocaleConf(context, Locale.getDefault())
setLanguage(context, languageName!!) 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) { private fun updateLocaleConf(context: Context, locale: Locale) {
val 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()
}
// Change API Language // Change API Language
Locale.setDefault(locale) Locale.setDefault(locale)