Skip to content

Instantly share code, notes, and snippets.

@pavlospt
Last active March 29, 2020 20:54
Show Gist options
  • Select an option

  • Save pavlospt/0954329d5885b899594a3182c55998d6 to your computer and use it in GitHub Desktop.

Select an option

Save pavlospt/0954329d5885b899594a3182c55998d6 to your computer and use it in GitHub Desktop.
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.ListAdapter
import androidx.viewbinding.ViewBinding
abstract class ViewBindingAdapter<Item : ViewBindingAdapterItem, VB : ViewBinding>(
diffCallback: ViewBindingDiffUtilCallback<Item>
) : ListAdapter<Item, ViewBindingViewHolder<Item, VB>>(diffCallback) {
override fun onBindViewHolder(holder: ViewBindingViewHolder<Item, VB>, position: Int) =
holder.bind(item = getItem(position))
override fun onBindViewHolder(
holder: ViewBindingViewHolder<Item, VB>,
position: Int,
payloads: MutableList<Any>
) {
holder.bind(item = getItem(position), payloads = payloads)
}
override fun getItemViewType(position: Int): Int = getItem(position).itemViewType
protected val ViewGroup.layoutInflater: LayoutInflater
get() = LayoutInflater.from(this.context)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment