]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java
LedgerAccount: fix NPE in getAmountCount() when there are no amounts
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / model / LedgerAccount.java
index c2ad2c2f63f460e5988fcfed3509b24134e72de1..256be6f082f7ee936f94943efde6782cf82386c3 100644 (file)
@@ -36,6 +36,7 @@ public class LedgerAccount {
     private boolean expanded;
     private List<LedgerAmount> amounts;
     private boolean hasSubAccounts;
+    private boolean amountsExpanded;
 
     public LedgerAccount(String name) {
         this.setName(name);
@@ -68,9 +69,9 @@ public class LedgerAccount {
 
         if (level == 0) return true;
 
-        return isVisible(Data.accounts.get());
+        return isVisible(Data.accounts);
     }
-    public boolean isVisible(ArrayList<LedgerAccount> list) {
+    public boolean isVisible(List<LedgerAccount> list) {
         for (LedgerAccount acc : list) {
             if (acc.isParentOf(this)) {
                 if (!acc.isExpanded()) return false;
@@ -118,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 "";
 
@@ -131,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;
     }
@@ -175,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; }
+
 }