Created
July 19, 2018 14:15
-
-
Save vorobeij/a86ee2e4fc0428c1d8b25a5ac4d923f6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| open class BaseDiffCallback<T>( | |
| var itemsOld: List<T> = listOf(), | |
| var itemsNew: List<T> = listOf() | |
| ) : DiffUtil.Callback() { | |
| lateinit var areItemsTheSame: ((oldItemPosition: Int, newItemPosition: Int) -> Boolean) | |
| lateinit var areContentTheSame: ((oldItemPosition: Int, newItemPosition: Int) -> Boolean) | |
| override fun getOldListSize(): Int = itemsOld.size | |
| override fun getNewListSize(): Int = itemsNew.size | |
| override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | |
| return areItemsTheSame.invoke(oldItemPosition, newItemPosition) | |
| } | |
| override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | |
| return areContentTheSame.invoke(oldItemPosition, newItemPosition) | |
| } | |
| } |
This file contains hidden or 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
| private val diffCallback = BaseDiffCallback<User>().apply { | |
| areItemsTheSame = { oldItemPosition, newItemPosition -> | |
| itemsOld[oldItemPosition].id == itemsNew[newItemPosition].id | |
| } | |
| areContentTheSame = { oldItemPosition, newItemPosition -> true } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment