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.model;
20 import androidx.annotation.NonNull;
21 import androidx.annotation.Nullable;
23 import net.ktnx.mobileledger.App;
24 import net.ktnx.mobileledger.utils.SimpleDate;
26 import org.jetbrains.annotations.NotNull;
28 public class TransactionListItem {
29 private final Type type;
30 private SimpleDate date;
31 private boolean monthShown;
32 private LedgerTransaction transaction;
33 private String boldAccountName;
34 public TransactionListItem(@NotNull SimpleDate date, boolean monthShown) {
35 this.type = Type.DELIMITER;
37 this.monthShown = monthShown;
39 public TransactionListItem(@NotNull LedgerTransaction transaction,
40 @Nullable String boldAccountName) {
41 this.type = Type.TRANSACTION;
42 this.transaction = transaction;
43 this.boldAccountName = boldAccountName;
45 public TransactionListItem() {
46 this.type = Type.HEADER;
49 public Type getType() {
53 public SimpleDate getDate() {
56 if (type == Type.HEADER)
57 throw new IllegalStateException("Header item has no date");
58 transaction.loadData(App.getDatabase());
59 return transaction.getDate();
61 public boolean isMonthShown() {
65 public LedgerTransaction getTransaction() {
66 if (type != Type.TRANSACTION)
67 throw new IllegalStateException(
68 String.format("Item type is not %s, but %s", Type.TRANSACTION, type));
72 String getBoldAccountName() {
73 return boldAccountName;
76 TRANSACTION, DELIMITER, HEADER;
77 public static Type valueOf(int i) {
78 if (i == TRANSACTION.ordinal())
80 else if (i == DELIMITER.ordinal())
82 else if (i == HEADER.ordinal())
85 throw new IllegalStateException("Unexpected value: " + i);