X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fdb%2FTemplateWithAccounts.java;h=a96236e6fb0554f00e907c09e34873809398f00d;hb=97fb6ae61fcfd39435bc3280ac6f9319f7f6cb10;hp=a40ecae924417214d543e880421fb1e3d2b92e3e;hpb=3ab99e1679326277d6ba7f8ce28f17a96dfa07aa;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/db/TemplateWithAccounts.java b/app/src/main/java/net/ktnx/mobileledger/db/TemplateWithAccounts.java index a40ecae9..a96236e6 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/TemplateWithAccounts.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/TemplateWithAccounts.java @@ -20,6 +20,7 @@ package net.ktnx.mobileledger.db; import androidx.room.Embedded; import androidx.room.Relation; +import java.util.ArrayList; import java.util.List; public class TemplateWithAccounts { @@ -28,7 +29,27 @@ public class TemplateWithAccounts { @Relation(parentColumn = "id", entityColumn = "template_id") public List accounts; + public static TemplateWithAccounts from(TemplateWithAccounts o) { + TemplateWithAccounts result = new TemplateWithAccounts(); + result.header = new TemplateHeader(o.header); + result.accounts = new ArrayList<>(); + for (TemplateAccount acc : o.accounts) { + result.accounts.add(new TemplateAccount(acc)); + } + + return result; + } public Long getId() { return header.getId(); } + public TemplateWithAccounts createDuplicate() { + TemplateWithAccounts result = new TemplateWithAccounts(); + result.header = header.createDuplicate(); + result.accounts = new ArrayList<>(); + for (TemplateAccount acc : accounts) { + result.accounts.add(acc.createDuplicate(result.header)); + } + + return result; + } }