Skip to content

Commit

Permalink
SelectionBottomSheet: send command when clicking on the selected value (
Browse files Browse the repository at this point in the history
#3820)

Signed-off-by: mueller-ma <[email protected]>
  • Loading branch information
mueller-ma authored Oct 27, 2024
1 parent e4ab2b2 commit 3876a0d
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class SliderBottomSheet : AbstractWidgetBottomSheet(), WidgetSlider.UpdateListen
}
}

class SelectionBottomSheet : AbstractWidgetBottomSheet(), RadioGroup.OnCheckedChangeListener {
class SelectionBottomSheet : AbstractWidgetBottomSheet() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.bottom_sheet_selection, container, false)
val group = view.findViewById<RadioGroup>(R.id.group)
Expand All @@ -108,23 +108,18 @@ class SelectionBottomSheet : AbstractWidgetBottomSheet(), RadioGroup.OnCheckedCh
radio.id = mapping.hashCode()
radio.text = mapping.label
radio.isChecked = stateString == mapping.value
radio.setOnClickListener {
connection?.httpClient?.sendItemCommand(widget.item, mapping.value)
dismissAllowingStateLoss()
}
group.addView(radio)
}
group.setOnCheckedChangeListener(this)

view.findViewById<TextView>(R.id.title).apply {
text = widget.label
}
return view
}

override fun onCheckedChanged(group: RadioGroup?, id: Int) {
val mapping = widget.mappingsOrItemOptions.firstOrNull { mapping -> mapping.hashCode() == id }
if (mapping != null) {
connection?.httpClient?.sendItemCommand(widget.item, mapping.value)
}
dismissAllowingStateLoss()
}
}

class ColorChooserBottomSheet : AbstractWidgetBottomSheet() {
Expand Down

0 comments on commit 3876a0d

Please sign in to comment.