]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
fix populating live account list when updating from JSON
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / async / RetrieveTransactionsTask.java
index dfb1f74548a891e04a6c802c26b376be356aef0d..e81a71c2c87b098cb6bcaa072790f191a3493e0f 100644 (file)
@@ -170,9 +170,9 @@ public class RetrieveTransactionsTask
                                     L(String.format("found account: %s", acct_name));
 
                                     lastAccount = profile.tryLoadAccount(db, acct_name);
-                                    if (lastAccount == null) {
+                                    if (lastAccount == null)
                                         lastAccount = new LedgerAccount(acct_name);
-                                    }
+                                    else lastAccount.removeAmounts();
                                     profile.storeAccount(db, lastAccount);
 
                                     // make sure the parent account(s) are present,
@@ -190,15 +190,16 @@ public class RetrieveTransactionsTask
                                             String aName = toAppend.pop();
                                             LedgerAccount acc = new LedgerAccount(aName);
                                             acc.setHiddenByStar(lastAccount.isHiddenByStar());
-                                            if (!onlyStarred || !acc.isHiddenByStar())
-                                                accountList.add(acc);
+                                            if ((!onlyStarred || !acc.isHiddenByStar()) &&
+                                                acc.isVisible(accountList)) accountList.add(acc);
                                             L(String.format("gap-filling with %s", aName));
                                             accountNames.put(aName, null);
                                             profile.storeAccount(db, acc);
                                         }
                                     }
 
-                                    if (!onlyStarred || !lastAccount.isHiddenByStar())
+                                    if ((!onlyStarred || !lastAccount.isHiddenByStar()) &&
+                                        lastAccount.isVisible(accountList))
                                         accountList.add(lastAccount);
                                     accountNames.put(acct_name, null);
 
@@ -395,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();