]> git.ktnx.net Git - mobile-ledger.git/commitdiff
refresh transaction list upon database update from the backend
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 19 Dec 2018 20:22:41 +0000 (20:22 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 19 Dec 2018 20:22:41 +0000 (20:22 +0000)
app/src/main/java/net/ktnx/mobileledger/TransactionListActivity.java
app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListViewModel.java

index 715af08a1539e8f6f8313abd4dcb24e2037c6b96..39323f7bf6b18a930660b1509404ac8fc76571a9 100644 (file)
@@ -47,7 +47,7 @@ public class TransactionListActivity extends AppCompatActivity {
     private SwipeRefreshLayout swiper;
     private RecyclerView root;
     private ProgressBar progressBar;
-    private TransactionListViewModel model;
+    public TransactionListViewModel model;
     private TextView tvLastUpdate;
     private TransactionListAdapter modelAdapter;
     @Override
index 63b30b5c0a9467d71163d062ee866bb7ff6c6c05..e63f30d2d026cc30988b1f191f0a38657f67472e 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()) {
@@ -207,6 +206,8 @@ public class RetrieveTransactionsTask extends
                     }
                 }
             }
+
+            if (success && !isCancelled()) ctx.model.reloadTransactions(ctx);
         }
         catch (MalformedURLException e) {
             error = R.string.err_bad_backend_url;
index 0ce37f2c0184776fc60e30ff631aad1976c495e8..53fb742f9a1acf7e2cc847781bbad3cb0e2c7e5a 100644 (file)
@@ -40,7 +40,7 @@ public class TransactionListViewModel extends ViewModel {
 
         return transactions;
     }
-    private void reloadTransactions(Context context) {
+    public void reloadTransactions(Context context) {
         transactions.clear();
         String sql = "SELECT id FROM transactions ORDER BY date desc, id desc";