From: Damyan Ivanov Date: Mon, 8 Feb 2021 05:56:11 +0000 (+0000) Subject: template details model: method for creating a copy of the data list X-Git-Tag: v0.17.0~99 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=128cb44c82144c3bb2fcba8afba5636c0196b61d;p=mobile-ledger.git template details model: method for creating a copy of the data list this is a clone-like list, that shares no common objects with the original needed so that any changes to it do not touch the original items and differ discovers the changes --- 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 7f983807..bf1dc35a 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 @@ -184,6 +184,21 @@ public class TemplateDetailsViewModel extends ViewModel { taDAO.finishSave(mPatternId); }); } + private ArrayList copyItems() { + List oldList = items.getValue(); + ArrayList result = new ArrayList<>(oldList.size()); + + for (TemplateDetailsItem item : oldList) { + if (item instanceof TemplateDetailsItem.Header) + result.add(new TemplateDetailsItem.Header(item.asHeaderItem())); + else if (item instanceof TemplateDetailsItem.AccountRow) + result.add(new TemplateDetailsItem.AccountRow(item.asAccountRowItem())); + else + throw new RuntimeException("Unexpected item " + item); + } + + return result; + } public void moveItem(int sourcePos, int targetPos) { ArrayList newList = new ArrayList<>(items.getValue()); TemplateDetailsItem item = newList.remove(sourcePos);