]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java
new transaction: hide currency/commodity selector by default; add menu item for showing
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / NewTransactionModel.java
index 0198b8696a12de0c3cbe929baa3a64461d43c8da..cad07c0def34ee0ea3acb810775aa98a81c4f270 100644 (file)
@@ -26,6 +26,7 @@ import androidx.lifecycle.Observer;
 import androidx.lifecycle.ViewModel;
 
 import net.ktnx.mobileledger.BuildConfig;
+import net.ktnx.mobileledger.model.Currency;
 import net.ktnx.mobileledger.model.LedgerTransactionAccount;
 import net.ktnx.mobileledger.utils.Logger;
 import net.ktnx.mobileledger.utils.Misc;
@@ -55,6 +56,7 @@ public class NewTransactionModel extends ViewModel {
     private final MutableLiveData<Integer> focusedItem = new MutableLiveData<>(0);
     private final MutableLiveData<Integer> accountCount = new MutableLiveData<>(0);
     private final MutableLiveData<Boolean> simulateSave = new MutableLiveData<>(false);
+    final MutableLiveData<Boolean> showCurrency = new MutableLiveData<>(false);
     public boolean getSimulateSave() {
         return simulateSave.getValue();
     }
@@ -304,6 +306,22 @@ public class NewTransactionModel extends ViewModel {
         final MutableLiveData<Boolean> commentVisible = getItem(position).commentVisible;
         commentVisible.postValue(!commentVisible.getValue());
     }
+    public void moveItemLast(int index) {
+        /*   0
+             1   <-- index
+             2
+             3   <-- desired position
+         */
+        int itemCount = items.size();
+
+        if (index < itemCount - 1) {
+            Item acc = items.remove(index);
+            items.add(itemCount - 1, acc);
+        }
+    }
+    public void toggleCurrencyVisible() {
+        showCurrency.setValue(!showCurrency.getValue());
+    }
     enum ItemType {generalData, transactionRow, bottomFiller}
 
     //==========================================================================================
@@ -321,6 +339,7 @@ public class NewTransactionModel extends ViewModel {
         private FocusedElement focusedElement = FocusedElement.Account;
         private MutableLiveData<String> comment = new MutableLiveData<>(null);
         private MutableLiveData<Boolean> commentVisible = new MutableLiveData<>(false);
+        private MutableLiveData<Currency> currency = new MutableLiveData<>(null);
         public Item(NewTransactionModel model) {
             this.model = model;
             type = ItemType.bottomFiller;
@@ -519,8 +538,7 @@ public class NewTransactionModel extends ViewModel {
         public void stopObservingCommentVisible(Observer<Boolean> observer) {
             commentVisible.removeObserver(observer);
         }
-        public void observeComment(NewTransactionActivity activity,
-                                          Observer<String> observer) {
+        public void observeComment(NewTransactionActivity activity, Observer<String> observer) {
             comment.observe(activity, observer);
         }
         public void stopObservingComment(Observer<String> observer) {
@@ -530,5 +548,20 @@ public class NewTransactionModel extends ViewModel {
             getAccount().setComment(comment);
             this.comment.postValue(comment);
         }
+        public Currency getCurrency() {
+            return this.currency.getValue();
+        }
+        public void setCurrency(Currency currency) {
+            getAccount().setCurrency((currency != null && !currency.getName()
+                                                                   .isEmpty()) ? currency.getName()
+                                                                               : null);
+            this.currency.setValue(currency);
+        }
+        public void observeCurrency(NewTransactionActivity activity, Observer<Currency> observer) {
+            currency.observe(activity, observer);
+        }
+        public void stopObservingCurrency(Observer<Currency> observer) {
+            currency.removeObserver(observer);
+        }
     }
 }