Skip to content

Instantly share code, notes, and snippets.

@manoj-mili
Created August 9, 2020 19:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-mili/bc7fca2af25fd323e6a78b65266a29e5 to your computer and use it in GitHub Desktop.
Save manoj-mili/bc7fca2af25fd323e6a78b65266a29e5 to your computer and use it in GitHub Desktop.
Implementing Recyclerview Adapter with DiffCallBack
class PostAdapter :
ListAdapter<Post, PostAdapter.ViewHolder>(TaskDiffCallBack()) {
//This check runs on background thread
class TaskDiffCallBack : DiffUtil.ItemCallback<Post>() {
override fun areItemsTheSame(oldItem: Post, newItem: Post): Boolean {
Log.d(TAG,Thread.currentThread().name)
return oldItem.id == newItem.id;
}
override fun areContentsTheSame(oldItem: Post, newItem: Post): Boolean {
Log.d(TAG,Thread.currentThread().name)
return oldItem == newItem
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment