Repository: openhab/openhab-android (language: kotlin)

Issue:
Update parsing of icon name
https://github.com/openhab/openhab-webui/pull/1766


Discussion hints:
nan

Pull request: Update parsing of icon name
Closes #3295

Test command: ./gradlew :mobile:testFossBetaDebugUnitTest --tests "org.openhab.habdroid.model.WidgetTest"

Fix patch:
diff --git a/mobile/src/main/java/org/openhab/habdroid/model/IconResource.kt b/mobile/src/main/java/org/openhab/habdroid/model/IconResource.kt
index 3b55f62d61..17b1c89f9e 100644
--- a/mobile/src/main/java/org/openhab/habdroid/model/IconResource.kt
+++ b/mobile/src/main/java/org/openhab/habdroid/model/IconResource.kt
@@ -47,17 +47,19 @@ data class IconResource internal constructor(
         var iconName = "none"
         var iconSet = "classic"
 
-        val segments = icon.split(":")
+        val segments = icon.split(":", limit = 3)
         when (segments.size) {
             1 -> iconName = segments[0]
             2 -> {
-                // segments[0] is the icon source, which we don't support
+                iconSet = segments[0]
                 iconName = segments[1]
             }
             3 -> {
-                // segments[0] is the icon source, which we don't support
-                iconSet = segments[1]
-                iconName = segments[2]
+                // Keep iconName=none for unsupported icon sources
+                if (segments[0] == "oh") {
+                    iconSet = segments[1]
+                    iconName = segments[2]
+                }
             }
         }
 


Test patch:
diff --git a/mobile/src/test/java/org/openhab/habdroid/model/WidgetTest.kt b/mobile/src/test/java/org/openhab/habdroid/model/WidgetTest.kt
index e7c6eb23db..4a2f275c25 100644
--- a/mobile/src/test/java/org/openhab/habdroid/model/WidgetTest.kt
+++ b/mobile/src/test/java/org/openhab/habdroid/model/WidgetTest.kt
@@ -79,6 +79,11 @@ class WidgetTest {
             "icon/rollershutter?format=SVG&anyFormat=true&iconset=mdi&state=42",
             sut3[3].icon?.toUrl(true, IconFormat.Svg)
         )
+        assertEquals(
+            "Iconset must be extracted from icon name",
+            "icon/frame?format=SVG&anyFormat=true&iconset=mdi",
+            sut3[0].icon?.toUrl(false, IconFormat.Svg)
+        )
         assertEquals(
             "If data saver is active, icon paths must not contain a state",
             "icon/rollershutter?format=SVG&anyFormat=true&iconset=mdi",
@@ -362,7 +367,7 @@ class WidgetTest {
                   'widgetId': '0202_0',
                   'type': 'Frame',
                   'label': 'Percent-based Widgets',
-                  'icon': 'frame',
+                  'icon': 'mdi:frame',
                   'mappings': [],
                   'widgets': [ {
                     'widgetId': '0202_0_0',