Skip to content

Instantly share code, notes, and snippets.

@DjakaTechnology
Created January 15, 2020 16:38
Show Gist options
  • Save DjakaTechnology/1277d6d8b83f8e5d5155d4c7bc335521 to your computer and use it in GitHub Desktop.
Save DjakaTechnology/1277d6d8b83f8e5d5155d4c7bc335521 to your computer and use it in GitHub Desktop.
class FeedStandardAdapterDelegate : AdapterDelegate<FeedItem> {
override fun isForViewType(items: List<FeedItem>, position: Int): Boolean {
return items[position] is FeedStandardItem
}
override fun onCreateViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
return ItemStandardViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.feed_standard_item, parent, false)
)
}
override fun onBindViewHolder(items: List<FeedItem>, position: Int, holder: RecyclerView.ViewHolder) {
(holder as ItemStandardViewHolder).bind(items[position] as FeedStandardItem)
}
class ItemStandardViewHolder(view: View): RecyclerView.ViewHolder(view) {
fun bind(item: FeedStandardItem) {
itemView.text_title.text = item.title
itemView.text_author.text = item.author
itemView.text_duration.text = item.duration
Glide.with(itemView.image_main.context).load(item.imageUrl).into(itemView.image_main)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment