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=965c1f982fc98db94458dfb1109d9e4eabd07c67;hp=4ca3f827449c0c0ea5364229169b501877ea4a25;hb=9020bea97b9666c71964b48cfcad11c966edb0e0;hpb=4ba4845b9cd0c49e7cf41d153aad0c752c1dd608 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 4ca3f827..965c1f98 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java @@ -49,7 +49,6 @@ import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.util.ArrayList; -import java.util.Date; import java.util.HashMap; import java.util.Stack; import java.util.regex.Matcher; @@ -340,10 +339,7 @@ public class RetrieveTransactionsTask profile.deleteNotPresentTransactions(db); db.setTransactionSuccessful(); - Log.d("db", "Updating transaction value stamp"); - Date now = new Date(); - profile.setLongOption(MLDB.OPT_LAST_SCRAPE, now.getTime()); - Data.lastUpdateDate.set(now); + profile.setLastUpdateStamp(); return null; } @@ -378,6 +374,7 @@ public class RetrieveTransactionsTask AccountListParser parser = new AccountListParser(resp); while (true) { + throwIfCancelled(); ParsedLedgerAccount parsedAccount = parser.nextAccount(); if (parsedAccount == null) break; @@ -388,8 +385,10 @@ public class RetrieveTransactionsTask b.getAquantity().asFloat()); } } + throwIfCancelled(); profile.deleteNotPresentAccounts(db); + throwIfCancelled(); db.setTransactionSuccessful(); } finally { @@ -412,6 +411,7 @@ public class RetrieveTransactionsTask try (InputStream resp = http.getInputStream()) { if (http.getResponseCode() != 200) throw new IOException(String.format("HTTP error %d", http.getResponseCode())); + throwIfCancelled(); db.beginTransaction(); try { profile.markTransactionsAsNotPresent(db); @@ -422,7 +422,9 @@ public class RetrieveTransactionsTask int processedTransactionCount = 0; while (true) { + throwIfCancelled(); ParsedLedgerTransaction parsedTransaction = parser.nextTransaction(); + throwIfCancelled(); if (parsedTransaction == null) break; LedgerTransaction transaction = parsedTransaction.asLedgerTransaction(); if (transaction.existsInDb(db)) { @@ -434,6 +436,7 @@ public class RetrieveTransactionsTask progress.setTotal(progress.getProgress()); publishProgress(progress); db.setTransactionSuccessful(); + profile.setLastUpdateStamp(); return true; } } @@ -447,8 +450,11 @@ public class RetrieveTransactionsTask publishProgress(progress); } + throwIfCancelled(); profile.deleteNotPresentTransactions(db); + throwIfCancelled(); db.setTransactionSuccessful(); + profile.setLastUpdateStamp(); } finally { db.endTransaction();