X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionModel.java;h=7c49bf1b4b08a0e49ad9b166ed147367ea7ab894;hb=040d5ba3aaa78a295a6c4a29500a234d3188ad6b;hp=5bc327a78329ffcb6c2ca3b0570d0de13d581b8f;hpb=44444c406faf8cab3542b05df60d2c837cdc4ca2;p=mobile-ledger.git 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 5bc327a7..7c49bf1b 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(); } @@ -151,6 +153,8 @@ public class NewTransactionModel extends ViewModel { 3a) there must be exactly one empty amount (with account) 4) empty accounts with empty amounts are ignored 5) a row with an empty account name or empty amount is guaranteed to exist + 6) at least two rows need to be present in the ledger + */ @SuppressLint("DefaultLocale") public void checkTransactionSubmittable(NewTransactionItemsAdapter adapter) { @@ -256,6 +260,9 @@ public class NewTransactionModel extends ViewModel { adapter.addRow(); } + // 6) at least two rows need to be present in the ledger + while (this.items.size() < 2) adapter.addRow(); + debug("submittable", submittable ? "YES" : "NO"); isSubmittable.setValue(submittable); @@ -317,6 +324,9 @@ public class NewTransactionModel extends ViewModel { items.add(itemCount - 1, acc); } } + public void toggleCurrencyVisible() { + showCurrency.setValue(!showCurrency.getValue()); + } enum ItemType {generalData, transactionRow, bottomFiller} //========================================================================================== @@ -334,6 +344,7 @@ public class NewTransactionModel extends ViewModel { 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; @@ -532,8 +543,7 @@ public class NewTransactionModel extends ViewModel { public void stopObservingCommentVisible(Observer observer) { commentVisible.removeObserver(observer); } - public void observeComment(NewTransactionActivity activity, - Observer observer) { + public void observeComment(NewTransactionActivity activity, Observer observer) { comment.observe(activity, observer); } public void stopObservingComment(Observer observer) { @@ -543,5 +553,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 observer) { + currency.observe(activity, observer); + } + public void stopObservingCurrency(Observer observer) { + currency.removeObserver(observer); + } } }