Skip to content

Instantly share code, notes, and snippets.

@DjakaTechnology
Created January 15, 2020 16:38
Show Gist options
  • Save DjakaTechnology/cb9af88c6ec12f52b9524765f28aed7c to your computer and use it in GitHub Desktop.
Save DjakaTechnology/cb9af88c6ec12f52b9524765f28aed7c to your computer and use it in GitHub Desktop.
class FeedPostAdapterDelegate : AdapterDelegate<FeedItem> {
override fun isForViewType(items: List<FeedItem>, position: Int): Boolean {
return items[position] is FeedPostItem
}
override fun onCreateViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
return ItemPostViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.feed_post_item, parent, false)
)
}
override fun onBindViewHolder(items: List<FeedItem>, position: Int, holder: RecyclerView.ViewHolder) {
(holder as ItemPostViewHolder).bind(items[position] as FeedPostItem)
}
class ItemPostViewHolder(view: View): RecyclerView.ViewHolder(view) {
fun bind(item: FeedPostItem) {
itemView.text_title.text = item.title
itemView.text_content.text = item.content
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