Skip to content

Instantly share code, notes, and snippets.

@fvilarino
Created April 19, 2021 21:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fvilarino/108addf40048dffa2e7f2e0b702668b0 to your computer and use it in GitHub Desktop.
Forecast ViewHolders
class ForecastHeaderViewHolder(
binding: ViewholderForecastHeaderBinding
) : RecyclerViewViewHolder<ForecastHeaderBindingItem>(binding) {
override fun bind(bindingItem: ForecastHeaderBindingItem) {
(binding as ViewholderForecastHeaderBinding).state = bindingItem.forecastHeaderState
binding.executePendingBindings()
}
}
class ForecastCardViewHolder(
binding: ViewholderForecastCardBinding
) : RecyclerViewViewHolder<ForecastCardBindingItem>(binding) {
override fun bind(bindingItem: ForecastCardBindingItem) {
(binding as ViewholderForecastCardBinding).state = bindingItem.forecastCardState
binding.executePendingBindings()
}
}
class ForecastHeaderBindingItem(
val forecastHeaderState: ForecastHeaderState
) : RecyclerViewBindingItem, Diffable by forecastHeaderState {
override val type: Int = R.layout.viewholder_forecast_header
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewViewHolder<*> {
val binding = ViewholderForecastHeaderBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
return ForecastHeaderViewHolder(binding)
}
}
class ForecastCardBindingItem(
val forecastCardState: ForecastCardState
) : RecyclerViewBindingItem, Diffable by forecastCardState {
override val type: Int = R.layout.viewholder_forecast_card
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewViewHolder<*> {
val binding = ViewholderForecastCardBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
return ForecastCardViewHolder(binding)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment