Skip to content

Instantly share code, notes, and snippets.

@AndrewHaisting
Created December 20, 2017 15:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save AndrewHaisting/63b38e93ae0d00169b564b0f2c67e4fc to your computer and use it in GitHub Desktop.
Save AndrewHaisting/63b38e93ae0d00169b564b0f2c67e4fc to your computer and use it in GitHub Desktop.
override fun onBindViewHolder(holder: ViewHolder,
position: Int,
payloads: MutableList<Any>) {
if (!payloads.isEmpty()) {
// Because these updates can be batched,
// there can be multiple payloads for a single bind
when (payloads[0]) {
Payload.FAVORITE_CHANGE -> {
// Change only the "favorite" icon,
// leave background image alone:
bindFavoriteIcon(holder,
items[position].isFavorited)
}
}
}
// When payload list is empty,
// or we don't have logic to handle a given type,
// default to full bind:
super.onBindViewHolder(holder, position, payloads)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment