Created
April 5, 2020 13:32
-
-
Save klukwist/612eaebbdb2df2a5aaa403690ed1e727 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
open class ProstoHolder<TBinding : ViewDataBinding>(val binding: TBinding) : RecyclerView.ViewHolder(binding.root) { | |
open fun <TData, TViewModel : ProstoViewModel<TData>> bind(viewModel: TViewModel, position: Int) { | |
binding.setVariable(BR.viewModel, viewModel) | |
binding.setVariable(BR.position, position) | |
binding.executePendingBindings() | |
} | |
companion object { | |
fun <TBinding : ViewDataBinding> create(parent: ViewGroup, layoutId: Int): ProstoHolder<TBinding> { | |
val inflater = LayoutInflater.from(parent.context) | |
val binding: TBinding = DataBindingUtil.inflate(inflater, layoutId, parent, false) | |
return ProstoHolder(binding) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment