Created
September 22, 2022 14:16
-
-
Save ercnksgl/da0470d05a8733a0bb5ebc5f39e68928 to your computer and use it in GitHub Desktop.
DiffUtils.kt for DiffUtils tutorial
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
import androidx.recyclerview.widget.DiffUtil | |
class CustomDiffUtils<T>( | |
private val oldList: List<T>, | |
private val newList: List<T> | |
) : DiffUtil.Callback() { | |
override fun getOldListSize() = oldList.size | |
override fun getNewListSize() = newList.size | |
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | |
return oldList[oldItemPosition].toString() == newList[newItemPosition].toString() | |
} | |
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | |
return oldList[oldItemPosition] == newList[newItemPosition] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment