]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java
whitespace
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / NewTransactionModel.java
index e1166b2ee9f3c0e095c509fb6a0e5cad9987c7f3..a2f356c68e6b44c42d7d1286c69812047648042f 100644 (file)
@@ -51,7 +51,7 @@ public class NewTransactionModel extends ViewModel {
     private final Item trailer = new Item(this);
     private final ArrayList<Item> items = new ArrayList<>();
     private final MutableLiveData<Boolean> isSubmittable = new MutableLiveData<>(false);
-    private final MutableLiveData<Integer> focusedItem = new MutableLiveData<>(null);
+    private final MutableLiveData<Integer> focusedItem = new MutableLiveData<>(0);
     private final MutableLiveData<Integer> accountCount = new MutableLiveData<>(0);
     public int getAccountCount() {
         return items.size();
@@ -90,6 +90,7 @@ public class NewTransactionModel extends ViewModel {
             @NonNull androidx.lifecycle.Observer<? super Integer> observer) {
         this.accountCount.removeObserver(observer);
     }
+    public int getFocusedItem() { return focusedItem.getValue(); }
     public void setFocusedItem(int position) {
         focusedItem.setValue(position);
     }
@@ -270,6 +271,18 @@ public class NewTransactionModel extends ViewModel {
     public void sendCountNotifications() {
         accountCount.setValue(getAccountCount());
     }
+    public void sendFocusedNotification() {
+        focusedItem.setValue(focusedItem.getValue());
+    }
+    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}
 
     //==========================================================================================
@@ -282,6 +295,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;
@@ -300,6 +314,9 @@ public class NewTransactionModel extends ViewModel {
             this.account = account;
             this.editable.setValue(true);
         }
+        public boolean focusIsOnAmount() {
+            return focusIsOnAmount;
+        }
         public NewTransactionModel getModel() {
             return model;
         }
@@ -444,11 +461,11 @@ public class NewTransactionModel extends ViewModel {
             final int myDay = c.get(Calendar.DAY_OF_MONTH);
 
             if (today.get(Calendar.YEAR) != myYear) {
-                return String.format(Locale.US, "%d/%02d/%02d", myYear, myMonth, myDay);
+                return String.format(Locale.US, "%d/%02d/%02d", myYear, myMonth + 1, myDay);
             }
 
             if (today.get(Calendar.MONTH) != myMonth) {
-                return String.format(Locale.US, "%d/%02d", myMonth, myDay);
+                return String.format(Locale.US, "%d/%02d", myMonth + 1, myDay);
             }
 
             return String.valueOf(myDay);
@@ -460,5 +477,8 @@ public class NewTransactionModel extends ViewModel {
         public void stopObservingEditableFlag(Observer<Boolean> observer) {
             editable.removeObserver(observer);
         }
+        public void setFocusIsOnAmount(boolean flag) {
+            focusIsOnAmount = flag;
+        }
     }
 }