Last active
March 29, 2020 20:54
-
-
Save pavlospt/0954329d5885b899594a3182c55998d6 to your computer and use it in GitHub Desktop.
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 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