-
-
Save kozmi55/70737a89923e3b0a1370b891589791a6 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
@BindingAdapter("itemViewModels") | |
fun bindItemViewModels(recyclerView: RecyclerView, itemViewModels: List<ItemViewModel>?) { | |
val adapter = getOrCreateAdapter(recyclerView) | |
adapter.updateItems(itemViewModels) | |
} | |
private fun getOrCreateAdapter(recyclerView: RecyclerView): BindableRecyclerViewAdapter { | |
return if (recyclerView.adapter != null && recyclerView.adapter is BindableRecyclerViewAdapter) { | |
recyclerView.adapter as BindableRecyclerViewAdapter | |
} else { | |
val bindableRecyclerAdapter = BindableRecyclerViewAdapter() | |
recyclerView.adapter = bindableRecyclerAdapter | |
bindableRecyclerAdapter | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment