X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fnew_transaction%2FNewTransactionModel.java;h=fdcab48788b94f6336f41254298f92c02748e4c6;hb=2de3d8a8c96e78f4ab89880be9fab05735acc910;hp=36b457ff4bf76bc1c0973a1db085196c2f3ee4e3;hpb=f973784f579d42988174acf0b24593aa23180fa6;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java index 36b457ff..fdcab487 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java @@ -92,6 +92,24 @@ public class NewTransactionModel extends ViewModel { checkTransactionSubmittable(newList); setItemsWithoutSubmittableChecks(newList); } + private void replaceItems(@NonNull List newList) { + renumberItems(); + + setItems(newList); + } + /** + * make old items replaceable in-place. makes the new values visually blend in + */ + private void renumberItems() { + final List list = items.getValue(); + if (list == null) { + return; + } + + int id = 0; + for (Item item : list) + item.id = id++; + } private void setItemsWithoutSubmittableChecks(@NonNull List list) { final int cnt = list.size(); for (int i = 1; i < cnt - 1; i++) { @@ -175,6 +193,7 @@ public class NewTransactionModel extends ViewModel { list.add(new TransactionAccount("")); list.add(new TransactionAccount("")); noteFocusChanged(0, FocusedElement.Description); + renumberItems(); isSubmittable.setValue(false); setItemsWithoutSubmittableChecks(list); } @@ -241,6 +260,7 @@ public class NewTransactionModel extends ViewModel { if (Misc.emptyIsNull(transactionComment) != null) head.setComment(transactionComment); + Item.resetIdDispenser(); List newItems = new ArrayList<>(); newItems.add(head); @@ -280,7 +300,7 @@ public class NewTransactionModel extends ViewModel { newItems.add(accRow); } - new Handler(Looper.getMainLooper()).post(() -> setItems(newItems)); + new Handler(Looper.getMainLooper()).post(() -> replaceItems(newItems)); }); } private int extractIntFromMatches(MatchResult m, Integer group, Integer literal) { @@ -441,15 +461,15 @@ public class NewTransactionModel extends ViewModel { return tr; } - void loadTransactionIntoModel(String profileUUID, int transactionId) { + void loadTransactionIntoModel(long profileId, int transactionId) { List newList = new ArrayList<>(); Item.resetIdDispenser(); LedgerTransaction tr; - MobileLedgerProfile profile = Data.getProfile(profileUUID); + MobileLedgerProfile profile = Data.getProfile(profileId); if (profile == null) throw new RuntimeException(String.format( "Unable to find profile %s, which is supposed to contain transaction %d", - profileUUID, transactionId)); + profileId, transactionId)); tr = profile.loadTransaction(transactionId); TransactionHead head = new TransactionHead(tr.getDescription()); @@ -865,7 +885,7 @@ public class NewTransactionModel extends ViewModel { static abstract class Item { private static int idDispenser = 0; - protected final int id; + protected int id; private Item() { if (this instanceof TransactionHead) id = 0; @@ -1011,7 +1031,7 @@ public class NewTransactionModel extends ViewModel { return ItemType.generalData; } public LedgerTransaction asLedgerTransaction() { - return new LedgerTransaction(null, date, description, Data.getProfile()); + return new LedgerTransaction(0, date, description, Data.getProfile()); } public boolean equalContents(TransactionHead other) { if (other == null)