From f8ccb6a9def9403cf24ae1d7f90c80d2ed759da9 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Mon, 18 Mar 2019 11:23:32 +0200 Subject: [PATCH] fill hasSubAccounts when populating account list on refresh --- .../async/RetrieveTransactionsTask.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java index e81a71c2..de459ece 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java @@ -112,7 +112,7 @@ public class RetrieveTransactionsTask int maxTransactionId = Progress.INDETERMINATE; ArrayList accountList = new ArrayList<>(); HashMap accountNames = new HashMap<>(); - LedgerAccount lastAccount = null; + LedgerAccount lastAccount = null, prevAccount = null; boolean onlyStarred = Data.optShowOnlyStarred.get(); HttpURLConnection http = NetworkUtil.prepareConnection(profile, "journal"); @@ -169,12 +169,15 @@ public class RetrieveTransactionsTask 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(); 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(); @@ -190,6 +193,7 @@ public class RetrieveTransactionsTask String aName = toAppend.pop(); LedgerAccount acc = new LedgerAccount(aName); acc.setHiddenByStar(lastAccount.isHiddenByStar()); + acc.setHasSubAccounts(true); if ((!onlyStarred || !acc.isHiddenByStar()) && acc.isVisible(accountList)) accountList.add(acc); L(String.format("gap-filling with %s", aName)); @@ -391,6 +395,8 @@ public class RetrieveTransactionsTask AccountListParser parser = new AccountListParser(resp); ArrayList accountList = new ArrayList<>(); + LedgerAccount prevAccount = null; + while (true) { throwIfCancelled(); ParsedLedgerAccount parsedAccount = parser.nextAccount(); @@ -407,6 +413,13 @@ public class RetrieveTransactionsTask } if (acc.isVisible(accountList)) accountList.add(acc); + + if (prevAccount != null) { + prevAccount.setHasSubAccounts( + acc.getName().startsWith(prevAccount.getName() + ":")); + } + + prevAccount = acc; } throwIfCancelled(); -- 2.39.5