Skip to content

Commit

Permalink
Merge branch 'develop' into pref2dataselector
Browse files Browse the repository at this point in the history
  • Loading branch information
srtvprateek authored Mar 30, 2024
2 parents 0f9a67d + 800de54 commit dfeadd1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(val title: String, val list: List<SelectorOption>, val preSelected: T?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ internal class MultiSelectorItemHolder(
selectedLiveData.removeObserver(selectedChoicesObserver)
}

private val selectedChoicesObserver = Observer<List<SelectorOption>> {
binding.checkbox.isSelected = it?.contains(item) ?: run { false }
private val selectedChoicesObserver = Observer<List<SelectorOption>> { list ->
binding.checkbox.isSelected =
item is SelectorOption && list?.any { it.displayTextString() == (item as SelectorOption).displayTextString() } ?: run { false }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit dfeadd1

Please sign in to comment.