Created
April 19, 2021 21:07
-
-
Save fvilarino/108addf40048dffa2e7f2e0b702668b0 to your computer and use it in GitHub Desktop.
Forecast ViewHolders
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
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