@Transaction
@Query("SELECT * FROM templates WHERE id = :id")
- public abstract LiveData<TemplateWithAccounts> getTemplateWithAccounts(Long id);
+ public abstract LiveData<TemplateWithAccounts> getTemplateWithAccounts(@NonNull Long id);
+
+ @Transaction
+ @Query("SELECT * FROM templates WHERE id = :id")
+ public abstract TemplateWithAccounts getTemplateWithAccountsSync(@NonNull Long id);
@Transaction
public void insertSync(TemplateWithAccounts templateWithAccounts) {
}
});
}
+ public void duplicateTemplateWitAccounts(@NonNull Long id, @Nullable
+ AsyncResultCallback<TemplateWithAccounts> callback) {
+ AsyncTask.execute(() -> {
+ TemplateWithAccounts src = getTemplateWithAccountsSync(id);
+ TemplateWithAccounts dup = src.createDuplicate();
+ dup.header.setName(dup.header.getName());
+ dup.header.setId(insertSync(dup.header));
+ TemplateAccountDAO accDao = DB.get()
+ .getTemplateAccountDAO();
+ for (TemplateAccount dupAcc : dup.accounts) {
+ dupAcc.setTemplateId(dup.header.getId());
+ dupAcc.setId(accDao.insertSync(dupAcc));
+ }
+ if (callback != null)
+ new Handler(Looper.getMainLooper()).post(() -> callback.onResult(dup));
+ });
+ }
}
public void setAccountCommentMatchGroup(Integer accountCommentMatchGroup) {
this.accountCommentMatchGroup = accountCommentMatchGroup;
}
+ public TemplateAccount createDuplicate() {
+ TemplateAccount dup = new TemplateAccount(this);
+ dup.id = null;
+ dup.templateId = null;
+
+ return dup;
+ }
}
Misc.equalIntegers(dateYear, o.dateYear) &&
Misc.equalIntegers(dateYearMatchGroup, o.dateYearMatchGroup);
}
+ public TemplateHeader createDuplicate() {
+ TemplateHeader dup = new TemplateHeader(this);
+ dup.id = null;
+
+ return dup;
+ }
}
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());
+ }
+
+ return result;
+ }
}