]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
transactions may come in random order from the backend
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / async / RetrieveTransactionsTask.java
index 63b30b5c0a9467d71163d062ee866bb7ff6c6c05..23f75c9c47e702f84d2343421c3b63c0a45c899e 100644 (file)
@@ -18,7 +18,6 @@
 package net.ktnx.mobileledger.async;
 
 import android.annotation.SuppressLint;
-import android.content.Context;
 import android.content.SharedPreferences;
 import android.database.sqlite.SQLiteDatabase;
 import android.os.AsyncTask;
@@ -92,7 +91,7 @@ public class RetrieveTransactionsTask extends
                     NetworkUtil.prepare_connection(params[0].getBackendPref(), "journal");
             http.setAllowUserInteraction(false);
             publishProgress(progress);
-            Context ctx = contextRef.get();
+            TransactionListActivity ctx = contextRef.get();
             if (ctx == null) return null;
             try (SQLiteDatabase db = MLDB.getWritableDatabase(ctx)) {
                 try (InputStream resp = http.getInputStream()) {
@@ -134,7 +133,8 @@ public class RetrieveTransactionsTask extends
                                                 "found transaction %d → expecting " + "description",
                                                 transactionId));
                                         progress.setProgress(++transactionCount);
-                                        if (progress.getTotal() == Progress.INDETERMINATE)
+                                        if ((progress.getTotal() == Progress.INDETERMINATE) ||
+                                            (progress.getTotal() < transactionId))
                                             progress.setTotal(transactionId);
                                         publishProgress(progress);
                                     }
@@ -207,6 +207,8 @@ public class RetrieveTransactionsTask extends
                     }
                 }
             }
+
+            if (success && !isCancelled()) ctx.model.reloadTransactions(ctx);
         }
         catch (MalformedURLException e) {
             error = R.string.err_bad_backend_url;