fix populating live account list when updating from JSON
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 14 Mar 2019 21:26:41 +0000 (23:26 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 15 Mar 2019 02:57:42 +0000 (04:57 +0200)
app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java

index c4f55d0..e81a71c 100644 (file)
@@ -396,14 +396,17 @@ public class RetrieveTransactionsTask
                         ParsedLedgerAccount parsedAccount = parser.nextAccount();
                         if (parsedAccount == null) break;
 
-                        LedgerAccount acc = new LedgerAccount(parsedAccount.getAname());
+                        LedgerAccount acc = profile.tryLoadAccount(db, parsedAccount.getAname());
+                        if (acc == null) acc = new LedgerAccount(parsedAccount.getAname());
+                        else acc.removeAmounts();
+
                         profile.storeAccount(db, acc);
                         for (ParsedBalance b : parsedAccount.getAebalance()) {
                             profile.storeAccountValue(db, acc.getName(), b.getAcommodity(),
                                     b.getAquantity().asFloat());
                         }
 
-                        accountList.add(acc);
+                        if (acc.isVisible(accountList)) accountList.add(acc);
                     }
                     throwIfCancelled();
 
index 0751d10..f632bba 100644 (file)
@@ -161,6 +161,6 @@ public class LedgerAccount {
         expanded = !expanded;
     }
     public void removeAmounts() {
-        amounts.clear();
+        if (amounts != null) amounts.clear();
     }
 }