]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
update the in-memory account list after parsing the JSON account list
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / async / RetrieveTransactionsTask.java
index ab0ab271d69e2cad91eeb50a596d9d3f72a58536..dcc91b2f27ff2a7cb2aa5433afee4970741522df 100644 (file)
@@ -372,8 +372,10 @@ public class RetrieveTransactionsTask
                     profile.markAccountsAsNotPresent(db);
 
                     AccountListParser parser = new AccountListParser(resp);
+                    ArrayList<LedgerAccount> accountList = new ArrayList<>();
 
                     while (true) {
+                        throwIfCancelled();
                         ParsedLedgerAccount parsedAccount = parser.nextAccount();
                         if (parsedAccount == null) break;
 
@@ -383,10 +385,15 @@ public class RetrieveTransactionsTask
                             profile.storeAccountValue(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)) {
@@ -444,7 +454,9 @@ public class RetrieveTransactionsTask
                         publishProgress(progress);
                     }
 
+                    throwIfCancelled();
                     profile.deleteNotPresentTransactions(db);
+                    throwIfCancelled();
                     db.setTransactionSuccessful();
                     profile.setLastUpdateStamp();
                 }