Skip to content

Commit

Permalink
Fix switch vs. section switch choice logic
Browse files Browse the repository at this point in the history
Make sure that item type 'Switch' leads to a normal switch even in case
item options are present on that item.

Mentioned in the forum:
https://community.openhab.org/t/problem-with-displaying-switch-item-in-the-android-app/162188

Signed-off-by: Danny Baumann <[email protected]>
  • Loading branch information
maniac103 committed Feb 7, 2025
1 parent b1b094d commit de9c38b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mobile/src/main/java/org/openhab/habdroid/ui/WidgetAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,10 @@ class WidgetAdapter(
Widget.Type.Group -> TYPE_GROUP
Widget.Type.Switch -> when {
widget.shouldRenderAsPlayer() -> TYPE_PLAYER
widget.mappingsOrItemOptions.size in 1..2 && !compactMode -> TYPE_SECTIONSWITCH_SMALL
widget.mappings.isNotEmpty() -> TYPE_SECTIONSWITCH
widget.mappings.isNotEmpty() -> determineSectionSwitchType(widget.mappings)
widget.item?.isOfTypeOrGroupType(Item.Type.Switch) == true -> TYPE_SWITCH
widget.item?.isOfTypeOrGroupType(Item.Type.Rollershutter) == true -> TYPE_ROLLERSHUTTER
widget.mappingsOrItemOptions.isNotEmpty() -> TYPE_SECTIONSWITCH
widget.mappingsOrItemOptions.isNotEmpty() -> determineSectionSwitchType(widget.mappingsOrItemOptions)
else -> TYPE_SWITCH
}
Widget.Type.Text -> TYPE_TEXT
Expand All @@ -403,6 +402,9 @@ class WidgetAdapter(
return toInternalViewType(actualViewType, compactMode)
}

private fun determineSectionSwitchType(mappings: List<LabeledValue>) =
if (mappings.size in 1..2 && !compactMode) TYPE_SECTIONSWITCH_SMALL else TYPE_SECTIONSWITCH

data class ViewHolderInitData(
val inflater: LayoutInflater,
val parent: ViewGroup,
Expand Down

0 comments on commit de9c38b

Please sign in to comment.