From: Damyan Ivanov Date: Mon, 8 Feb 2021 06:05:54 +0000 (+0000) Subject: model: adjust items' positions when an item is removed X-Git-Tag: v0.17.0~95 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=e543f465bd9c7f340c4a572287ecf0a31caccee9;p=mobile-ledger.git model: adjust items' positions when an item is removed --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java index 8357678a..5d3d7431 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java @@ -316,8 +316,12 @@ public class TemplateDetailsViewModel extends ViewModel { items.setValue(newList); } public void removeItem(int position) { - ArrayList newList = new ArrayList<>(items.getValue()); + Logger.debug("tmpl", "Removing item at position " + position); + ArrayList newList = copyItems(); newList.remove(position); + for (int i = position; i < newList.size(); i++) + newList.get(i) + .setPosition(i); applyList(newList); } } \ No newline at end of file