X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FLedgerAccount.java;h=256be6f082f7ee936f94943efde6782cf82386c3;hp=f632bba94311d97485e6f98584776c9176095bd6;hb=2a0d9c329ac8163eee557dd72475d8f85ec372da;hpb=c040f83305fb25dfe9a7c088683926b7d101c373 diff --git a/app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java b/app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java index f632bba9..256be6f0 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java @@ -23,6 +23,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; public class LedgerAccount { static Pattern reHigherAccount = Pattern.compile("^[^:]+:"); @@ -35,6 +36,7 @@ public class LedgerAccount { private boolean expanded; private List amounts; private boolean hasSubAccounts; + private boolean amountsExpanded; public LedgerAccount(String name) { this.setName(name); @@ -48,6 +50,17 @@ public class LedgerAccount { this.amounts = new ArrayList(); this.addAmount(amount); } + @Override + public int hashCode() { + return name.hashCode(); + } + @Override + public boolean equals(@Nullable Object obj) { + if (obj == null) return false; + + return obj.getClass().equals(this.getClass()) && + name.equals(((LedgerAccount) obj).getName()); + } // an account is visible if: // - it is starred (not hidden by a star) // - and it has an expanded parent or is a top account @@ -56,9 +69,9 @@ public class LedgerAccount { if (level == 0) return true; - return isVisible(Data.accounts.get()); + return isVisible(Data.accounts); } - public boolean isVisible(ArrayList list) { + public boolean isVisible(List list) { for (LedgerAccount acc : list) { if (acc.isParentOf(this)) { if (!acc.isExpanded()) return false; @@ -106,7 +119,7 @@ public class LedgerAccount { public void addAmount(float amount) { this.addAmount(amount, null); } - + public int getAmountCount() { return (amounts != null) ? amounts.size() : 0; } public String getAmountsString() { if ((amounts == null) || amounts.isEmpty()) return ""; @@ -119,7 +132,21 @@ public class LedgerAccount { return builder.toString(); } + public String getAmountsString(int limit) { + if ((amounts == null) || amounts.isEmpty()) return ""; + int included = 0; + StringBuilder builder = new StringBuilder(); + for (LedgerAmount amount : amounts) { + String amt = amount.toString(); + if (builder.length() > 0) builder.append('\n'); + builder.append(amt); + included++; + if (included == limit) break; + } + + return builder.toString(); + } public int getLevel() { return level; } @@ -163,4 +190,8 @@ public class LedgerAccount { public void removeAmounts() { if (amounts != null) amounts.clear(); } + public boolean amountsExpanded() { return amountsExpanded; } + public void setAmountsExpanded(boolean flag) { amountsExpanded = flag; } + public void toggleAmountsExpanded() { amountsExpanded = !amountsExpanded; } + }