Skip to content

Instantly share code, notes, and snippets.

@DjakaTechnology
Last active January 15, 2020 16:44
Show Gist options
  • Save DjakaTechnology/2ab8bf4c57a5ec5ffc02e6a0cfd29874 to your computer and use it in GitHub Desktop.
Save DjakaTechnology/2ab8bf4c57a5ec5ffc02e6a0cfd29874 to your computer and use it in GitHub Desktop.
class GenericAdapter<T>(var items: List<T>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private val delegateManager = AdapterDelegateManager<T>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return delegateManager.onCreateViewHolder(parent, viewType)
}
override fun getItemCount(): Int {
return items.size
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
delegateManager.onBindViewHolder(items, position, holder)
}
override fun getItemViewType(position: Int): Int {
return delegateManager.getItemViewType(items, position)
}
fun addDelegate(delegate: AdapterDelegate<T>) {
delegateManager.addDelegate(delegate)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment