Skip to content

Instantly share code, notes, and snippets.

@kozmi55
Created August 16, 2021 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kozmi55/1d6e71466b96d0b832cbd6aaf93043a8 to your computer and use it in GitHub Desktop.
Save kozmi55/1d6e71466b96d0b832cbd6aaf93043a8 to your computer and use it in GitHub Desktop.
interface ItemViewModel {
...
val bindableProperties: Map<Int, Any>
}
class CarAdViewModel(val make: String, val model: String, val price: String) : ItemViewModel {
...
override val bindableProperties: Map<Int, Any> = mapOf(
BR.make to make,
BR.model to model
)
}
class BindableViewHolder(private val binding: ViewDataBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(itemViewModel: ItemViewModel) {
itemViewModel.bindableProperties.entries.forEach {
binding.setVariable(it.key, it.value)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment