Created
May 30, 2021 23:14
-
-
Save k0siara/765963f821c0bac7fc5bfd2eb123c402 to your computer and use it in GitHub Desktop.
DiffUtilCallback.kt
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 DiffUtilCallback( | |
private val oldItems: List, | |
private val newItems: List | |
) : DiffUtil.Callback() { | |
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | |
return oldItems[oldItemPosition].id == newItems[newItemPosition].id | |
} | |
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | |
// It works properly if Item is a data class | |
// Otherwise, we should check if all fields of the items are the same | |
return oldItems[oldItemPosition] == newItems[newItemPosition] | |
} | |
override fun getOldListSize() = oldItems.size | |
override fun getNewListSize() = newItems.size | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment