]> git.ktnx.net Git - mobile-ledger.git/commitdiff
transaction load: replace the list atomically
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 21 Dec 2018 20:23:20 +0000 (20:23 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 21 Dec 2018 20:23:20 +0000 (20:23 +0000)
otherwise it was emptied and filled up sequentially, while the scroller may
request an item at a position that is not yet loaded

app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListViewModel.java

index 53fb742f9a1acf7e2cc847781bbad3cb0e2c7e5a..f2377c958022ed653a3158330877f5f197bb7d9a 100644 (file)
@@ -41,14 +41,16 @@ public class TransactionListViewModel extends ViewModel {
         return transactions;
     }
     public void reloadTransactions(Context context) {
-        transactions.clear();
+        ArrayList<LedgerTransaction> 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;
             }
         }