Skip to content

Instantly share code, notes, and snippets.

@fnk0
Created October 17, 2016 04:49
Show Gist options
  • Save fnk0/d430cd9b5f28f97b24e175d88d9a1784 to your computer and use it in GitHub Desktop.
Save fnk0/d430cd9b5f28f97b24e175d88d9a1784 to your computer and use it in GitHub Desktop.
public class PersonPresenter extends Presenter {
Context mContext;
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
if (mContext == null) {
// We do this to avoid creating a new ContextThemeWrapper for each one of the cards
// If we look inside the ImageCardView they warn us about the same this.
// Example: Try using the constructor: ImageCardView(context, style)
// It is deprecated right? This is because that constructor creates a new ContextThemeWrapper every time a
// ImageCardView is allocated.
mContext = new ContextThemeWrapper(parent.getContext(), R.style.PersonCardTheme);
}
return new ViewHolder(new ImageCardView(mContext));
}
@Override
public void onBindViewHolder(ViewHolder viewHolder, Object item) {
ImageCardView view = (ImageCardView) viewHolder.view;
CastMember member = (CastMember) item;
Glide.with(view.getContext())
.load(HttpClientModule.POSTER_URL + member.getProfilePath())
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(view.getMainImageView());
view.setTitleText(member.getName());
view.setContentText(member.getCharacter());
}
@Override
public void onUnbindViewHolder(ViewHolder viewHolder) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment