import net.ktnx.mobileledger.TransactionListActivity;
import net.ktnx.mobileledger.model.LedgerTransaction;
import net.ktnx.mobileledger.model.LedgerTransactionItem;
-import net.ktnx.mobileledger.utils.MobileLedgerDatabase;
+import net.ktnx.mobileledger.utils.MLDB;
import net.ktnx.mobileledger.utils.NetworkUtil;
import java.io.BufferedReader;
publishProgress(progress);
Context ctx = contextRef.get();
if (ctx == null) return null;
- try (MobileLedgerDatabase dbh = new MobileLedgerDatabase(ctx)) {
- try (SQLiteDatabase db = dbh.getWritableDatabase()) {
+ try (SQLiteDatabase db = MLDB.getWritableDatabase(ctx)) {
try (InputStream resp = http.getInputStream()) {
if (http.getResponseCode() != 200) throw new IOException(
String.format("HTTP error %d", http.getResponseCode()));
LedgerTransaction transaction = null;
LINES:
while ((line = buf.readLine()) != null) {
+ if (isCancelled()) break;
+ if (!line.isEmpty() && (line.charAt(0) == ' ')) continue;
Matcher m;
- L(String.format("State is %d", state));
+ //L(String.format("State is %d", state));
switch (state) {
case ParserState.EXPECTING_JOURNAL:
if (line.equals("<h2>General Journal</h2>")) {
state = ParserState.EXPECTING_TRANSACTION;
L(String.format("transaction %s saved → expecting " +
"transaction", transaction.getId()));
+
+// sounds like a good idea, but transaction-1 may not be the first one chronologically
+// for example, when you add the initial seeding transaction after entering some others
+// if (transactionId == 1) {
+// L("This was the initial transaction. Terminating " +
+// "parser");
+// break LINES;
+// }
}
else {
m = transactionDetailsPattern.matcher(line);
state));
}
}
- db.setTransactionSuccessful();
+ if (!isCancelled()) db.setTransactionSuccessful();
}
finally {
db.endTransaction();