import android.content.Context;
import android.content.res.Resources;
import android.database.sqlite.SQLiteDatabase;
-import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.widget.TextView;
import net.ktnx.mobileledger.model.LedgerTransaction;
-import net.ktnx.mobileledger.model.LedgerTransactionItem;
+import net.ktnx.mobileledger.model.LedgerTransactionAccount;
+import net.ktnx.mobileledger.utils.Globals;
import net.ktnx.mobileledger.utils.MLDB;
import java.util.Iterator;
public void onBindViewHolder(@NonNull TransactionRowHolder holder, int position) {
LedgerTransaction tr = transactions.get(position);
Context ctx = holder.row.getContext();
- Resources rm = ctx.getResources();
- try (SQLiteDatabase db = MLDB.getReadableDatabase(ctx.getApplicationContext())) {
+
+ try (SQLiteDatabase db = MLDB.getReadableDatabase(ctx)) {
tr.loadData(db);
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<LedgerTransactionItem> it = tr.getItemsIterator(); it.hasNext(); ) {
- LedgerTransactionItem acc = it.next();
+ for (LedgerTransactionAccount acc : tr.getAccounts()) {
TableRow row = new TableRow(holder.row.getContext());
TextView child = new TextView(ctx);
child.setText(acc.getShortAccountName());
}
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));
+ holder.row.setBackgroundColor(Globals.table_row_even_bg);
}
else {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) holder.row
- .setBackgroundColor(rm.getColor(R.color.table_row_odd_bg, ctx
- .getTheme()));
- else holder.row.setBackgroundColor(rm.getColor(R.color.table_row_odd_bg));
+ holder.row.setBackgroundColor(Globals.table_row_odd_bg);
}
holder.row.setTag(R.id.POS, position);