Created
November 13, 2021 10:16
-
-
Save seoft/63ed9c4f4f4cd3b7aa0a65d2f7477db0 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
private val adapter by lazy { | |
DataBindingAdapter<NormalUiModel>( | |
bindingVariableId = BR.item, | |
variables = mapOf(BR.onNormalListener to onNormalListener), | |
object : DiffUtil.ItemCallback<BindingItem<NormalUiModel>>() { | |
override fun areItemsTheSame( | |
oldItem: BindingItem<NormalUiModel>, newItem: BindingItem<NormalUiModel> | |
) = oldItem.item.id == newItem.item.id | |
override fun areContentsTheSame( | |
oldItem: BindingItem<NormalUiModel>, newItem: BindingItem<NormalUiModel> | |
) = oldItem == newItem | |
}) | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
binding.recyclerView.adapter = adapter | |
viewModel.uiModels.observe(this) { uiModels -> | |
adapter.submitList( | |
uiModels.map { | |
when (it) { | |
is NormalUiModel.Monitor -> it.toBindingItem(R.layout.item_normal_monitor) | |
is NormalUiModel.Mouse -> it.toBindingItem(R.layout.item_normal_mouse) | |
is NormalUiModel.Phone -> it.toBindingItem(R.layout.item_normal_phone) | |
} | |
} | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment