Last active
April 14, 2020 11:17
-
-
Save justtwago/8af65eb258d038bbf430e6103d340f89 to your computer and use it in GitHub Desktop.
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