Skip to content

Instantly share code, notes, and snippets.

@Kashif-E
Last active August 3, 2022 21:03
Show Gist options
  • Save Kashif-E/e3edce66cc3dd6af4ec13b1f5e53bbeb to your computer and use it in GitHub Desktop.
Save Kashif-E/e3edce66cc3dd6af4ec13b1f5e53bbeb to your computer and use it in GitHub Desktop.
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
abstract class MyBaseAdapter():
RecyclerView.Adapter<MyBaseAdapter.MyBaseViewHolder>() {
inner class MyBaseViewHolder(private val itemViewBinding: ViewBinding) :
RecyclerView.ViewHolder(itemViewBinding.root) {
fun bindView(binder: (binding: ViewBinding) -> Unit) {
binder(itemViewBinding)
}
}
open var viewBinder: ((ViewGroup) -> ViewBinding)? = null
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyBaseViewHolder {
return viewBinder?.let {
it(parent)
}?.let {
MyBaseViewHolder(it)
}!!
}
override fun getItemCount(): Int {
return getCount()
}
abstract fun getCount():Int
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment