From 324f40ffba80292007999d9812929acc6f6a36f8 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sat, 15 Dec 2018 19:34:58 +0000 Subject: [PATCH] TransactionListViewModel: also load transaction accounts 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 --- .../transaction_list/TransactionListViewModel.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 35b01145..d0c979e6 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 @@ -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); } } -- 2.39.5