From 7c2782d1ba2a27c6d9d2ee5e48ab723e63c27d12 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Fri, 21 Dec 2018 20:23:20 +0000 Subject: [PATCH] transaction load: replace the list atomically otherwise it was emptied and filled up sequentially, while the scroller may request an item at a position that is not yet loaded --- .../ui/transaction_list/TransactionListViewModel.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 53fb742f..f2377c95 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 @@ -41,14 +41,16 @@ public class TransactionListViewModel extends ViewModel { return transactions; } public void reloadTransactions(Context context) { - transactions.clear(); + ArrayList newList = new ArrayList<>(); + String sql = "SELECT id FROM transactions ORDER BY date desc, id desc"; try (SQLiteDatabase db = MLDB.getReadableDatabase(context)) { try (Cursor cursor = db.rawQuery(sql, null)) { while (cursor.moveToNext()) { - transactions.add(new LedgerTransaction(cursor.getInt(0))); + newList.add(new LedgerTransaction(cursor.getInt(0))); } + transactions = newList; } } -- 2.39.5