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=acd1475d1e66eddf89cdbf0c34436a7ca2e149dc;hp=ab0ab271d69e2cad91eeb50a596d9d3f72a58536;hb=ff3be47725919f5284a2a4e2348d1ab6fd561325;hpb=4ee225877f078570881e4c0f5c2e1c4c99b52dda 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 ab0ab271..acd1475d 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java @@ -166,7 +166,7 @@ public class RetrieveTransactionsTask lastAccount = profile.loadAccount(acct_name); if (lastAccount == null) { lastAccount = new LedgerAccount(acct_name); - profile.storeAccount(lastAccount); + profile.storeAccount(db, lastAccount); } // make sure the parent account(s) are present, @@ -188,7 +188,7 @@ public class RetrieveTransactionsTask accountList.add(acc); L(String.format("gap-filling with %s", aName)); accountNames.put(aName, null); - profile.storeAccount(acc); + profile.storeAccount(db, acc); } } @@ -213,7 +213,7 @@ public class RetrieveTransactionsTask if (currency == null) currency = ""; value = value.replace(',', '.'); L("curr=" + currency + ", value=" + value); - profile.storeAccountValue(lastAccount.getName(), currency, + profile.storeAccountValue(db, lastAccount.getName(), currency, Float.valueOf(value)); lastAccount.addAmount(Float.parseFloat(value), currency); } @@ -291,7 +291,7 @@ public class RetrieveTransactionsTask } } else { - profile.storeTransaction(transaction); + profile.storeTransaction(db, transaction); matchedTransactionsCount = 0; progress.setTotal(maxTransactionId); } @@ -372,21 +372,28 @@ public class RetrieveTransactionsTask profile.markAccountsAsNotPresent(db); AccountListParser parser = new AccountListParser(resp); + ArrayList accountList = new ArrayList<>(); while (true) { + throwIfCancelled(); ParsedLedgerAccount parsedAccount = parser.nextAccount(); if (parsedAccount == null) break; LedgerAccount acc = new LedgerAccount(parsedAccount.getAname()); - profile.storeAccount(acc); + profile.storeAccount(db, acc); for (ParsedBalance b : parsedAccount.getAebalance()) { - profile.storeAccountValue(acc.getName(), b.getAcommodity(), + profile.storeAccountValue(db, acc.getName(), b.getAcommodity(), b.getAquantity().asFloat()); } + + accountList.add(acc); } + throwIfCancelled(); profile.deleteNotPresentAccounts(db); + throwIfCancelled(); db.setTransactionSuccessful(); + Data.accounts.set(accountList); } finally { db.endTransaction(); @@ -408,6 +415,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); @@ -418,7 +426,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)) { @@ -435,7 +445,7 @@ public class RetrieveTransactionsTask } } else { - profile.storeTransaction(transaction); + profile.storeTransaction(db, transaction); matchedTransactionsCount = 0; progress.setTotal(maxTransactionId); } @@ -444,7 +454,9 @@ public class RetrieveTransactionsTask publishProgress(progress); } + throwIfCancelled(); profile.deleteNotPresentTransactions(db); + throwIfCancelled(); db.setTransactionSuccessful(); profile.setLastUpdateStamp(); }