From 0fb03702b44e99bef2a5674d96f025595aed4274 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Thu, 20 Feb 2020 19:43:32 +0200 Subject: [PATCH] track locale changes in new transaction entry activity --- app/src/main/java/net/ktnx/mobileledger/App.java | 2 ++ app/src/main/java/net/ktnx/mobileledger/model/Data.java | 1 + .../ui/activity/NewTransactionItemHolder.java | 9 ++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/App.java b/app/src/main/java/net/ktnx/mobileledger/App.java index fb69138b..d6b1ffaf 100644 --- a/app/src/main/java/net/ktnx/mobileledger/App.java +++ b/app/src/main/java/net/ktnx/mobileledger/App.java @@ -89,6 +89,8 @@ public class App extends Application { public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); updateMonthNames(); + Data.refreshCurrencyData(Locale.getDefault()); + Data.locale.setValue(Locale.getDefault()); } public SQLiteDatabase getDB() { if (dbHelper == null) initDb(); 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 b79ed766..1b659ff7 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/Data.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/Data.java @@ -55,6 +55,7 @@ public final class Data { public static MutableLiveData currencySymbolPosition = new MutableLiveData<>(); public static MutableLiveData currencyGap = new MutableLiveData<>(true); + public static MutableLiveData locale = new MutableLiveData<>(Locale.getDefault()); private static AtomicInteger backgroundTaskCount = new AtomicInteger(0); private static Locker profilesLocker = new Locker(); private static RetrieveTransactionsTask retrieveTransactionsTask; diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java index 45a57e54..0ee99136 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java @@ -81,6 +81,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder private Observer editableObserver; private Observer commentVisibleObserver; private Observer commentObserver; + private Observer localeObserver; private boolean inUpdate = false; private boolean syncingData = false; private View commentButton; @@ -206,7 +207,6 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder tvComment.addTextChangedListener(tw); tvAmount.addTextChangedListener(amountWatcher); - // FIXME: react on locale changes if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) tvAmount.setKeyListener(DigitsKeyListener.getInstance(Locale.getDefault(), true, true)); else @@ -314,6 +314,11 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder else tvAmount.setImeOptions(EditorInfo.IME_ACTION_NEXT); }; + + localeObserver = locale -> { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + tvAmount.setKeyListener(DigitsKeyListener.getInstance(locale, true, true)); + }; } private void setEditable(Boolean editable) { tvDate.setEnabled(editable); @@ -442,6 +447,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder .stopObservingFocusedItem(focusedAccountObserver); this.item.getModel() .stopObservingAccountCount(accountCountObserver); + Data.locale.removeObserver(localeObserver); this.item = null; } @@ -494,6 +500,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder .observeFocusedItem(activity, focusedAccountObserver); item.getModel() .observeAccountCount(activity, accountCountObserver); + Data.locale.observe(activity, localeObserver); } } finally { -- 2.39.5