From: Damyan Ivanov Date: Thu, 11 Mar 2021 06:52:11 +0000 (+0200) Subject: smooth items replacement when old transaction is loaded and upon reset X-Git-Tag: v0.17.0~3 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=4123c82ce24688f2a91da9706ebe77135f3185ea;p=mobile-ledger.git smooth items replacement when old transaction is loaded and upon reset --- 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..9539476d 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); } @@ -865,7 +884,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;