2 * Copyright © 2021 Damyan Ivanov.
3 * This file is part of MoLe.
4 * MoLe is free software: you can distribute it and/or modify it
5 * under the term of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your opinion), any later version.
9 * MoLe is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License terms for details.
14 * You should have received a copy of the GNU General Public License
15 * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
18 package net.ktnx.mobileledger.async;
20 import net.ktnx.mobileledger.model.LedgerTransaction;
21 import net.ktnx.mobileledger.model.TransactionListItem;
22 import net.ktnx.mobileledger.ui.MainModel;
23 import net.ktnx.mobileledger.utils.SimpleDate;
25 import java.util.ArrayList;
27 public class TransactionAccumulator {
28 private final ArrayList<TransactionListItem> list = new ArrayList<>();
29 private final String boldAccountName;
30 private SimpleDate earliestDate, latestDate;
31 private SimpleDate lastDate;
32 private int transactionCount = 0;
33 public TransactionAccumulator(String boldAccountName) {
34 this.boldAccountName = boldAccountName;
36 list.add(new TransactionListItem()); // head item
38 public void put(LedgerTransaction transaction) {
39 put(transaction, transaction.getDate());
41 public void put(LedgerTransaction transaction, SimpleDate date) {
45 if (null == latestDate)
49 if (!date.equals(lastDate)) {
51 lastDate = SimpleDate.today();
52 boolean showMonth = date.month != lastDate.month || date.year != lastDate.year;
53 list.add(new TransactionListItem(date, showMonth));
56 list.add(new TransactionListItem(transaction, boldAccountName));
60 public void publishResults(MainModel model) {
61 model.setDisplayedTransactions(list, transactionCount);
62 model.setFirstTransactionDate(earliestDate);
63 model.setLastTransactionDate(latestDate);