Skip to content

Commit

Permalink
FIX: changing the OS locale doesn't change the app locale (#4323)
Browse files Browse the repository at this point in the history
* When the serving size value is incorrect (eg: "serving" with barcode 5900951251849), the app shouldn't crash
#4270

* FIX: changing the OS locale doesn't change the app locale
Issue #4309

* [CodeFactor] Apply fixes

Co-authored-by: codefactor-io <support@codefactor.io>
  • Loading branch information
g123k and code-factor committed Oct 24, 2021
1 parent b3cc1c2 commit 965b4ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Expand Up @@ -310,13 +310,16 @@ class ProductEditNutritionFactsFragment : ProductEditFragment() {
getModifierIndex(nutriments[nutriment]?.modifier)

private fun updateServingSize(servingSize: String) {
try {
val (value, unit) = parseServing(servingSize)

val (value, unit) = parseServing(servingSize)

binding.servingSize.setText(value)
binding.servingSize.setText(value)

if (unit != null) {
binding.servingSize.unitSpinner?.setSelection(getServingUnitIndex(unit))
if (unit != null) {
binding.servingSize.unitSpinner?.setSelection(getServingUnitIndex(unit))
}
} catch (exception : IllegalArgumentException) {
binding.servingSize.setText("")
}
}

Expand Down
Expand Up @@ -40,12 +40,14 @@ class LocaleManager @Inject constructor(
private var currentLocale: Locale

init {
currentLocale = getLanguageFromPrefs()?.let {
LocaleUtils.parseLocale(it)
} ?: Locale.getDefault()
currentLocale = reloadLocale()
}

fun restoreLocalizedContext(context: Context) = changeAppLanguage(context, currentLocale)
fun restoreLocalizedContext(context: Context): Context = changeAppLanguage(context, reloadLocale())

private fun reloadLocale() = getLanguageFromPrefs()?.let {
LocaleUtils.parseLocale(it)
} ?: Locale.getDefault()

/**
* Get the language of the app [Locale] (Selected in settings).
Expand Down

0 comments on commit 965b4ba

Please sign in to comment.