X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionModel.java;h=0801eb2ecbb4769ac5e740395d823a460ad84d04;hb=c8a46620566a9027fe620cb16cf1aefa708085a3;hp=9017973998da8c39efaf91b110d640de1b22decf;hpb=a08a6e0d8f07a3d709aa4efa0cce5d8a444a2dfe;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 90179739..0801eb2e 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 @@ -34,6 +34,7 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collections; import java.util.Date; import java.util.GregorianCalendar; import java.util.List; @@ -53,6 +54,21 @@ public class NewTransactionModel extends ViewModel { private final MutableLiveData isSubmittable = new MutableLiveData<>(false); private final MutableLiveData focusedItem = new MutableLiveData<>(0); private final MutableLiveData accountCount = new MutableLiveData<>(0); + private final MutableLiveData simulateSave = new MutableLiveData<>(false); + public boolean getSimulateSave() { + return simulateSave.getValue(); + } + public void setSimulateSave(boolean simulateSave) { + this.simulateSave.setValue(simulateSave); + } + public void toggleSimulateSave() { + simulateSave.setValue(!simulateSave.getValue()); + } + public void observeSimulateSave(@NonNull @NotNull androidx.lifecycle.LifecycleOwner owner, + @NonNull + androidx.lifecycle.Observer observer) { + this.simulateSave.observe(owner, observer); + } public int getAccountCount() { return items.size(); } @@ -283,6 +299,9 @@ public class NewTransactionModel extends ViewModel { public void noteFocusIsOnAmount(int position) { getItem(position).setFocusIsOnAmount(true); } + public void swapItems(int one, int two) { + Collections.swap(items, one-1, two-1); + } enum ItemType {generalData, transactionRow, bottomFiller} //========================================================================================== @@ -295,9 +314,6 @@ public class NewTransactionModel extends ViewModel { private MutableLiveData amountHint = new MutableLiveData<>(null); private NewTransactionModel model; private MutableLiveData editable = new MutableLiveData<>(true); - public boolean focusIsOnAmount() { - return focusIsOnAmount; - } private boolean focusIsOnAmount = false; public Item(NewTransactionModel model) { this.model = model; @@ -317,6 +333,9 @@ public class NewTransactionModel extends ViewModel { this.account = account; this.editable.setValue(true); } + public boolean focusIsOnAmount() { + return focusIsOnAmount; + } public NewTransactionModel getModel() { return model; } @@ -378,6 +397,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);