Skip to content

Instantly share code, notes, and snippets.

@DjakaTechnology
Created January 15, 2020 16:40
Show Gist options
  • Save DjakaTechnology/f551e7d93478bc8105cf3a429c06d583 to your computer and use it in GitHub Desktop.
Save DjakaTechnology/f551e7d93478bc8105cf3a429c06d583 to your computer and use it in GitHub Desktop.
//If you dont want to use GenericAdapter
class FeedAdapter(var items: List<FeedItem>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private val delegateManager = AdapterDelegateManager<FeedItem>()
init {
delegateManager.run {
addDelegate(FeedPostAdapterDelegate())
addDelegate(FeedStandardAdapterDelegate())
addDelegate(FeedStoryAdapterDelegate())
}
}
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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment