From 5c58813e5530aa557e19e5532d9d1f0c9c449782 Mon Sep 17 00:00:00 2001 From: mueller-ma Date: Mon, 29 Apr 2024 18:00:56 +0200 Subject: [PATCH] Special handling for icon=none only for oh source (#3662) See https://github.com/openhab/openhab-webui/pull/2534 Signed-off-by: mueller-ma --- .../org/openhab/habdroid/model/IconResource.kt | 10 ++++++---- .../org/openhab/habdroid/model/IconResourceTest.kt | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) 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 309bb98bc9..470d29af33 100644 --- a/mobile/src/main/java/org/openhab/habdroid/model/IconResource.kt +++ b/mobile/src/main/java/org/openhab/habdroid/model/IconResource.kt @@ -20,7 +20,6 @@ import android.net.Uri import android.os.Parcelable import androidx.annotation.VisibleForTesting import java.util.Locale -import kotlin.text.replace import kotlinx.parcelize.Parcelize import org.json.JSONException import org.json.JSONObject @@ -150,12 +149,15 @@ fun SharedPreferences.Editor.putIconResource(key: String, icon: IconResource?): return this } +@VisibleForTesting +fun String.isNoneIcon() = "(oh:([a-z]+:)?)?none".toRegex().matches(this) + fun String?.toOH1IconResource(): IconResource? { - return if (isNullOrEmpty() || this == "none") null else IconResource(this, false, "") + return if (isNullOrEmpty() || isNoneIcon()) null else IconResource(this, false, "") } fun String?.toOH2IconResource(): IconResource? { - return if (isNullOrEmpty() || this == "none") null else IconResource(this, true, "") + return if (isNullOrEmpty() || isNoneIcon()) null else IconResource(this, true, "") } internal fun String?.toOH2WidgetIconResource( @@ -164,7 +166,7 @@ internal fun String?.toOH2WidgetIconResource( hasMappings: Boolean, useState: Boolean ): IconResource? { - if (isNullOrEmpty() || this == "none") { + if (isNullOrEmpty() || isNoneIcon()) { return null } diff --git a/mobile/src/test/java/org/openhab/habdroid/model/IconResourceTest.kt b/mobile/src/test/java/org/openhab/habdroid/model/IconResourceTest.kt index 8f35d1199e..ca0f8d636a 100644 --- a/mobile/src/test/java/org/openhab/habdroid/model/IconResourceTest.kt +++ b/mobile/src/test/java/org/openhab/habdroid/model/IconResourceTest.kt @@ -70,6 +70,20 @@ class IconResourceTest { } } + @Test + fun testIsNoneIcon() { + mapOf( + "none" to true, + "oh:none" to true, + "oh:classic:none" to true, + "oh:foo:none" to true, + "f7:none" to false, + "lights" to false + ).forEach { + assertEquals("${it.key} failed", it.key.isNoneIcon(), it.value) + } + } + private fun testIconToUrl(icon: String, url: String) { assertEquals( "$icon icon failed!",