Created
January 15, 2020 16:38
-
-
Save DjakaTechnology/1277d6d8b83f8e5d5155d4c7bc335521 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 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