From 1857937cbdb55199cb9391a7b42766d6dcba80c8 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Wed, 19 Dec 2018 20:22:41 +0000 Subject: [PATCH] refresh transaction list upon database update from the backend --- .../java/net/ktnx/mobileledger/TransactionListActivity.java | 2 +- .../ktnx/mobileledger/async/RetrieveTransactionsTask.java | 5 +++-- .../ui/transaction_list/TransactionListViewModel.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/TransactionListActivity.java b/app/src/main/java/net/ktnx/mobileledger/TransactionListActivity.java index 715af08a..39323f7b 100644 --- a/app/src/main/java/net/ktnx/mobileledger/TransactionListActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/TransactionListActivity.java @@ -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 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 63b30b5c..e63f30d2 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java @@ -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; diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListViewModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListViewModel.java index 0ce37f2c..53fb742f 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListViewModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListViewModel.java @@ -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"; -- 2.39.5