@Override public void onBindViewHolder(BaseViewHolder holder, int position) { LineItem lineItem = (LineItem) getItem(position); GridSLM.LayoutParams lp = GridSLM.LayoutParams.from(holder.itemView.getLayoutParams()); if (lineItem.isHeader) { lp.headerDisplay = LayoutManager.LayoutParams.HEADER_STICKY | LayoutManager.LayoutParams.HEADER_INLINE; lp.headerEndMarginIsAuto = true; lp.headerStartMarginIsAuto = true; ((HeaderViewHolder) holder).header.setText(lineItem.data.toString()); } else { FestPhotoCardViewHolder jHolder = (FestPhotoCardViewHolder) holder; ListCard card = (ListCard) lineItem.data; Context context = jHolder.itemView.getContext(); jHolder.title.setText(card.getVotingTitle()); if (!TextUtils.isEmpty(card.getWin())) { jHolder.win.setVisibility(View.VISIBLE); int color; if ("1".equals(card.getWin())) { color = R.color.gold; } else if ("2".equals(card.getWin())) { color = R.color.silver; } else { color = R.color.bronze; } jHolder.win.setColorFilter(context.getResources().getColor(color)); } else { jHolder.win.setVisibility(View.GONE); } Glide.with(context).load(Utils.getCardImageUrl(context, card)).into(jHolder.photo); } lp.setSlm(LinearSLM.ID); lp.setFirstPosition(lineItem.sectionFirstPosition); holder.itemView.setLayoutParams(lp); }
@Override public void onBindViewHolder(ViewHolder holder, int position) { LineItem item = items.get(position); holder.bindItem(item); GridSLM.LayoutParams layoutParams = GridSLM.LayoutParams.from(holder.itemView.getLayoutParams()); if (item.isHeader) { layoutParams.headerDisplay = LayoutManager.LayoutParams.HEADER_ALIGN_START + LayoutManager.LayoutParams.HEADER_STICKY; layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT; layoutParams.headerEndMarginIsAuto = false; layoutParams.headerStartMarginIsAuto = false; } layoutParams.setSlm(LinearSLM.ID); layoutParams.setFirstPosition(items.get(position).sectionFirstPosition); holder.itemView.setLayoutParams(layoutParams); }
@Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { final LineItem item = mItems.get(position); final View itemView = holder.itemView; if (holder instanceof PersonViewHolder) { final PersonViewHolder pHolder = (PersonViewHolder) holder; final Person person = (Person) item.data; pHolder.bindItem((Person) item.data); pHolder.imgView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { boolean checked = !selected.contains(person); if (checked) { pHolder.checkIcon.setVisibility(View.VISIBLE); pHolder.imgView.setAlpha(0.5f); selected.add(person); } else { pHolder.checkIcon.setVisibility(View.INVISIBLE); pHolder.imgView.setAlpha(1f); selected.remove(person); } if (checkListener != null) { checkListener.onPersonCheck(person, checked, selected); } } }); pHolder.imgView.setAlpha(selected.contains(person) ? 0.5f : 1f); pHolder.checkIcon.setVisibility(selected.contains(person) ? View.VISIBLE : View.INVISIBLE); } else { ((LabelViewHolder) holder).bindItem(item.data.toString()); } final GridSLM.LayoutParams lp = GridSLM.LayoutParams.from(itemView.getLayoutParams()); // Overrides xml attrs, could use different layouts too. if (item.isHeader) { lp.headerDisplay = mHeaderDisplay; if (lp.isHeaderInline() || (mMarginsFixed && !lp.isHeaderOverlay())) { lp.width = ViewGroup.LayoutParams.MATCH_PARENT; } else { lp.width = ViewGroup.LayoutParams.WRAP_CONTENT; } lp.headerEndMarginIsAuto = !mMarginsFixed; lp.headerStartMarginIsAuto = !mMarginsFixed; } lp.setSlm(LinearSLM.ID); lp.setColumnWidth(mContext.getResources().getDimensionPixelSize(R.dimen.grid_column_width)); lp.setFirstPosition(item.sectionFirstPosition); itemView.setLayoutParams(lp); }