import net.ktnx.mobileledger.model.Data;
import net.ktnx.mobileledger.model.LedgerAccount;
+import java.util.List;
+
class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAdapter.LedgerRowHolder> {
private boolean selectionActive;
}
public void onBindViewHolder(@NonNull LedgerRowHolder holder, int position) {
- LedgerAccount acc = Data.accounts.get().get(position);
- Context ctx = holder.row.getContext();
- Resources rm = ctx.getResources();
-
- holder.tvAccountName.setText(acc.getShortName());
- holder.tvAccountName.setPadding(
- acc.getLevel() * rm.getDimensionPixelSize(R.dimen.activity_horizontal_margin) / 2,
- 0, 0, 0);
- holder.tvAccountAmounts.setText(acc.getAmountsString());
-
- if (acc.isHidden()) {
- holder.tvAccountName.setTypeface(null, Typeface.ITALIC);
- holder.tvAccountAmounts.setTypeface(null, Typeface.ITALIC);
- }
- else {
- holder.tvAccountName.setTypeface(null, Typeface.NORMAL);
- holder.tvAccountAmounts.setTypeface(null, Typeface.NORMAL);
- }
+ List<LedgerAccount> accounts = Data.accounts.get();
+ if (position < accounts.size()) {
+ LedgerAccount acc = accounts.get(position);
+ Context ctx = holder.row.getContext();
+ Resources rm = ctx.getResources();
+
+ holder.row.setVisibility(View.VISIBLE);
+ holder.vTrailer.setVisibility(View.GONE);
+ holder.tvAccountName.setText(acc.getShortName());
+ holder.tvAccountName.setPadding(
+ acc.getLevel() * rm.getDimensionPixelSize(R.dimen.activity_horizontal_margin) /
+ 2, 0, 0, 0);
+ holder.tvAccountAmounts.setText(acc.getAmountsString());
+
+ if (acc.isHidden()) {
+ holder.tvAccountName.setTypeface(null, Typeface.ITALIC);
+ holder.tvAccountAmounts.setTypeface(null, Typeface.ITALIC);
+ }
+ else {
+ holder.tvAccountName.setTypeface(null, Typeface.NORMAL);
+ holder.tvAccountAmounts.setTypeface(null, Typeface.NORMAL);
+ }
- if (position % 2 == 0) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) holder.row
- .setBackgroundColor(rm.getColor(R.color.table_row_dark_bg, ctx.getTheme()));
- else holder.row.setBackgroundColor(rm.getColor(R.color.table_row_dark_bg));
+ if (position % 2 == 0) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) holder.row
+ .setBackgroundColor(rm.getColor(R.color.table_row_dark_bg, ctx.getTheme()));
+ else holder.row.setBackgroundColor(rm.getColor(R.color.table_row_dark_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.selectionCb.setVisibility(selectionActive ? View.VISIBLE : View.GONE);
+ holder.selectionCb.setChecked(!acc.isHiddenToBe());
+
+ holder.row.setTag(R.id.POS, position);
}
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.vTrailer.setVisibility(View.VISIBLE);
+ holder.row.setVisibility(View.GONE);
}
-
- holder.selectionCb.setVisibility(selectionActive ? View.VISIBLE : View.GONE);
- holder.selectionCb.setChecked(!acc.isHiddenToBe());
-
- holder.row.setTag(R.id.POS, position);
}
@NonNull
@Override
public int getItemCount() {
- return Data.accounts.get().size();
+ return Data.accounts.get().size() + 1;
}
public void startSelection() {
for (LedgerAccount acc : Data.accounts.get()) acc.setHiddenToBe(acc.isHidden());
CheckBox selectionCb;
TextView tvAccountName, tvAccountAmounts;
LinearLayout row;
+ View vTrailer;
public LedgerRowHolder(@NonNull View itemView) {
super(itemView);
- this.row = (LinearLayout) itemView;
+ this.row = itemView.findViewById(R.id.account_summary_row);
this.tvAccountName = itemView.findViewById(R.id.account_row_acc_name);
this.tvAccountAmounts = itemView.findViewById(R.id.account_row_acc_amounts);
this.selectionCb = itemView.findViewById(R.id.account_row_check);
+ this.vTrailer = itemView.findViewById(R.id.account_summary_trailer);
}
}
}