Created
December 11, 2018 07:23
-
-
Save plusmobileapps/29b1c6b016f8b81ea52d99c5a2384564 to your computer and use it in GitHub Desktop.
This file contains 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
abstract class BaseViewHolder<T>(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
abstract fun bind(data: T) | |
} | |
class CardViewHolder(itemView: View, | |
private val glide: RequestManager, | |
private val clickListener: (DataWrapper.CardData) -> Unit, | |
private val deleteListener: (DataWrapper.CardData) -> Unit) : BaseViewHolder<DataWrapper.CardData>(itemView) { | |
private val header = itemView.findViewById<TextView>(R.id.header) | |
private val body = itemView.findViewById<TextView>(R.id.body) | |
private val image = itemView.findViewById<ImageView>(R.id.image) | |
private val deleteButton = itemView.findViewById<ImageView>(R.id.delete_button) | |
override fun bind(data: DataWrapper.CardData) { | |
header.text = data.header | |
body.text = data.body | |
glide.load(data.imageUrl).into(image) | |
itemView.setOnClickListener { clickListener(data) } | |
deleteButton.setOnClickListener { deleteListener(data) } | |
} | |
} | |
class CarouselViewHolder(itemView: View, clickListener: (CarouselItem) -> Unit) : BaseViewHolder<List<CarouselItem>>(itemView) { | |
private val recyclerView = itemView.findViewById<RecyclerView>(R.id.carousel_recyclerview) | |
private val adapter = CarouselListAdapter(clickListener) | |
init { | |
recyclerView.adapter = adapter | |
} | |
override fun bind(data: List<CarouselItem>) = adapter.submitList(data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment