]> git.ktnx.net Git - mobile-ledger.git/commitdiff
NT: account/amount focus also survives re-configuration
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 25 Nov 2019 21:25:52 +0000 (23:25 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 25 Nov 2019 21:25:52 +0000 (23:25 +0200)
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemsAdapter.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java

index fc17560614e9d85e8e72a30ce8d9cc59c678d861..f83eec8ae036b859f5de9f3b57cca88b922e9329 100644 (file)
@@ -38,6 +38,7 @@ import net.ktnx.mobileledger.async.DescriptionSelectedCallback;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerTransactionAccount;
 import net.ktnx.mobileledger.model.MobileLedgerProfile;
+import net.ktnx.mobileledger.ui.AutoCompleteTextViewWithClear;
 import net.ktnx.mobileledger.ui.DatePickerFragment;
 import net.ktnx.mobileledger.utils.Logger;
 import net.ktnx.mobileledger.utils.MLDB;
@@ -96,7 +97,14 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
                 boolean wasSyncing = syncingData;
                 syncingData = true;
                 try {
-                    adapter.updateFocusedItem(getAdapterPosition());
+                    final int pos = getAdapterPosition();
+                    adapter.updateFocusedItem(pos);
+                    if (v instanceof AutoCompleteTextViewWithClear) {
+                        adapter.noteFocusIsOnAccount(pos);
+                    }
+                    else {
+                        adapter.noteFocusIsOnAmount(pos);
+                    }
                 }
                 finally {
                     syncingData = wasSyncing;
@@ -233,10 +241,15 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
                     case transactionRow:
                         // do nothing if a row element already has the focus
                         if (!itemView.hasFocus()) {
-                            focused = tvAccount.requestFocus();
-                            tvAccount.dismissDropDown();
-                            if (focused)
-                                Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext());
+                            if (item.focusIsOnAmount()) {
+                                tvAmount.requestFocus();
+                            }
+                            else {
+                                focused = tvAccount.requestFocus();
+                                tvAccount.dismissDropDown();
+                                if (focused)
+                                    Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext());
+                            }
                         }
 
                         break;
index 452e348efb308afec5984f7e5bbd7d189aa02d0b..cb03f3d1d29425303f47ca1f9cc45f62e8339740 100644 (file)
@@ -204,4 +204,10 @@ class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItem
     public void updateFocusedItem(int position) {
         model.updateFocusedItem(position);
     }
+    public void noteFocusIsOnAccount(int position) {
+        model.noteFocusIsOnAccount(position);
+    }
+    public void noteFocusIsOnAmount(int position) {
+        model.noteFocusIsOnAmount(position);
+    }
 }
index e1e1166d7b4cba65e962f0c067e7755f07225830..9017973998da8c39efaf91b110d640de1b22decf 100644 (file)
@@ -277,6 +277,12 @@ public class NewTransactionModel extends ViewModel {
     public void updateFocusedItem(int position) {
         focusedItem.setValue(position);
     }
+    public void noteFocusIsOnAccount(int position) {
+        getItem(position).setFocusIsOnAmount(false);
+    }
+    public void noteFocusIsOnAmount(int position) {
+        getItem(position).setFocusIsOnAmount(true);
+    }
     enum ItemType {generalData, transactionRow, bottomFiller}
 
     //==========================================================================================
@@ -289,6 +295,10 @@ public class NewTransactionModel extends ViewModel {
         private MutableLiveData<String> amountHint = new MutableLiveData<>(null);
         private NewTransactionModel model;
         private MutableLiveData<Boolean> editable = new MutableLiveData<>(true);
+        public boolean focusIsOnAmount() {
+            return focusIsOnAmount;
+        }
+        private boolean focusIsOnAmount = false;
         public Item(NewTransactionModel model) {
             this.model = model;
             type = ItemType.bottomFiller;
@@ -467,5 +477,8 @@ public class NewTransactionModel extends ViewModel {
         public void stopObservingEditableFlag(Observer<Boolean> observer) {
             editable.removeObserver(observer);
         }
+        public void setFocusIsOnAmount(boolean flag) {
+            focusIsOnAmount = flag;
+        }
     }
 }