From: Damyan Ivanov Date: Fri, 23 Apr 2021 19:25:58 +0000 (+0300) Subject: TransactionAccumulator needs not keep a reference to the main model X-Git-Tag: v0.18.0~38 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=e6c38110eaac249a03c397ff2f4707dbf23f92f9;p=mobile-ledger.git TransactionAccumulator needs not keep a reference to the main model --- diff --git a/app/src/main/java/net/ktnx/mobileledger/async/TransactionAccumulator.java b/app/src/main/java/net/ktnx/mobileledger/async/TransactionAccumulator.java index 46b8426a..bdf4b7b1 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/TransactionAccumulator.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/TransactionAccumulator.java @@ -26,16 +26,12 @@ import java.util.ArrayList; public class TransactionAccumulator { private final ArrayList list = new ArrayList<>(); - private final MainModel model; private final String boldAccountName; private SimpleDate earliestDate, latestDate; private SimpleDate lastDate; private boolean done; - public TransactionAccumulator(MainModel model) { - this.model = model; - - boldAccountName = model.getAccountFilter() - .getValue(); + public TransactionAccumulator(String boldAccountName) { + this.boldAccountName = boldAccountName; list.add(new TransactionListItem()); // head item } @@ -62,8 +58,7 @@ public class TransactionAccumulator { lastDate = date; } - public void done() { - done = true; + public void publishResults(MainModel model) { model.setDisplayedTransactions(list); model.setFirstTransactionDate(earliestDate); model.setLastTransactionDate(latestDate); diff --git a/app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java b/app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java index 38db6b17..785ec144 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java @@ -60,7 +60,7 @@ public class UpdateTransactionsTask extends AsyncTask { .getAllWithAccountsFilteredSync(profileId, accFilter); } - TransactionAccumulator accumulator = new TransactionAccumulator(model); + TransactionAccumulator accumulator = new TransactionAccumulator(accFilter); for (TransactionWithAccounts tr : transactions) { if (isCancelled()) @@ -69,7 +69,8 @@ public class UpdateTransactionsTask extends AsyncTask { accumulator.put(new LedgerTransaction(tr)); } - accumulator.done(); + accumulator.publishResults(model); + debug("UTT", "transaction list value updated"); return null; diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java index 039e24df..a620255d 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java @@ -133,7 +133,7 @@ public class MainModel extends ViewModel { String accNameFilter = model.getAccountFilter() .getValue(); - TransactionAccumulator acc = new TransactionAccumulator(model); + TransactionAccumulator acc = new TransactionAccumulator(accNameFilter); for (LedgerTransaction tr : list) { if (isInterrupted()) { return; @@ -143,10 +143,12 @@ public class MainModel extends ViewModel { acc.put(tr, tr.getDate()); } } - if (!isInterrupted()) { - acc.done(); - } - Logger.debug("dFilter", "left synchronized block"); + + if (isInterrupted()) + return; + + acc.publishResults(model); + Logger.debug("dFilter", "transaction list updated"); } } }