From f509116c89a72e6db0aa09c6893798fb41404cca Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sun, 16 Aug 2020 15:59:57 +0300 Subject: [PATCH] move locale live-data initialization to a static initialization block avoids a warning about assigning locale to a final variable. the warning is misleading, because the locale is assigned to a final mutable live data object, not to a final variable --- .../main/java/net/ktnx/mobileledger/model/Data.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/model/Data.java b/app/src/main/java/net/ktnx/mobileledger/model/Data.java index a278a1b6..aaaf4991 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/Data.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/Data.java @@ -66,7 +66,7 @@ public final class Data { public static final MutableLiveData currencySymbolPosition = new MutableLiveData<>(); public static final MutableLiveData currencyGap = new MutableLiveData<>(true); - public static final MutableLiveData locale = new MutableLiveData<>(Locale.getDefault()); + public static final MutableLiveData locale = new MutableLiveData<>(); public static final MutableLiveData drawerOpen = new MutableLiveData<>(false); private static final MutableLiveData profile = new InertMutableLiveData<>(); @@ -74,6 +74,11 @@ public final class Data { private static final Locker profilesLocker = new Locker(); public static MutableLiveData foundTransactionItemIndex = new MutableLiveData<>(null); private static RetrieveTransactionsTask retrieveTransactionsTask; + + static { + locale.setValue(Locale.getDefault()); + } + @NonNull public static MobileLedgerProfile getProfile() { return Objects.requireNonNull(profile.getValue()); @@ -189,10 +194,10 @@ public final class Data { public static void refreshCurrencyData(Locale locale) { NumberFormat formatter = NumberFormat.getCurrencyInstance(locale); java.util.Currency currency = formatter.getCurrency(); - String symbol = currency.getSymbol(); + String symbol = currency != null ? currency.getSymbol() : ""; Logger.debug("locale", String.format( "Discovering currency symbol position for locale %s (currency is %s; symbol is %s)", - locale.toString(), currency.toString(), symbol)); + locale.toString(), currency != null ? currency.toString() : "", symbol)); String formatted = formatter.format(1234.56f); Logger.debug("locale", String.format("1234.56 formats as '%s'", formatted)); -- 2.39.2