Skip to content

Instantly share code, notes, and snippets.

@ercnksgl
Created September 22, 2022 14:16
Show Gist options
  • Save ercnksgl/da0470d05a8733a0bb5ebc5f39e68928 to your computer and use it in GitHub Desktop.
Save ercnksgl/da0470d05a8733a0bb5ebc5f39e68928 to your computer and use it in GitHub Desktop.
DiffUtils.kt for DiffUtils tutorial
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