]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java
new transaction: simulated backend communication is controller via menu (visible...
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / NewTransactionModel.java
index e1e1166d7b4cba65e962f0c067e7755f07225830..1f4cec56ab462ee6d903ab42254a5e57e20b7531 100644 (file)
@@ -53,6 +53,21 @@ public class NewTransactionModel extends ViewModel {
     private final MutableLiveData<Boolean> isSubmittable = new MutableLiveData<>(false);
     private final MutableLiveData<Integer> focusedItem = new MutableLiveData<>(0);
     private final MutableLiveData<Integer> accountCount = new MutableLiveData<>(0);
+    private final MutableLiveData<Boolean> simulateSave = new MutableLiveData<>(false);
+    public boolean getSimulateSave() {
+        return simulateSave.getValue();
+    }
+    public void setSimulateSave(boolean simulateSave) {
+        this.simulateSave.setValue(simulateSave);
+    }
+    public void toggleSimulateSave() {
+        simulateSave.setValue(!simulateSave.getValue());
+    }
+    public void observeSimulateSave(@NonNull @NotNull androidx.lifecycle.LifecycleOwner owner,
+                                    @NonNull
+                                            androidx.lifecycle.Observer<? super Boolean> observer) {
+        this.simulateSave.observe(owner, observer);
+    }
     public int getAccountCount() {
         return items.size();
     }
@@ -277,6 +292,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 +310,7 @@ public class NewTransactionModel extends ViewModel {
         private MutableLiveData<String> amountHint = new MutableLiveData<>(null);
         private NewTransactionModel model;
         private MutableLiveData<Boolean> editable = new MutableLiveData<>(true);
+        private boolean focusIsOnAmount = false;
         public Item(NewTransactionModel model) {
             this.model = model;
             type = ItemType.bottomFiller;
@@ -307,6 +329,9 @@ public class NewTransactionModel extends ViewModel {
             this.account = account;
             this.editable.setValue(true);
         }
+        public boolean focusIsOnAmount() {
+            return focusIsOnAmount;
+        }
         public NewTransactionModel getModel() {
             return model;
         }
@@ -368,6 +393,13 @@ public class NewTransactionModel extends ViewModel {
             this.date.setValue(date);
         }
         public void setDate(String text) {
+            if ((text == null) || text.trim()
+                                      .isEmpty())
+            {
+                setDate((Date) null);
+                return;
+            }
+
             int year, month, day;
             final Calendar c = GregorianCalendar.getInstance();
             Matcher m = reYMD.matcher(text);
@@ -467,5 +499,8 @@ public class NewTransactionModel extends ViewModel {
         public void stopObservingEditableFlag(Observer<Boolean> observer) {
             editable.removeObserver(observer);
         }
+        public void setFocusIsOnAmount(boolean flag) {
+            focusIsOnAmount = flag;
+        }
     }
 }