mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 07:29:14 +01:00
theme album screens from their cover art
This commit is contained in:
@@ -50,6 +50,7 @@ import com.subtracks.ui.settings.AddSourceScreen
|
||||
import com.subtracks.ui.settings.AddSourceState
|
||||
import com.subtracks.ui.settings.SettingsScreen
|
||||
import com.subtracks.ui.theme.SubtracksTheme
|
||||
import com.subtracks.ui.theme.artworkColorsFromSeed
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
@@ -120,6 +121,7 @@ class AppScreenshotTest {
|
||||
album = Fixtures.albums.first(),
|
||||
songs = Fixtures.songs,
|
||||
coverArt = { id, _ -> id?.let { CoverArtRef(it, "test:$it") } },
|
||||
artwork = artworkColorsFromSeed(Color.rgb(120, 80, 200)),
|
||||
onBack = {},
|
||||
onSongClick = {},
|
||||
playingSongId = Fixtures.songs.first().id,
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.subtracks.ui.theme
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.luminance
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class ArtworkColorsTest {
|
||||
private val seeds =
|
||||
listOf(
|
||||
0xFF3A7BD5.toInt(),
|
||||
0xFFD53A3A.toInt(),
|
||||
0xFF3AD55F.toInt(),
|
||||
0xFFB0B0B0.toInt(),
|
||||
0x00000000,
|
||||
)
|
||||
|
||||
@Test
|
||||
fun darkBackgroundWithReadableText() {
|
||||
for (seed in seeds) {
|
||||
val scheme = artworkColorsFromSeed(seed).scheme
|
||||
assertTrue("background for $seed", scheme.background.luminance() < 0.1f)
|
||||
assertTrue("onBackground for $seed", contrast(scheme.background, scheme.onBackground) >= 4.5f)
|
||||
assertTrue("primary text for $seed", contrast(scheme.primary, scheme.onPrimary) >= 3f)
|
||||
assertTrue("onSurface for $seed", contrast(scheme.surface, scheme.onSurface) >= 4.5f)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun independentOfAlphaBits() {
|
||||
assertEquals(
|
||||
artworkColorsFromSeed(0xFF3A7BD5.toInt()).scheme.primary,
|
||||
artworkColorsFromSeed(0x3A7BD5).scheme.primary,
|
||||
)
|
||||
}
|
||||
|
||||
private fun contrast(
|
||||
a: Color,
|
||||
b: Color,
|
||||
): Float {
|
||||
val hi = maxOf(a.luminance(), b.luminance())
|
||||
val lo = minOf(a.luminance(), b.luminance())
|
||||
return (hi + 0.05f) / (lo + 0.05f)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user