From: Damyan Ivanov Date: Fri, 21 Dec 2018 20:23:20 +0000 (+0000) Subject: transaction load: replace the list atomically X-Git-Tag: v0.3~178 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=7c2782d1ba2a27c6d9d2ee5e48ab723e63c27d12;p=mobile-ledger.git 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 --- 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; } }