Skip to content

Instantly share code, notes, and snippets.

@amyu
Last active March 31, 2017 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amyu/1e4058b67b21fb11c060eee2f879c81b to your computer and use it in GitHub Desktop.
Save amyu/1e4058b67b21fb11c060eee2f879c81b to your computer and use it in GitHub Desktop.
import android.support.v7.util.DiffUtil
class DiffUtilCallback<T>(private val oldList: List<T>, private val newList: List<T>) : DiffUtil.Callback() {
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean = oldList[oldItemPosition] == newList[newItemPosition]
override fun getOldListSize(): Int = oldList.size
override fun getNewListSize(): Int = newList.size
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean = oldList[oldItemPosition]?.hashCode() == newList[newItemPosition]?.hashCode()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment