Skip to content

Instantly share code, notes, and snippets.

@roschlau
Last active March 5, 2017 00:38
Show Gist options
  • Save roschlau/2c57f050222a51cf7002a8a17c03082d to your computer and use it in GitHub Desktop.
Save roschlau/2c57f050222a51cf7002a8a17c03082d to your computer and use it in GitHub Desktop.
Default implementation of a DiffUtil.Callback
import android.support.v7.util.DiffUtil
open class DiffUtilCallback<T>(val oldList: List<T>, val newList: List<T>) : DiffUtil.Callback() {
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int)
= oldList[oldItemPosition] == newList[newItemPosition]
override fun getOldListSize()
= oldList.size
override fun getNewListSize()
= newList.size
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int)
= oldList[oldItemPosition] == newList[newItemPosition]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment