]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java
account list: add hollow trailing item
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / account_summary / AccountSummaryAdapter.java
index 6c6f4a7624a5c48e0e05bd4532f6401e94f06610..6f3e4f2b29b1948b226bea5d2a69f8ac8657d373 100644 (file)
@@ -34,6 +34,8 @@ import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerAccount;
 
 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;
 
 class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAdapter.LedgerRowHolder> {
     private boolean selectionActive;
 
@@ -42,40 +44,49 @@ class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAdapter.L
     }
 
     public void onBindViewHolder(@NonNull LedgerRowHolder holder, int position) {
     }
 
     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 {
         }
         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
     }
 
     @NonNull
@@ -88,7 +99,7 @@ class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAdapter.L
 
     @Override
     public int getItemCount() {
 
     @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());
     }
     public void startSelection() {
         for (LedgerAccount acc : Data.accounts.get()) acc.setHiddenToBe(acc.isHidden());
@@ -127,12 +138,14 @@ class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAdapter.L
         CheckBox selectionCb;
         TextView tvAccountName, tvAccountAmounts;
         LinearLayout row;
         CheckBox selectionCb;
         TextView tvAccountName, tvAccountAmounts;
         LinearLayout row;
+        View vTrailer;
         public LedgerRowHolder(@NonNull View itemView) {
             super(itemView);
         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.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);
         }
     }
 }
         }
     }
 }