Skip to content

Instantly share code, notes, and snippets.

@tonnylitao
Last active June 17, 2020 09:48
Show Gist options
  • Save tonnylitao/8ca1548b5617767849cb036bbf19c19c to your computer and use it in GitHub Desktop.
Save tonnylitao/8ca1548b5617767849cb036bbf19c19c to your computer and use it in GitHub Desktop.
import androidx.recyclerview.widget.DiffUtil
interface RecyclerItem {
val layoutId: Int
val variableId: Int
val dataToBind: Any
val id: Int
override fun equals(other:Any?): Boolean
companion object {
fun <M: RecyclerItem> diffCallback()
= object: DiffUtil.ItemCallback<M>() {
override fun areItemsTheSame(od:M, nw:M)
= od === nw || od.id == nw.id
override fun areContentsTheSame(od:M, nw:M)
= od == nw
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment