+ 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);
+ db.execSQL(
+ "insert or replace into account_values(account, currency, value, keep) values(?, ?, ?, 1);",
+ new Object[]{lastAccount.getName(), currency,
+ Float.valueOf(value)
+ });
+ lastAccount.addAmount(Float.parseFloat(value), currency);
+ }
+
+ if (match_found) {
+ state = ParserState.EXPECTING_ACCOUNT;
+ L("→ expecting account");
+ }
+
+ break;
+
+ case EXPECTING_TRANSACTION:
+ if (!line.isEmpty() && (line.charAt(0) == ' ')) continue;
+ m = transactionStartPattern.matcher(line);
+ if (m.find()) {
+ transactionId = Integer.valueOf(m.group(1));
+ state = ParserState.EXPECTING_TRANSACTION_DESCRIPTION;
+ L(String.format(
+ "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 = endPattern.matcher(line);
+ if (m.find()) {
+ L("--- transaction value complete ---");
+ success = true;
+ break LINES;
+ }
+ break;
+
+ case EXPECTING_TRANSACTION_DESCRIPTION:
+ if (!line.isEmpty() && (line.charAt(0) == ' ')) continue;
+ m = transactionDescriptionPattern.matcher(line);
+ if (m.find()) {
+ if (transactionId == 0)
+ throw new TransactionParserException(
+ "Transaction Id is 0 while expecting " +
+ "description");
+
+ transaction =
+ new LedgerTransaction(transactionId, m.group(1),
+ m.group(2));
+ state = ParserState.EXPECTING_TRANSACTION_DETAILS;
+ L(String.format("transaction %d created for %s (%s) →" +
+ " expecting details", transactionId,
+ m.group(1), m.group(2)));
+ }
+ break;
+
+ case EXPECTING_TRANSACTION_DETAILS:
+ if (line.isEmpty()) {
+ // transaction data collected
+ if (transaction.existsInDb(db)) {
+ db.execSQL("UPDATE transactions SET keep = 1 WHERE id" +
+ "=?", new Integer[]{transaction.getId()});
+ matchedTransactionsCount++;
+
+ if (matchedTransactionsCount ==
+ MATCHING_TRANSACTIONS_LIMIT)
+ {
+ db.execSQL("UPDATE transactions SET keep=1 WHERE " +
+ "id < ?",
+ new Integer[]{transaction.getId()});
+ success = true;
+ progress.setTotal(progress.getProgress());
+ publishProgress(progress);
+ break LINES;
+ }