+ public abstract LiveData<TemplateWithAccounts> getTemplateWithAccounts(Long id);
+
+ @Transaction
+ public void insertSync(TemplateWithAccounts templateWithAccounts) {
+ long template_id = insertSync(templateWithAccounts.header);
+ for (TemplateAccount acc : templateWithAccounts.accounts) {
+ acc.setTemplateId(template_id);
+ DB.get()
+ .getTemplateAccountDAO()
+ .insertSync(acc);
+ }
+ }
+
+ public void getTemplateWitAccountsAsync(@NonNull Long id, @NonNull
+ AsyncResultCallback<TemplateWithAccounts> callback) {
+ LiveData<TemplateWithAccounts> resultReceiver = getTemplateWithAccounts(id);
+ resultReceiver.observeForever(new Observer<TemplateWithAccounts>() {
+ @Override
+ public void onChanged(TemplateWithAccounts result) {
+ if (result == null)
+ return;
+
+ resultReceiver.removeObserver(this);
+ callback.onResult(result);
+ }
+ });
+ }
+ public void insertAsync(@NonNull TemplateWithAccounts item, @Nullable Runnable callback) {
+ AsyncTask.execute(() -> {
+ insertSync(item);
+ if (callback != null) {
+ new Handler(Looper.getMainLooper()).post(callback);
+ }
+ });
+ }
+