Skip to content

Instantly share code, notes, and snippets.

@CDRussell
Created March 21, 2018 01:44
Show Gist options
  • Save CDRussell/2e9b046c73303a45a8f0d1fd88c702f3 to your computer and use it in GitHub Desktop.
Save CDRussell/2e9b046c73303a45a8f0d1fd88c702f3 to your computer and use it in GitHub Desktop.
class TaskDiffCallback : DiffUtil.ItemCallback<Task>() {
override fun areItemsTheSame(oldItem: Task?, newItem: Task?): Boolean {
return oldItem?.id == newItem?.id
}
override fun areContentsTheSame(oldItem: Task?, newItem: Task?): Boolean {
return oldItem == newItem
}
}
@jamesmporter
Copy link

jamesmporter commented Oct 31, 2018

Thanks for this, it's very helpful.
Just as a comment, I'm not sure if I'm using a different version of DiffUtil, but the parameters of the two methods are specified as @nonnull, hence the ? needs to be removed on them to make this work. I'm no expert, so I welcome your opinion on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment