Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

setLanguageWithoutNotification #74

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,32 @@ open class LocalizationActivityDelegate(val activity: Activity) {
}
}

fun setLanguageWithoutNotification(context: Context, newLanguage: String) {
val locale = Locale(newLanguage)
setLanguageWithoutNotification(context, locale)
}

fun setLanguageWithoutNotification(context: Context, newLanguage: String, newCountry: String) {
val locale = Locale(newLanguage, newCountry)
setLanguageWithoutNotification(context, locale)
}

/**
* Change application language but without recreating it
*/
fun setLanguageWithoutNotification(context: Context, newLocale: Locale) {

val oldLocale = LanguageSetting.getLanguageWithDefault(
context,
LanguageSetting.getDefaultLanguage(context)
)
if (!isCurrentLanguageSetting(newLocale, oldLocale)) {
LanguageSetting.setLanguage(activity, newLocale)
// Don't notifiy current activity notifyLanguageChanged()
}

}

// Get current language
fun getLanguage(context: Context): Locale {
return LanguageSetting.getLanguageWithDefault(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ abstract class LocalizationActivity : AppCompatActivity, OnLocaleChangedListener
localizationDelegate.setLanguage(this, locale)
}

fun setLanguageWithoutNotification(language: String) {
localizationDelegate.setLanguageWithoutNotification(this, language)
}

fun setLanguageWithoutNotification(language: String, country: String) {
localizationDelegate.setLanguageWithoutNotification(this, language, country)
}

fun setLanguageWithoutNotification(locale: Locale) {
localizationDelegate.setLanguageWithoutNotification(this, locale)
}

fun getCurrentLanguage(): Locale {
return localizationDelegate.getLanguage(this)
}
Expand Down