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");
default:
throw new HTTPException(http.getResponseCode(), http.getResponseMessage());
}
- try (SQLiteDatabase db = MLDB.getWritableDatabase()) {
+ try (SQLiteDatabase db = MLDB.getDatabase()) {
try (InputStream resp = http.getInputStream()) {
if (http.getResponseCode() != 200)
throw new IOException(String.format("HTTP error %d", http.getResponseCode()));
if (line.equals("<h2>General Journal</h2>")) {
state = ParserState.EXPECTING_TRANSACTION;
L("→ expecting transaction");
+ // commit the current transaction and start a new one
+ // the account list in the UI should reflect the (committed)
+ // state of the database
+ db.setTransactionSuccessful();
+ db.endTransaction();
Data.accounts.set(accountList);
+ db.beginTransaction();
continue;
}
m = reAccountName.matcher(line);
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();
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));
throw new HTTPException(http.getResponseCode(), http.getResponseMessage());
}
publishProgress(progress);
- try (SQLiteDatabase db = MLDB.getWritableDatabase()) {
- try (InputStream resp = http.getInputStream()) {
- if (http.getResponseCode() != 200)
- throw new IOException(String.format("HTTP error %d", http.getResponseCode()));
+ SQLiteDatabase db = MLDB.getDatabase();
+ try (InputStream resp = http.getInputStream()) {
+ if (http.getResponseCode() != 200)
+ throw new IOException(String.format("HTTP error %d", http.getResponseCode()));
- db.beginTransaction();
- try {
- profile.markAccountsAsNotPresent(db);
+ db.beginTransaction();
+ try {
+ profile.markAccountsAsNotPresent(db);
- AccountListParser parser = new AccountListParser(resp);
- ArrayList<LedgerAccount> accountList = new ArrayList<>();
+ AccountListParser parser = new AccountListParser(resp);
+ ArrayList<LedgerAccount> accountList = new ArrayList<>();
- while (true) {
- throwIfCancelled();
- ParsedLedgerAccount parsedAccount = parser.nextAccount();
- if (parsedAccount == null) break;
-
- LedgerAccount acc = new LedgerAccount(parsedAccount.getAname());
- profile.storeAccount(db, acc);
- for (ParsedBalance b : parsedAccount.getAebalance()) {
- profile.storeAccountValue(db, acc.getName(), b.getAcommodity(),
- b.getAquantity().asFloat());
- }
+ LedgerAccount prevAccount = null;
- accountList.add(acc);
- }
+ while (true) {
throwIfCancelled();
+ ParsedLedgerAccount parsedAccount = parser.nextAccount();
+ if (parsedAccount == null) break;
- profile.deleteNotPresentAccounts(db);
- throwIfCancelled();
- db.setTransactionSuccessful();
- Data.accounts.set(accountList);
- }
- finally {
- db.endTransaction();
+ 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());
+ }
+
+ if (acc.isVisible(accountList)) accountList.add(acc);
+
+ if (prevAccount != null) {
+ prevAccount.setHasSubAccounts(
+ acc.getName().startsWith(prevAccount.getName() + ":"));
+ }
+
+ prevAccount = acc;
}
+ throwIfCancelled();
+
+ profile.deleteNotPresentAccounts(db);
+ throwIfCancelled();
+ db.setTransactionSuccessful();
+ Data.accounts.set(accountList);
+ }
+ finally {
+ db.endTransaction();
}
}
default:
throw new HTTPException(http.getResponseCode(), http.getResponseMessage());
}
- try (SQLiteDatabase db = MLDB.getWritableDatabase()) {
+ try (SQLiteDatabase db = MLDB.getDatabase()) {
try (InputStream resp = http.getInputStream()) {
if (http.getResponseCode() != 200)
throw new IOException(String.format("HTTP error %d", http.getResponseCode()));