Fix radio button selection transition (#1209)

This commit is contained in:
Andrew 2023-05-24 11:23:57 +09:30 committed by GitHub
parent 95a165aa05
commit 945df19aef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -42,6 +42,7 @@ class ClearAllDataDialog : BaseDialog() {
var selectedOption = device
val optionAdapter = RadioOptionAdapter { selectedOption = it }
binding.recyclerView.apply {
itemAnimator = null
adapter = optionAdapter
addItemDecoration(DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL))
setHasFixedSize(true)

View File

@ -16,8 +16,8 @@ class RadioOptionAdapter(
) : ListAdapter<RadioOption, RadioOptionAdapter.ViewHolder>(RadioOptionDiffer()) {
class RadioOptionDiffer: DiffUtil.ItemCallback<RadioOption>() {
override fun areItemsTheSame(oldItem: RadioOption, newItem: RadioOption) = oldItem === newItem
override fun areContentsTheSame(oldItem: RadioOption, newItem: RadioOption) = oldItem == newItem
override fun areItemsTheSame(oldItem: RadioOption, newItem: RadioOption) = oldItem.title == newItem.title
override fun areContentsTheSame(oldItem: RadioOption, newItem: RadioOption) = oldItem.value == newItem.value
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
@ -31,7 +31,7 @@ class RadioOptionAdapter(
holder.bind(option, isSelected) {
onClickListener(it)
selectedOptionPosition = position
notifyDataSetChanged()
notifyItemRangeChanged(0, itemCount)
}
}