Skip to content

Commit

Permalink
Special handling for icon=none only for oh source (#3662)
Browse files Browse the repository at this point in the history
See openhab/openhab-webui#2534

Signed-off-by: mueller-ma <mueller-ma@users.noreply.github.com>
  • Loading branch information
mueller-ma authored Apr 29, 2024
1 parent ce0c0eb commit 5c58813
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
10 changes: 6 additions & 4 deletions mobile/src/main/java/org/openhab/habdroid/model/IconResource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -164,7 +166,7 @@ internal fun String?.toOH2WidgetIconResource(
hasMappings: Boolean,
useState: Boolean
): IconResource? {
if (isNullOrEmpty() || this == "none") {
if (isNullOrEmpty() || isNoneIcon()) {
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down

0 comments on commit 5c58813

Please sign in to comment.