]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/TransactionListAdapter.java
save a method call
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / TransactionListAdapter.java
index f190efcd87ce571c384ff6b831b6eaecdc905336..1ec01132a1505a4000f22f0d03424e308ad366ed 100644 (file)
@@ -19,7 +19,7 @@ package net.ktnx.mobileledger;
 
 import android.content.Context;
 import android.content.res.Resources;
-import android.os.Build;
+import android.database.sqlite.SQLiteDatabase;
 import android.support.annotation.NonNull;
 import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
@@ -27,10 +27,15 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.widget.LinearLayout;
 import android.widget.TableLayout;
+import android.widget.TableRow;
 import android.widget.TextView;
 
 import net.ktnx.mobileledger.model.LedgerTransaction;
+import net.ktnx.mobileledger.model.LedgerTransactionAccount;
+import net.ktnx.mobileledger.utils.Globals;
+import net.ktnx.mobileledger.utils.MLDB;
 
+import java.util.Iterator;
 import java.util.List;
 
 class TransactionListAdapter
@@ -44,23 +49,35 @@ class TransactionListAdapter
     public void onBindViewHolder(@NonNull TransactionRowHolder holder, int position) {
         LedgerTransaction tr = transactions.get(position);
         Context ctx = holder.row.getContext();
-        Resources rm = ctx.getResources();
 
-        holder.tvDescription.setText(String.format("%s\n%s", tr.getDescription(), tr.getDate()));
-//        holder.tableAccounts.setText(acc.getAmountsString());
+        try (SQLiteDatabase db = MLDB.getReadableDatabase(ctx)) {
+            tr.loadData(db);
 
-        if (position % 2 == 0) {
-            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) holder.row
-                    .setBackgroundColor(rm.getColor(R.color.table_row_even_bg, ctx.getTheme()));
-            else holder.row.setBackgroundColor(rm.getColor(R.color.table_row_even_bg));
-        }
-        else {
-            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) holder.row
-                    .setBackgroundColor(rm.getColor(R.color.drawer_background, ctx.getTheme()));
-            else holder.row.setBackgroundColor(rm.getColor(R.color.drawer_background));
-        }
+            holder.tvDescription
+                    .setText(String.format("%s\n%s", tr.getDescription(), tr.getDate()));
+            TableLayout tbl = holder.row.findViewById(R.id.transaction_row_acc_amounts);
+            tbl.removeAllViews();
+            for (Iterator<LedgerTransactionAccount> it = tr.getAccountsIterator(); it.hasNext(); ) {
+                LedgerTransactionAccount acc = it.next();
+                TableRow row = new TableRow(holder.row.getContext());
+                TextView child = new TextView(ctx);
+                child.setText(acc.getShortAccountName());
+                row.addView(child);
+                child = new TextView(ctx);
+                child.setText(acc.toString());
+                row.addView(child);
+                tbl.addView(row);
+            }
 
-        holder.row.setTag(R.id.POS, position);
+            if (position % 2 == 0) {
+                holder.row.setBackgroundColor(Globals.table_row_even_bg);
+            }
+            else {
+                holder.row.setBackgroundColor(Globals.table_row_odd_bg);
+            }
+
+            holder.row.setTag(R.id.POS, position);
+        }
     }
 
     @NonNull