X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fasync%2FRetrieveTransactionsTask.java;h=8a9a8f62e8e98c4917aab9e383828c48f496771d;hp=2e3ca764d9897b1adecf718dd814d2e7b914ae8e;hb=6c58c1072c9af6ea0d0f52baeae7f95ba7f7ee2f;hpb=a983099d6150044a08a1fbc601d9af9bd8d0c0a8 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 2e3ca764..8a9a8f62 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java @@ -28,7 +28,7 @@ import net.ktnx.mobileledger.R; 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; @@ -94,15 +94,14 @@ public class RetrieveTransactionsTask extends 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())); db.beginTransaction(); try { - String root = params[0].getAccountsRoot(); db.execSQL("DELETE FROM transactions;"); + db.execSQL("DELETE FROM transaction_accounts"); int state = ParserState.EXPECTING_JOURNAL; String line; @@ -114,8 +113,10 @@ public class RetrieveTransactionsTask extends 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("

General Journal

")) { @@ -167,6 +168,14 @@ public class RetrieveTransactionsTask extends 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); @@ -189,7 +198,7 @@ public class RetrieveTransactionsTask extends state)); } } - db.setTransactionSuccessful(); + if (!isCancelled()) db.setTransactionSuccessful(); } finally { db.endTransaction();