X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fasync%2FTransactionAccumulator.java;h=eb8376f0fc91a70176e5ec7e3f30fbc5fdcbfd4d;hb=3a3e22991c6e4666eb5c800bfd49ee7c271b5a32;hp=1b96425681642a25580c13c7a8d2518e035051ae;hpb=8c70bbbbe73f4246f4af217a0d8b81a859a4bba7;p=mobile-ledger.git 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 1b964256..eb8376f0 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/TransactionAccumulator.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/TransactionAccumulator.java @@ -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 @@ -28,21 +28,28 @@ public class TransactionAccumulator { private final ArrayList list = new ArrayList<>(); private final MainModel model; private SimpleDate earliestDate, latestDate; - private SimpleDate lastDate = SimpleDate.today(); + private SimpleDate lastDate; private boolean done; public TransactionAccumulator(MainModel model) { this.model = model; + + 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()"); - if (null == latestDate) { + + // first item + if (null == latestDate) latestDate = date; - list.add(new TransactionListItem(date, SimpleDate.today().month != date.month)); - } 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)); }