diff --git a/dachlatten-compose/src/main/kotlin/de/sipgate/dachlatten/compose/asset/DisplayableAssetExt.kt b/dachlatten-compose/src/main/kotlin/de/sipgate/dachlatten/compose/asset/DisplayableAssetExt.kt index 4a98eef..3b1e3c4 100644 --- a/dachlatten-compose/src/main/kotlin/de/sipgate/dachlatten/compose/asset/DisplayableAssetExt.kt +++ b/dachlatten-compose/src/main/kotlin/de/sipgate/dachlatten/compose/asset/DisplayableAssetExt.kt @@ -2,12 +2,13 @@ package de.sipgate.dachlatten.compose.asset import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.runtime.Composable -import de.sipgate.dachlatten.asset.DisplayableAsset import de.sipgate.dachlatten.asset.AssetUrl +import de.sipgate.dachlatten.asset.DisplayableAsset @Composable -fun DisplayableAsset.getThemeDependingUri(): AssetUrl = - when { - isSystemInDarkTheme() -> dark ?: light - else -> light - } +fun DisplayableAsset.resolve( + useDarkMode: Boolean = isSystemInDarkTheme() +): AssetUrl = when { + useDarkMode -> dark ?: light + else -> light +} diff --git a/dachlatten-compose/src/test/kotlin/de/sipgate/dachlatten/compose/asset/DisplayableAssetTest.kt b/dachlatten-compose/src/test/kotlin/de/sipgate/dachlatten/compose/asset/DisplayableAssetTest.kt index 3dc7405..ea93cbc 100644 --- a/dachlatten-compose/src/test/kotlin/de/sipgate/dachlatten/compose/asset/DisplayableAssetTest.kt +++ b/dachlatten-compose/src/test/kotlin/de/sipgate/dachlatten/compose/asset/DisplayableAssetTest.kt @@ -45,9 +45,19 @@ class DisplayableAssetTest { expectResolvedComposeUrl(lightModeVariantUrl, image) } - private fun expectResolvedComposeUrl(expected: String, image: DisplayableAsset) { + @Test + @Config(qualifiers = "notnight") + fun urlResolvesToDarkVariantInLightModeWhenExplicitlyRequested() { + expectResolvedComposeUrl(darkModeVariantUrl, image, true) + } + + private fun expectResolvedComposeUrl(expected: String, image: DisplayableAsset, useDarkMode: Boolean? = null) { composeTestRule.setContent { - val resolvedString = image.getThemeDependingUri() + val resolvedString = if (useDarkMode != null) { + image.resolve(useDarkMode) + } else { + image.resolve() + } assertEquals(expected, resolvedString) } }