+ }
+
+ if ((!onlyStarred || !lastAccount.isHiddenByStar()) &&
+ lastAccount.isVisible(accountList))
+ accountList.add(lastAccount);
+ accountNames.put(acct_name, null);
+
+ state = ParserState.EXPECTING_ACCOUNT_AMOUNT;
+ L("→ expecting account amount");
+ }
+ break;
+
+ case EXPECTING_ACCOUNT_AMOUNT:
+ m = reAccountValue.matcher(line);
+ boolean match_found = false;
+ while (m.find()) {
+ throwIfCancelled();
+
+ match_found = true;
+ String value = m.group(1);
+ String currency = m.group(2);
+ if (currency == null) currency = "";
+ value = value.replace(',', '.');
+ L("curr=" + currency + ", value=" + value);
+ final float val = Float.parseFloat(value);
+ profile.storeAccountValue(db, lastAccount.getName(), currency, val);
+ lastAccount.addAmount(val, currency);
+ for (LedgerAccount syn : syntheticAccounts.values()) {
+ L(String.format(Locale.ENGLISH, "propagating %s %1.2f to %s",
+ currency, val, syn.getName()));
+ syn.addAmount(val, currency);
+ profile.storeAccountValue(db, syn.getName(), currency, val);
+ }
+ }
+
+ if (match_found) {
+ syntheticAccounts.clear();
+ state = ParserState.EXPECTING_ACCOUNT;
+ L("→ expecting account");
+ }
+
+ break;
+
+ case EXPECTING_TRANSACTION:
+ if (!line.isEmpty() && (line.charAt(0) == ' ')) continue;
+ m = reTransactionStart.matcher(line);
+ if (m.find()) {
+ transactionId = Integer.valueOf(m.group(1));
+ state = ParserState.EXPECTING_TRANSACTION_DESCRIPTION;
+ L(String.format(Locale.ENGLISH,
+ "found transaction %d → expecting description",
+ transactionId));
+ progress.setProgress(++processedTransactionCount);
+ if (maxTransactionId < transactionId)
+ maxTransactionId = transactionId;
+ if ((progress.getTotal() == Progress.INDETERMINATE) ||
+ (progress.getTotal() < transactionId))
+ progress.setTotal(transactionId);
+ publishProgress(progress);
+ }
+ m = reEnd.matcher(line);
+ if (m.find()) {
+ L("--- transaction value complete ---");
+ break LINES;
+ }
+ break;
+
+ case EXPECTING_TRANSACTION_DESCRIPTION:
+ if (!line.isEmpty() && (line.charAt(0) == ' ')) continue;
+ m = reTransactionDescription.matcher(line);
+ if (m.find()) {
+ if (transactionId == 0) throw new TransactionParserException(
+ "Transaction Id is 0 while expecting " + "description");
+
+ String date = m.group(1);
+ try {
+ int equalsIndex = date.indexOf('=');
+ if (equalsIndex >= 0) date = date.substring(equalsIndex + 1);
+ transaction =
+ new LedgerTransaction(transactionId, date, m.group(2));
+ }
+ catch (ParseException e) {
+ e.printStackTrace();
+ return String.format("Error parsing date '%s'", date);
+ }
+ state = ParserState.EXPECTING_TRANSACTION_DETAILS;
+ L(String.format(Locale.ENGLISH,
+ "transaction %d created for %s (%s) →" +
+ " expecting details", transactionId, date, m.group(2)));
+ }
+ break;
+
+ case EXPECTING_TRANSACTION_DETAILS:
+ if (line.isEmpty()) {
+ // transaction data collected
+ if (transaction.existsInDb(db)) {
+ profile.markTransactionAsPresent(db, transaction);
+ matchedTransactionsCount++;
+
+ if (matchedTransactionsCount == MATCHING_TRANSACTIONS_LIMIT) {
+ profile.markTransactionsBeforeTransactionAsPresent(db,
+ transaction);
+ progress.setTotal(progress.getProgress());
+ publishProgress(progress);