Skip to content

Commit

Permalink
ADS: Fix selected option in RadioListDialog (#2577)
Browse files Browse the repository at this point in the history
  • Loading branch information
nalcalag authored and malmstein committed Jan 12, 2023
1 parent 051f9fb commit 922c83b
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class RadioListAlertDialogBuilder(val context: Context) : DaxAlertDialog {
private set
var optionList: MutableList<CharSequence> = mutableListOf()
private set
var selectedOption = 0
var selectedOption: Int? = null
private set

fun setTitle(@StringRes textId: Int): RadioListAlertDialogBuilder {
Expand All @@ -78,7 +78,7 @@ class RadioListAlertDialogBuilder(val context: Context) : DaxAlertDialog {

fun setOptions(
@StringRes stackedButtonTextId: List<Int>,
selectedItem: Int = 0,
selectedItem: Int? = null,
): RadioListAlertDialogBuilder {
stackedButtonTextId.forEach {
optionList.add(context.getText(it))
Expand Down Expand Up @@ -143,18 +143,20 @@ class RadioListAlertDialogBuilder(val context: Context) : DaxAlertDialog {
binding.radioListDialogMessage.text = messageText
}

optionList.forEach {
optionList.forEachIndexed { index, option ->
val radioButton = RadioButton(context, null)
radioButton.text = it
radioButton.id = index + 1
radioButton.text = option
val params = RadioGroup.LayoutParams(RadioGroup.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT)
radioButton.layoutParams = params
binding.radioListDialogRadioGroup.addView(radioButton)
}

with(binding.radioListDialogRadioGroup) {
check(selectedOption)
setOnCheckedChangeListener { group, checkedId ->
selectedOption?.let { check(it) }
setOnCheckedChangeListener { _, checkedId ->
listener.onRadioItemSelected(checkedId)
binding.radioListDialogPositiveButton.isEnabled = true
}
}

Expand All @@ -163,6 +165,7 @@ class RadioListAlertDialogBuilder(val context: Context) : DaxAlertDialog {
listener.onPositiveButtonClicked(binding.radioListDialogRadioGroup.checkedRadioButtonId)
dialog.dismiss()
}
binding.radioListDialogPositiveButton.isEnabled = selectedOption != null

binding.radioListDialogNegativeButton.text = negativeButtonText
binding.radioListDialogNegativeButton.setOnClickListener {
Expand Down

0 comments on commit 922c83b

Please sign in to comment.