Closed Shahjahan786 closed 4 years ago
You can do this with an extension function:
fun LocalizationActivityDelegate.setLanguageWithoutNotification(context: Context, newLocale: Locale) {
val oldLocale = LanguageSetting.getLanguageWithDefault(
context,
LanguageSetting.getDefaultLanguage(context)
)
if (!isCurrentLanguageSetting(newLocale, oldLocale)) {
LanguageSetting.setLanguage(activity, newLocale)
// Dont notifiy current activity notifyLanguageChanged()
}
}
private fun isCurrentLanguageSetting(newLocale: Locale, currentLocale: Locale): Boolean {
return newLocale.toString() == currentLocale.toString()
}
You can do this with an extension function:
fun LocalizationActivityDelegate.setLanguageWithoutNotification(context: Context, newLocale: Locale) { val oldLocale = LanguageSetting.getLanguageWithDefault( context, LanguageSetting.getDefaultLanguage(context) ) if (!isCurrentLanguageSetting(newLocale, oldLocale)) { LanguageSetting.setLanguage(activity, newLocale) // Dont notifiy current activity notifyLanguageChanged() } } private fun isCurrentLanguageSetting(newLocale: Locale, currentLocale: Locale): Boolean { return newLocale.toString() == currentLocale.toString() }
What if app source code is in Java?
I think you have to create a new class that extends LocalizationActivityDelegate
.
Add setLanguageWithoutNotification
in the new class and use your custom class instead LocalizationActivityDelegate
.
setLanguageWithoutNotification
Ok Got it, Thanks @sgallego
Please add support for changing language without activity recreation. like ActivityRecreationHelper