Created
August 9, 2020 19:04
-
-
Save manoj-mili/bc7fca2af25fd323e6a78b65266a29e5 to your computer and use it in GitHub Desktop.
Implementing Recyclerview Adapter with DiffCallBack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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