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=39b9ac8ad60f09dd3b44eae84995870f9158ccf1;hp=4c200fc592af0ea2610c890d2f54b53d67d822fd;hb=54e204dbd812a622745677849e1dec9210d1d926;hpb=ba6513e75e8cfc577f333fb38c0e6c597f9c8875 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 4c200fc5..39b9ac8a 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 @@ -51,7 +51,7 @@ public class NewTransactionModel extends ViewModel { private final Item trailer = new Item(this); private final ArrayList items = new ArrayList<>(); private final MutableLiveData isSubmittable = new MutableLiveData<>(false); - private final MutableLiveData focusedItem = new MutableLiveData<>(null); + private final MutableLiveData focusedItem = new MutableLiveData<>(0); private final MutableLiveData accountCount = new MutableLiveData<>(0); public int getAccountCount() { return items.size(); @@ -90,6 +90,7 @@ public class NewTransactionModel extends ViewModel { @NonNull androidx.lifecycle.Observer 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 amountHint = new MutableLiveData<>(null); private NewTransactionModel model; private MutableLiveData 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; } @@ -361,6 +378,13 @@ public class NewTransactionModel extends ViewModel { this.date.setValue(date); } public void setDate(String text) { + if ((text == null) || text.trim() + .isEmpty()) + { + setDate((Date) null); + return; + } + int year, month, day; final Calendar c = GregorianCalendar.getInstance(); Matcher m = reYMD.matcher(text); @@ -460,5 +484,8 @@ public class NewTransactionModel extends ViewModel { public void stopObservingEditableFlag(Observer observer) { editable.removeObserver(observer); } + public void setFocusIsOnAmount(boolean flag) { + focusIsOnAmount = flag; + } } }