]> git.ktnx.net Git - mobile-ledger.git/commitdiff
TransactionListViewModel: also load transaction accounts
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 15 Dec 2018 19:34:58 +0000 (19:34 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 15 Dec 2018 19:34:58 +0000 (19:34 +0000)
this becomes rather slow and needs to be reworked

only the list of transaction IDs needs to be loaded initially, and the
details and the accounts need to be loaded on demand, per row

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

index 35b011458c8f36759d3e520a2d1552c98fb8a946..d0c979e6df9b06ea6325fa80c3e906f5f3a78e62 100644 (file)
@@ -22,6 +22,7 @@ import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 
 import net.ktnx.mobileledger.model.LedgerTransaction;
+import net.ktnx.mobileledger.model.LedgerTransactionItem;
 import net.ktnx.mobileledger.utils.MobileLedgerDatabase;
 
 import java.util.ArrayList;
@@ -50,7 +51,16 @@ public class TransactionListViewModel extends ViewModel {
                     LedgerTransaction tr =
                             new LedgerTransaction(cursor.getString(0), cursor.getString(1),
                                     cursor.getString(2));
-                    // TODO: fill accounts and amounts
+                    try (Cursor cAcc = db.rawQuery("SELECT account_name, amount, currency FROM " +
+                                                   "transaction_accounts WHERE transaction_id = ?",
+                            new String[]{tr.getId()}))
+                    {
+                        while (cAcc.moveToNext()) {
+                            tr.add_item(
+                                    new LedgerTransactionItem(cAcc.getString(0), cAcc.getFloat(1),
+                                            cAcc.getString(2)));
+                        }
+                    }
                     transactions.add(tr);
                 }
             }