mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-07 12:24:58 +10:00
Fix selected position labels when editing on/off/on type switches (#1091)
This commit is contained in:
+39
@@ -35,4 +35,43 @@ public class ToggleSwitchPositionPropertyValueSource extends AbstractDynamicProp
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayValue(Object value) {
|
||||
if (value == null) {
|
||||
return "None";
|
||||
}
|
||||
|
||||
if (properties == null) {
|
||||
return super.getDisplayValue(value);
|
||||
}
|
||||
|
||||
Optional<PropertyWrapper> typeProperty = properties.stream()
|
||||
.filter(p -> {
|
||||
try {
|
||||
return p.getGetter().getName().equals("getValue");
|
||||
} catch (NoSuchMethodException e) {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.findFirst();
|
||||
|
||||
if (typeProperty.isEmpty()) {
|
||||
return super.getDisplayValue(value);
|
||||
}
|
||||
|
||||
ToggleSwitchType switchType =
|
||||
(ToggleSwitchType) typeProperty.get().getValue();
|
||||
|
||||
int position = (Integer) value;
|
||||
|
||||
if (switchType.name().endsWith("_off")) {
|
||||
if (position == 1) {
|
||||
return "OFF";
|
||||
}
|
||||
return "ON" + (position == 0 ? 1 : 2);
|
||||
}
|
||||
|
||||
return "ON" + (position + 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user