From: Damyan Ivanov Date: Sun, 31 Mar 2024 07:17:32 +0000 (+0300) Subject: add shortcut method for casting X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=e687d63b107a215ba3b28e7028b9235cdf645bc0;p=mobile-ledger.git add shortcut method for casting and drop the one accessing the underlying account object --- diff --git a/app/src/main/java/net/ktnx/mobileledger/model/AccountListItem.java b/app/src/main/java/net/ktnx/mobileledger/model/AccountListItem.java index dfd3d982..1efe1962 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/AccountListItem.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/AccountListItem.java @@ -34,12 +34,19 @@ public abstract class AccountListItem { else throw new RuntimeException("Unsupported sub-class " + this); } - @NotNull - public LedgerAccount getAccount() { - if (this instanceof Account) - return ((Account) this).account; - - throw new IllegalStateException(String.format("Item type is not Account, but %s", this)); + public boolean isAccount() { + return this instanceof Account; + } + public Account toAccount() { + assert isAccount(); + return ((Account) this); + } + public boolean isHeader() { + return this instanceof Header; + } + public Header toHeader() { + assert isHeader(); + return ((Header) this); } public enum Type {ACCOUNT, HEADER} @@ -59,6 +66,10 @@ public abstract class AccountListItem { ((Account) other).account.getAmountsString() .equals(account.getAmountsString()); } + @NotNull + public LedgerAccount getAccount() { + return account; + } } public static class Header extends AccountListItem { diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java index 329109fd..dfa6b5c5 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java @@ -38,6 +38,7 @@ import java.util.Locale; public class MainModel extends ViewModel { public final MutableLiveData foundTransactionItemIndex = new MutableLiveData<>(null); private final MutableLiveData updatingFlag = new MutableLiveData<>(false); + private final MutableLiveData showZeroBalanceAccounts = new MutableLiveData<>(true); private final MutableLiveData accountFilter = new MutableLiveData<>(null); private final MutableLiveData> displayedTransactions = new MutableLiveData<>(new ArrayList<>()); @@ -66,6 +67,7 @@ public class MainModel extends ViewModel { public void setFirstTransactionDate(SimpleDate earliestDate) { this.firstTransactionDate = earliestDate; } + public MutableLiveData getShowZeroBalanceAccounts() {return showZeroBalanceAccounts;} public MutableLiveData getAccountFilter() { return accountFilter; } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java index d7da335d..88970641 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java @@ -66,8 +66,10 @@ public class AccountSummaryAdapter extends RecyclerView.Adapter payloads) { - LedgerAccount acc = item.getAccount(); + LedgerAccount acc = item.toAccount() + .getAccount(); Change changes = new Change(); if (payloads != null) {