]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/async/TransactionAccumulator.java
speculatively update last update date before the transactions are stored
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / async / TransactionAccumulator.java
index 8f57e769174e763abaa2a204776319b08a0acf6e..62b962748b9bab4e3a0deda55e1fe77f2cc34bc9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2020 Damyan Ivanov.
+ * Copyright © 2021 Damyan Ivanov.
  * This file is part of MoLe.
  * MoLe is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
 
 package net.ktnx.mobileledger.async;
 
+import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerTransaction;
 import net.ktnx.mobileledger.model.TransactionListItem;
 import net.ktnx.mobileledger.ui.MainModel;
 import net.ktnx.mobileledger.utils.SimpleDate;
 
 import java.util.ArrayList;
+import java.util.Date;
 
 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 = SimpleDate.today();
+    private SimpleDate lastDate;
     private boolean done;
     public TransactionAccumulator(MainModel model) {
         this.model = model;
+
+        boldAccountName = model.getAccountFilter()
+                               .getValue();
+
+        list.add(new TransactionListItem());    // head item
+    }
+    public void put(LedgerTransaction transaction) {
+        put(transaction, transaction.getDate());
     }
     public void put(LedgerTransaction transaction, SimpleDate date) {
         if (done)
             throw new IllegalStateException("Can't put new items after done()");
+
+        // first item
         if (null == latestDate)
             latestDate = date;
         earliestDate = date;
 
         if (!date.equals(lastDate)) {
+            if (lastDate == null)
+                lastDate = SimpleDate.today();
             boolean showMonth = date.month != lastDate.month || date.year != lastDate.year;
             list.add(new TransactionListItem(date, showMonth));
         }
 
-        list.add(new TransactionListItem(transaction));
+        list.add(new TransactionListItem(transaction, boldAccountName));
 
         lastDate = date;
     }
     public void done() {
         done = true;
         model.setDisplayedTransactions(list);
+        Data.lastUpdateDate.postValue(new Date());
         model.setFirstTransactionDate(earliestDate);
         model.setLastTransactionDate(latestDate);
     }