Last active
June 17, 2020 09:48
-
-
Save tonnylitao/8ca1548b5617767849cb036bbf19c19c to your computer and use it in GitHub Desktop.
RecyclerItem, a abstract item in RecyclerView for https://medium.com/@tonny/recyclerview-2020-when-recyclerview-meets-data-binding-616ca5c2147d
This file contains hidden or 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 | |
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