Skip to content

Commit

Permalink
Recognize iconify URLs as icons for caching
Browse files Browse the repository at this point in the history
Signed-off-by: mueller-ma <mueller-ma@users.noreply.github.com>
  • Loading branch information
mueller-ma committed Jul 16, 2024
1 parent 379dfc2 commit 4f80e91
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ data class IconResource internal constructor(
when (iconSource) {
"if", "iconify" -> {
builder.scheme("https")
.authority("api.iconify.design")
.authority(ICONIFY_API_URL)
.path(iconSet)
.appendPath("$iconName.svg")
.appendQueryParameter("height", desiredSizePixels.toString())
Expand Down Expand Up @@ -121,6 +121,10 @@ data class IconResource internal constructor(
fun withCustomState(state: String): IconResource {
return IconResource(icon, isOh2, state)
}

companion object {
public const val ICONIFY_API_URL = "api.iconify.design"
}
}

fun SharedPreferences.getIconResource(key: String): IconResource? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import okhttp3.Cache
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import org.openhab.habdroid.model.IconFormat
import org.openhab.habdroid.model.IconResource

class CacheManager private constructor(appContext: Context) {
val httpCache: Cache = Cache(File(appContext.cacheDir, "http"), (10 * 1024 * 1024).toLong())
Expand Down Expand Up @@ -61,7 +62,8 @@ class CacheManager private constructor(appContext: Context) {
}
}

private fun HttpUrl.isIconUrl() = pathSegments.firstOrNull() == "icon" && pathSegments[1].isNotEmpty()
private fun HttpUrl.isIconUrl() = host == IconResource.ICONIFY_API_URL ||
(pathSegments.firstOrNull() == "icon" && pathSegments[1].isNotEmpty())

fun isBitmapCached(url: HttpUrl, @ColorInt fallbackColor: Int): Boolean {
return getCachedBitmap(url, fallbackColor) != null
Expand Down

0 comments on commit 4f80e91

Please sign in to comment.