From e543f465bd9c7f340c4a572287ecf0a31caccee9 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Mon, 8 Feb 2021 06:05:54 +0000 Subject: [PATCH] model: adjust items' positions when an item is removed --- .../mobileledger/ui/templates/TemplateDetailsViewModel.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 -- 2.39.5