]> git.ktnx.net Git - mobile-ledger.git/commitdiff
track locale changes in new transaction entry activity
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 20 Feb 2020 17:43:32 +0000 (19:43 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 20 Feb 2020 17:43:32 +0000 (19:43 +0200)
app/src/main/java/net/ktnx/mobileledger/App.java
app/src/main/java/net/ktnx/mobileledger/model/Data.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java

index fb69138b8cdcdf273fe29f410daa49007d428dbf..d6b1ffaf7afc784ebd41ccb5a1227bf2e1bb47ac 100644 (file)
@@ -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();
index b79ed766c3c59031e6c9a901648960f3917bdf88..1b659ff7d866485d8874b1efcfadafc5d7084186 100644 (file)
@@ -55,6 +55,7 @@ public final class Data {
     public static MutableLiveData<Currency.Position> currencySymbolPosition =
             new MutableLiveData<>();
     public static MutableLiveData<Boolean> currencyGap = new MutableLiveData<>(true);
+    public static MutableLiveData<Locale> locale = new MutableLiveData<>(Locale.getDefault());
     private static AtomicInteger backgroundTaskCount = new AtomicInteger(0);
     private static Locker profilesLocker = new Locker();
     private static RetrieveTransactionsTask retrieveTransactionsTask;
index 45a57e542988dbcf9f485c9cf7d0f2652077ca66..0ee99136eaa0d51579677b296e4a55e42a397b85 100644 (file)
@@ -81,6 +81,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
     private Observer<Boolean> editableObserver;
     private Observer<Boolean> commentVisibleObserver;
     private Observer<String> commentObserver;
+    private Observer<Locale> 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 {