@Override public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) { int viewType = getItemViewType(position); if (viewType == VIEW_TYPE_ITEM) { ItemViewHolder vh = (ItemViewHolder) viewHolder; Post item = model.get(position); vh.title.setText(item.getTitle()); vh.excerpt.setText(item.getExcerpt()); vh.date.setText(item.getDatePretty()); int thumbnailId = item.getThumbnailId(); if (thumbnailId > 0) { vh.thumbnail.setVisibility(View.VISIBLE); // vh.thumbnail.setImageResource(R.drawable.place_holder_image); // vh.thumbnail.setAdjustViewBounds(true); // vh.thumbnail.setScaleType(ImageView.ScaleType.FIT_CENTER); Context context = vh.thumbnail.getContext(); ImageLoader.enqueue(context, position, thumbnailId, vh.thumbnail); } else { vh.thumbnail.setVisibility(View.GONE); } } else if (viewType == VIEW_TYPE_FOOTER) { FooterViewHolder vh = (FooterViewHolder) viewHolder; vh.progressBar.setIndeterminate(true); } }
@Override public int getItemViewType(int position) { if (position >= model.size()) { return VIEW_TYPE_FOOTER; } return VIEW_TYPE_ITEM; }
@Override public int getItemCount() { return (footerEnabled) ? model.size() + 1 : model.size(); }