Created
January 15, 2020 16:38
-
-
Save DjakaTechnology/cb9af88c6ec12f52b9524765f28aed7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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