int maxTransactionId = Progress.INDETERMINATE;
ArrayList<LedgerAccount> accountList = new ArrayList<>();
HashMap<String, Void> accountNames = new HashMap<>();
- LedgerAccount lastAccount = null;
+ LedgerAccount lastAccount = null, prevAccount = null;
boolean onlyStarred = Data.optShowOnlyStarred.get();
HttpURLConnection http = NetworkUtil.prepareConnection(profile, "journal");
acct_name = acct_name.replace("\"", "");
L(String.format("found account: %s", acct_name));
+ prevAccount = lastAccount;
lastAccount = profile.tryLoadAccount(db, acct_name);
if (lastAccount == null)
lastAccount = new LedgerAccount(acct_name);
- else
- lastAccount.removeAmounts();
+ else lastAccount.removeAmounts();
profile.storeAccount(db, lastAccount);
+ if (prevAccount != null) prevAccount
+ .setHasSubAccounts(prevAccount.isParentOf(lastAccount));
// make sure the parent account(s) are present,
// synthesising them if necessary
String parentName = lastAccount.getParentName();
String aName = toAppend.pop();
LedgerAccount acc = new LedgerAccount(aName);
acc.setHiddenByStar(lastAccount.isHiddenByStar());
- if (!onlyStarred || !acc.isHiddenByStar())
- accountList.add(acc);
+ acc.setHasSubAccounts(true);
+ 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);
AccountListParser parser = new AccountListParser(resp);
ArrayList<LedgerAccount> accountList = new ArrayList<>();
+ LedgerAccount prevAccount = null;
+
while (true) {
throwIfCancelled();
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);
+
+ if (prevAccount != null) {
+ prevAccount.setHasSubAccounts(
+ acc.getName().startsWith(prevAccount.getName() + ":"));
+ }
+
+ prevAccount = acc;
}
throwIfCancelled();