]> git.ktnx.net Git - mobile-ledger.git/commitdiff
TransactionAccumulator needs not keep a reference to the main model
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 23 Apr 2021 19:25:58 +0000 (22:25 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 25 Apr 2021 17:07:58 +0000 (17:07 +0000)
app/src/main/java/net/ktnx/mobileledger/async/TransactionAccumulator.java
app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java

index 46b8426abbae7aaf1b16b91fd975ed87af52640b..bdf4b7b1e712c04401a95b7fdc7278183049c659 100644 (file)
@@ -26,16 +26,12 @@ import java.util.ArrayList;
 
 public class TransactionAccumulator {
     private final ArrayList<TransactionListItem> 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);
index 38db6b17f8c7b30648a92d980f23626f4fbe222e..785ec1447eac017e3303a192f2e9eafe7269504a 100644 (file)
@@ -60,7 +60,7 @@ public class UpdateTransactionsTask extends AsyncTask<MainModel, Void, String> {
                                  .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<MainModel, Void, String> {
                 accumulator.put(new LedgerTransaction(tr));
             }
 
-            accumulator.done();
+            accumulator.publishResults(model);
+
             debug("UTT", "transaction list value updated");
 
             return null;
index 039e24df6c45ed9495b09056efad4661debee203..a620255dff7fcea330ce35dffe43e0f2c21ada52 100644 (file)
@@ -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");
         }
     }
 }