]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java
handle transaction comment UI changes
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / NewTransactionModel.java
index 062495c1537a0a169fe7febc7015a44292b6529b..7fd177683f461db1be543200007585a74dec4efb 100644 (file)
@@ -59,6 +59,10 @@ public class NewTransactionModel extends ViewModel {
             profile -> showCurrency.postValue(profile.getShowCommodityByDefault());
     private final AtomicInteger busyCounter = new AtomicInteger(0);
     private final MutableLiveData<Boolean> busyFlag = new MutableLiveData<>(false);
+    final MutableLiveData<Boolean> showComments = new MutableLiveData<>(false);
+    void observeShowComments(LifecycleOwner owner, Observer<? super Boolean> observer) {
+        showComments.observe(owner, observer);
+    }
     void observeBusyFlag(@NonNull LifecycleOwner owner, Observer<? super Boolean> observer) {
         busyFlag.observe(owner, observer);
     }
@@ -89,12 +93,16 @@ public class NewTransactionModel extends ViewModel {
     public String getDescription() {
         return header.description.getValue();
     }
+    public String getComment() {
+        return header.comment.getValue();
+    }
     LiveData<Boolean> isSubmittable() {
         return this.isSubmittable;
     }
     void reset() {
         header.date.setValue(null);
         header.description.setValue(null);
+        header.comment.setValue(null);
         items.clear();
         items.add(new Item(this, new LedgerTransactionAccount("")));
         items.add(new Item(this, new LedgerTransactionAccount("")));
@@ -207,9 +215,12 @@ public class NewTransactionModel extends ViewModel {
     public boolean getBusyFlag() {
         return busyFlag.getValue();
     }
+    public void toggleShowComments() {
+        showComments.setValue(!showComments.getValue());
+    }
     enum ItemType {generalData, transactionRow, bottomFiller}
 
-    enum FocusedElement {Account, Comment, Amount}
+    enum FocusedElement {Account, Comment, Amount, Description, TransactionComment}
 
 
     //==========================================================================================
@@ -379,6 +390,23 @@ public class NewTransactionModel extends ViewModel {
                 @NonNull androidx.lifecycle.Observer<? super String> observer) {
             this.description.removeObserver(observer);
         }
+        public String getTransactionComment() {
+            ensureType(ItemType.generalData);
+            return comment.getValue();
+        }
+        public void setTransactionComment(String transactionComment) {
+            ensureType(ItemType.generalData);
+            this.comment.setValue(transactionComment);
+        }
+        void observeTransactionComment(@NonNull @NotNull LifecycleOwner owner,
+                                       @NonNull Observer<? super String> observer) {
+            ensureType(ItemType.generalData);
+            this.comment.observe(owner, observer);
+        }
+        void stopObservingTransactionComment(@NonNull Observer<? super String> observer) {
+            ensureType(ItemType.generalData);
+            this.comment.removeObserver(observer);
+        }
         public LedgerTransactionAccount getAccount() {
             ensureType(ItemType.transactionRow);
             return account;