diff --git a/pluto-plugins/base/lib/src/main/java/com/pluto/utilities/selector/DataSelector.kt b/pluto-plugins/base/lib/src/main/java/com/pluto/utilities/selector/DataSelector.kt index 15d63aa7..0e69fcba 100644 --- a/pluto-plugins/base/lib/src/main/java/com/pluto/utilities/selector/DataSelector.kt +++ b/pluto-plugins/base/lib/src/main/java/com/pluto/utilities/selector/DataSelector.kt @@ -41,7 +41,9 @@ class Selector : ViewModel() { } abstract class SelectorOption : ListItem() { - abstract fun displayText(): String + abstract fun displayText(): CharSequence + + fun displayTextString(): String = displayText().toString() } internal data class SelectorData(val title: String, val list: List, val preSelected: T?) diff --git a/pluto-plugins/base/lib/src/main/java/com/pluto/utilities/selector/ui/DataSelectorDialog.kt b/pluto-plugins/base/lib/src/main/java/com/pluto/utilities/selector/ui/DataSelectorDialog.kt index 00c1c895..4ec1acc4 100644 --- a/pluto-plugins/base/lib/src/main/java/com/pluto/utilities/selector/ui/DataSelectorDialog.kt +++ b/pluto-plugins/base/lib/src/main/java/com/pluto/utilities/selector/ui/DataSelectorDialog.kt @@ -80,9 +80,12 @@ class DataSelectorDialog : BottomSheetDialogFragment() { object : DiffAwareAdapter.OnActionListener { override fun onAction(action: String, data: ListItem, holder: DiffAwareHolder) { if (data is SelectorOption) { - val tempSet = tempSelectedOptionLiveData.value?.toHashSet() ?: hashSetOf() - if (!tempSet.add(data)) { - tempSet.remove(data) + var tempSet = tempSelectedOptionLiveData.value?.toHashSet() ?: hashSetOf() + val isOptionAlreadyPresent = tempSet.any { it.displayTextString() == data.displayTextString() } + if (isOptionAlreadyPresent) { + tempSet = tempSet.filter { it.displayTextString() != data.displayTextString() }.toHashSet() + } else { + tempSet.add(data) } tempSelectedOptionLiveData.postValue(tempSet.toList()) } diff --git a/pluto-plugins/base/lib/src/main/java/com/pluto/utilities/selector/ui/MultiSelectorAdapter.kt b/pluto-plugins/base/lib/src/main/java/com/pluto/utilities/selector/ui/MultiSelectorAdapter.kt index d9c3843c..85738f11 100644 --- a/pluto-plugins/base/lib/src/main/java/com/pluto/utilities/selector/ui/MultiSelectorAdapter.kt +++ b/pluto-plugins/base/lib/src/main/java/com/pluto/utilities/selector/ui/MultiSelectorAdapter.kt @@ -54,7 +54,8 @@ internal class MultiSelectorItemHolder( selectedLiveData.removeObserver(selectedChoicesObserver) } - private val selectedChoicesObserver = Observer> { - binding.checkbox.isSelected = it?.contains(item) ?: run { false } + private val selectedChoicesObserver = Observer> { list -> + binding.checkbox.isSelected = + item is SelectorOption && list?.any { it.displayTextString() == (item as SelectorOption).displayTextString() } ?: run { false } } } diff --git a/pluto-plugins/base/lib/src/main/java/com/pluto/utilities/selector/ui/SingleSelectorAdapter.kt b/pluto-plugins/base/lib/src/main/java/com/pluto/utilities/selector/ui/SingleSelectorAdapter.kt index 068f3a18..b5b883ac 100644 --- a/pluto-plugins/base/lib/src/main/java/com/pluto/utilities/selector/ui/SingleSelectorAdapter.kt +++ b/pluto-plugins/base/lib/src/main/java/com/pluto/utilities/selector/ui/SingleSelectorAdapter.kt @@ -32,7 +32,7 @@ internal class SingleSelectorItemHolder( binding.title.setSpan { append(item.displayText()) } - binding.radio.isSelected = selected?.let { it == item } ?: run { false } + binding.radio.isSelected = selected?.let { it.displayTextString() == item.displayTextString() } ?: run { false } binding.root.setOnDebounceClickListener { onAction("click") }