From e6c38110eaac249a03c397ff2f4707dbf23f92f9 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Fri, 23 Apr 2021 22:25:58 +0300 Subject: [PATCH] TransactionAccumulator needs not keep a reference to the main model --- .../mobileledger/async/TransactionAccumulator.java | 11 +++-------- .../mobileledger/async/UpdateTransactionsTask.java | 5 +++-- .../java/net/ktnx/mobileledger/ui/MainModel.java | 12 +++++++----- 3 files changed, 13 insertions(+), 15 deletions(-) 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"); } } } -- 2.39.5