X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionModel.java;h=cad07c0def34ee0ea3acb810775aa98a81c4f270;hp=bd2c640fd0ddfaa7b477f1287e6875c9f306b3e1;hb=6d8645bc5ffd9ad56124ddc21b2477c687c15ff7;hpb=7ae5407090d9ffe2026775ba9e569014f879b54d diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java index bd2c640f..cad07c0d 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java @@ -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 focusedItem = new MutableLiveData<>(0); private final MutableLiveData accountCount = new MutableLiveData<>(0); private final MutableLiveData simulateSave = new MutableLiveData<>(false); + final MutableLiveData showCurrency = new MutableLiveData<>(false); public boolean getSimulateSave() { return simulateSave.getValue(); } @@ -298,7 +300,27 @@ public class NewTransactionModel extends ViewModel { getItem(position).setFocusedElement(element); } public void swapItems(int one, int two) { - Collections.swap(items, one-1, two-1); + Collections.swap(items, one - 1, two - 1); + } + public void toggleComment(int position) { + final MutableLiveData 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} @@ -315,6 +337,9 @@ public class NewTransactionModel extends ViewModel { private NewTransactionModel model; private MutableLiveData editable = new MutableLiveData<>(true); private FocusedElement focusedElement = FocusedElement.Account; + private MutableLiveData comment = new MutableLiveData<>(null); + private MutableLiveData commentVisible = new MutableLiveData<>(false); + private MutableLiveData currency = new MutableLiveData<>(null); public Item(NewTransactionModel model) { this.model = model; type = ItemType.bottomFiller; @@ -506,5 +531,37 @@ public class NewTransactionModel extends ViewModel { public void stopObservingEditableFlag(Observer observer) { editable.removeObserver(observer); } + public void observeCommentVisible(NewTransactionActivity activity, + Observer observer) { + commentVisible.observe(activity, observer); + } + public void stopObservingCommentVisible(Observer observer) { + commentVisible.removeObserver(observer); + } + public void observeComment(NewTransactionActivity activity, Observer observer) { + comment.observe(activity, observer); + } + public void stopObservingComment(Observer observer) { + comment.removeObserver(observer); + } + public void setComment(String comment) { + 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 observer) { + currency.observe(activity, observer); + } + public void stopObservingCurrency(Observer observer) { + currency.removeObserver(observer); + } } }