drakeet / MultiType

Flexible multiple types for Android RecyclerView.
Apache License 2.0
5.76k stars 751 forks source link

请问MultiType与AsyncListDiffer如何结合使用 #333

Open liukepeng opened 2 years ago

liukepeng commented 2 years ago

如题

XM-XiaoMa commented 1 month ago

如下

class ConvAdapter : MultiTypeAdapter() { private val asyncListDiffer: AsyncListDiffer = AsyncListDiffer(this, object : DiffUtil.ItemCallback() { override fun areItemsTheSame(oldItem: Any, newItem: Any): Boolean { if (oldItem is ConvBean && newItem is ConvBean) return oldItem.peerUser.uid == newItem.peerUser.uid return false }

        override fun areContentsTheSame(oldItem: Any, newItem: Any): Boolean {
            return if (oldItem is ConvBean && newItem is ConvBean) oldItem == newItem
            else if (oldItem::class == newItem::class) true
            else false
        }
    })

fun submitList(list: List<Any>) {
    items = list
    asyncListDiffer.submitList(list)
}

}