X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fnew_transaction%2FNewTransactionModel.java;h=2e9027154ae805014d6e878336434faaa8c6a7e0;hp=060046c43ce4f87fb3b7fb87885356b0e9b501ef;hb=cf08359f12073863a51b69d03b614df300c42c43;hpb=5893f6b43cfa856588eb32df4bd2365e96e702db 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 060046c4..2e902715 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 @@ -738,8 +738,9 @@ public class NewTransactionModel extends ViewModel { list = copyList(list); liveListCopied = true; } - Item item = emptyItems.remove(1); - list.remove(item); + // the list is a copy, so the empty item is no longer present + Item itemToRemove = emptyItems.remove(1); + removeItemById(list, itemToRemove.id); listChanged = true; } @@ -752,8 +753,8 @@ public class NewTransactionModel extends ViewModel { list = copyList(list); liveListCopied = true; } - Item item = emptyItems.get(0); - list.remove(item); + // the list is a copy, so the empty item is no longer present + removeItemById(list, emptyItems.get(0).id); listChanged = true; } } @@ -791,6 +792,19 @@ public class NewTransactionModel extends ViewModel { setItemsWithoutSubmittableChecks(list); } } + private void removeItemById(@NotNull List list, int id) { + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { + list.removeIf(item -> item.id == id); + } + else { + for (Item item : list) { + if (item.id == id) { + list.remove(item); + break; + } + } + } + } @SuppressLint("DefaultLocale") private void dumpItemList(@NotNull String msg, @NotNull List list) { Logger.debug("submittable", "== Dump of all items " + msg);