]> git.ktnx.net Git - mobile-ledger.git/commitdiff
model: adjust items' positions when an item is removed
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 8 Feb 2021 06:05:54 +0000 (06:05 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 18 Feb 2021 07:36:49 +0000 (07:36 +0000)
app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java

index 8357678ab18167954f467d14e78406d3d57cac64..5d3d743189ed1ed0916915fab9a6fdec1b16454e 100644 (file)
@@ -316,8 +316,12 @@ public class TemplateDetailsViewModel extends ViewModel {
         items.setValue(newList);
     }
     public void removeItem(int position) {
-        ArrayList<TemplateDetailsItem> newList = new ArrayList<>(items.getValue());
+        Logger.debug("tmpl", "Removing item at position " + position);
+        ArrayList<TemplateDetailsItem> 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