Skip to content

Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.

Light and dark, and colours the records own

Lelonio871bc9a60a07
diff --git a/app/src/main/java/dev/lelonio/square/data/AppleCatalog.kt b/app/src/main/java/dev/lelonio/square/data/AppleCatalog.kt
index ecb08e8..c5c51ec 100644
--- a/app/src/main/java/dev/lelonio/square/data/AppleCatalog.kt
+++ b/app/src/main/java/dev/lelonio/square/data/AppleCatalog.kt
@@ -6,6 +6,7 @@ import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
+import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
@@ -80,7 +81,7 @@ object AppleCatalog {
// bigger pictures means the old rows are answers to a different
// question. A new name retires them in one line.
store = context.getSharedPreferences(
- "apple-catalog-v5",
+ "apple-catalog-v7",
android.content.Context.MODE_PRIVATE,
)
}
@@ -136,6 +137,20 @@ object AppleCatalog {
* same picture lands somewhere near it and often on a skin tone.
*/
val bgColor: String? = null,
+ /** The picture's own proportions, width over height. */
+ val heroAspect: Float? = null,
+ /** The ink the catalogue picked for that ground; see textColor1. */
+ val textHex: String? = null,
+ /**
+ * The four inks filed with the picture, brightest first.
+ *
+ * They are not a theme — they are colours taken out of this artwork and
+ * chosen to sit together on it, which is exactly what a light moving
+ * behind the cover needs. A palette worked out here instead pulls
+ * whatever the swatch extractor finds most vivid, and on a crimson
+ * sleeve with a black rose on it that came back blue.
+ */
+ val inkPalette: List<String> = emptyList(),
/** What Apple's editors wrote about it, where they wrote anything. */
val notes: String? = null,
/**
@@ -155,6 +170,20 @@ object AppleCatalog {
val heroUrl: String?,
/** The page's own tint, as six hex digits; see Album.bgColor. */
val bgColor: String? = null,
+ /** The picture's own proportions, width over height. */
+ val heroAspect: Float? = null,
+ /** The ink the catalogue picked for that ground; see textColor1. */
+ val textHex: String? = null,
+ /**
+ * The four inks filed with the picture, brightest first.
+ *
+ * They are not a theme — they are colours taken out of this artwork and
+ * chosen to sit together on it, which is exactly what a light moving
+ * behind the cover needs. A palette worked out here instead pulls
+ * whatever the swatch extractor finds most vivid, and on a crimson
+ * sleeve with a black rose on it that came back blue.
+ */
+ val inkPalette: List<String> = emptyList(),
/** What Apple's editors wrote about them, where they wrote anything. */
val bio: String? = null,
/** Where they are from, or where the band was formed. */
@@ -365,16 +394,65 @@ object AppleCatalog {
// picture — the vertical crop, framed on the face. The default `bb`
// fits the whole square inside the frame and pads the rest, which on a
// header this tall is two bars of flat colour.
- val hero = attributes["artwork"]?.jsonObject?.template()
- ?: editorial?.get("subscriptionHero")?.jsonObject?.template()
+ // The picture and the colour have to come out of the same row.
+ //
+ // The colour was read off `artwork` alone while the picture could come
+ // from either that or the editorial one — so an artist filed with only
+ // an editorial portrait had a page with no colour at all, and fell back
+ // to a tone worked out from the photograph. On a portrait that is skin
+ // and hair, which is how a page the catalogue draws in dark brown
+ // arrived as pink.
+ // The tall editorial portrait first, and the square identity picture
+ // only as a fallback.
+ //
+ // `artwork` on an artist is a 2400x2400 square. Asked for a 3:4 header
+ // it is cropped to fit, and a square cropped that hard on a phone-height
+ // header arrives as an eye and an ear. The catalogue files a portrait
+ // drawn for exactly this slot — superHeroTall, 1680x2240 — and asking
+ // for the shape it already is leaves nothing to crop.
+ val heroArt = editorial?.get("superHeroTall")?.jsonObject
+ ?: editorial?.get("staticDetailTall")?.jsonObject
+ ?: attributes["artwork"]?.jsonObject
+ ?: editorial?.get("subscriptionHero")?.jsonObject
+ val hero = heroArt?.template()
+
+ // The colour, though, comes off the identity picture where there is
+ // one. The tall portrait carries the colour of its own padding — white,
+ // usually — while the square one carries the colour the catalogue uses
+ // for the artist's page: dark brown for the artist whose page is dark
+ // brown.
+ val colourArt = attributes["artwork"]?.jsonObject ?: heroArt
val logo = listOf("musicContentColorLogoTrimmed", "brandLogo", "logo")
.firstNotNullOfOrNull { editorial?.get(it)?.jsonObject }
if (hero == null && logo == null) return null
return Artist(
- heroUrl = hero?.let { size(it, HERO_W, HERO_H, crop = "va") },
- bgColor = attributes["artwork"]?.jsonObject?.get("bgColor")?.jsonPrimitive?.content,
+ // At the picture's own proportions rather than forced into a
+ // portrait shape.
+ //
+ // Some artists are filed with a tall portrait drawn for this slot
+ // and some with only a square identity picture. Asking every one of
+ // them for 3:4 crops the square ones hard, and a square face cropped
+ // to a phone-tall header is an eye and an ear. Asked for the shape
+ // it already is, nothing is cut; the page below is what makes up the
+ // height, the way the reference does it.
+ heroUrl = hero?.let {
+ val ratio = heroRatio(heroArt)
+ if (ratio == null) {
+ size(it, HERO_W, HERO_H, crop = "va")
+ } else {
+ size(it, HERO_W, (HERO_W / ratio).toInt().coerceAtLeast(1))
+ }
+ },
+ heroAspect = heroRatio(heroArt),
+ bgColor = colourArt?.get("bgColor")?.jsonPrimitive?.content,
+ // The catalogue files the ink beside the ground, picked for it.
+ // Working one out ourselves from the ground's brightness is a
+ // guess at a decision somebody already made, and it shows: theirs
+ // is a near-white with a trace of the photograph in it.
+ textHex = colourArt?.get("textColor1")?.jsonPrimitive?.content,
+ inkPalette = inkPaletteOf(colourArt),
bio = attributes["artistBio"]?.jsonPrimitive?.content,
origin = attributes["bornOrFormed"]?.jsonPrimitive?.content,
// At the picture's own proportions, whatever they are. Every crop
@@ -481,20 +559,35 @@ object AppleCatalog {
?.let { it["standard"] ?: it["short"] }
?.jsonPrimitive?.content
+ // One row for the colour and the ink, the way the artist's is read.
+ val pageArt = attributes["editorialArtwork"]?.jsonObject
+ ?.get("staticDetailTall")?.jsonObject
+ ?: attributes["artwork"]?.jsonObject
+
if (tall == null && cover == null) return null
return Album(
heroUrl = (tall ?: motionStill)?.let { size(it, DETAIL_W, DETAIL_H) },
motionUrl = motionUrl,
- bgColor = (
- attributes["editorialArtwork"]?.jsonObject
- ?.get("staticDetailTall")?.jsonObject
- ?: attributes["artwork"]?.jsonObject
- )?.get("bgColor")?.jsonPrimitive?.content,
+ bgColor = pageArt?.get("bgColor")?.jsonPrimitive?.content,
+ textHex = pageArt?.get("textColor1")?.jsonPrimitive?.content,
+ inkPalette = inkPaletteOf(pageArt),
coverUrl = cover?.let { size(it, COVER_PX, COVER_PX) },
notes = notes,
)
}
+ /** An artwork row's own proportions, width over height. */
+ private fun heroRatio(art: JsonObject?): Float? {
+ val w = art?.get("width")?.jsonPrimitive?.content?.toFloatOrNull() ?: return null
+ val h = art["height"]?.jsonPrimitive?.content?.toFloatOrNull() ?: return null
+ return (w / h).takeIf { it.isFinite() && it > 0f }
+ }
+
+ /** The four text colours filed with an artwork row, in order. */
+ private fun inkPaletteOf(art: JsonObject?): List<String> =
+ listOf("textColor1", "textColor2", "textColor3", "textColor4")
+ .mapNotNull { art?.get(it)?.jsonPrimitive?.content }
+
/**
* The full-height picture a record's page opens with, where it has one.
*
diff --git a/app/src/main/java/dev/lelonio/square/ui/MainViewModel.kt b/app/src/main/java/dev/lelonio/square/ui/MainViewModel.kt
index 77cc9a3..d2ceba4 100644
--- a/app/src/main/java/dev/lelonio/square/ui/MainViewModel.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/MainViewModel.kt
@@ -190,6 +190,10 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {
val notes: String? = null,
/** The page's tint as six hex digits, where the catalogue names one. */
val tintHex: String? = null,
+ /** The ink the catalogue picked for that tint; see AppleCatalog. */
+ val inkHex: String? = null,
+ /** The header picture's own proportions, width over height. */
+ val heroAspect: Float? = null,
/**
* Whose list it is: the account that made a playlist.
*
@@ -2023,6 +2027,8 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {
byline = state.byline.ifEmpty { current.byline },
origin = state.origin ?: current.origin,
tintHex = state.tintHex ?: current.tintHex,
+ inkHex = state.inkHex ?: current.inkHex,
+ heroAspect = state.heroAspect ?: current.heroAspect,
motionUrl = state.motionUrl ?: current.motionUrl,
// Owned by the lookup alone: every other publish carries the
// flag's default and would clear the wait a batch of tracks
@@ -3659,6 +3665,8 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {
heroUrl = found.heroUrl,
logoUrl = found.logoUrl,
tintHex = found.bgColor,
+ inkHex = found.textHex,
+ heroAspect = found.heroAspect,
notes = found.bio,
origin = found.origin,
heroPending = false,
@@ -3694,6 +3702,7 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {
coverUrl = found.coverUrl,
notes = found.notes,
tintHex = found.bgColor,
+ inkHex = found.textHex,
motionUrl = found.motionUrl,
heroPending = false,
)
diff --git a/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt b/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt
index 2dbd0c2..8710e49 100644
--- a/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt
@@ -100,7 +100,6 @@ import androidx.navigation.compose.rememberNavController
import androidx.compose.ui.platform.LocalContext
import coil.compose.AsyncImage
import coil.request.ImageRequest
-import dev.lelonio.square.ui.components.BlurTransformation
import dev.lelonio.square.ui.glass.backdrop.Backdrop
import dev.lelonio.square.ui.glass.backdrop.backdrops.layerBackdrop
import dev.lelonio.square.ui.glass.backdrop.backdrops.rememberLayerBackdrop
@@ -159,10 +158,10 @@ import dev.lelonio.square.ui.search.SearchScreen
import dev.lelonio.square.ui.onboarding.BackendChoiceScreen
import dev.lelonio.square.ui.onboarding.OnboardingScreen
import dev.lelonio.square.ui.settings.SettingsScreen
+import dev.lelonio.square.ui.theme.footToneFor
import dev.lelonio.square.ui.theme.Ink
import dev.lelonio.square.ui.theme.pageColorFor
import dev.lelonio.square.ui.theme.pageColorForHex
-import dev.lelonio.square.ui.theme.PageFloor
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.slideInHorizontally
@@ -171,6 +170,7 @@ import androidx.compose.animation.fadeIn
import androidx.compose.animation.togetherWith
import dev.lelonio.square.ui.theme.SquareTheme
import dev.lelonio.square.ui.theme.rememberArtworkColor
+import dev.lelonio.square.ui.theme.rememberArtworkFootColor
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import com.adamglin.PhosphorIcons
@@ -232,12 +232,16 @@ private val BottomBarHeight = 62.dp
* a tint belongs, and only then mixes — so a purple page gives a purple-white and
* a green one a green-white, whatever the page's own colour was worth.
*/
+@Composable
private fun inkTintedBy(color: Color): Color {
val hsv = FloatArray(3)
android.graphics.Color.colorToHSV(color.toArgb(), hsv)
if (hsv[1] < 0.06f) return Ink
hsv[1] = hsv[1].coerceIn(0.5f, 1f)
- hsv[2] = 0.9f
+ // Bright over a dark page and deep over a light one. Fixed bright was the
+ // whole of this before there was a light side, and there it gave a pale
+ // icon on a white film — the tint was right and the direction was not.
+ hsv[2] = if (dev.lelonio.square.ui.theme.lightPage()) 0.38f else 0.9f
return androidx.compose.ui.graphics.lerp(Ink, Color(android.graphics.Color.HSVToColor(hsv)), 0.3f)
}
@@ -350,11 +354,6 @@ private fun rememberLocalAudioPermission(onAnswered: () -> Unit): () -> Unit {
}
}
-private const val BACKDROP_DECODE_PX = 128
-
-/** Radius in pixels of the decoded image; see [BlurTransformation]. */
-private val BackdropBlur = BlurTransformation(radius = 14, passes = 2)
-
@UnstableApi
@Composable
fun SquareApp(
@@ -694,6 +693,15 @@ fun SquareApp(
val artBackdrop = rememberLayerBackdrop()
val pageBackdrop = rememberLayerBackdrop()
+ // What the player's own glass refracts: the ambient field made from the
+ // record, and nothing of the page underneath.
+ //
+ // The panes in the player used to sample `artBackdrop`, which is the page's
+ // flat tone — drawn behind a screen that entirely covers it. So the pill
+ // under the title and the transport bent a colour that was not on screen,
+ // and sat on the ambient without ever picking anything up from it.
+ val playerBackdrop = rememberLayerBackdrop()
+
// Everything the modals cover: the screens, the bars *and* the player. The
// sheets used to sample `pageBackdrop`, which stops at the navigation host,
// so opening one over the player blurred the home page behind it instead of
@@ -746,6 +754,13 @@ fun SquareApp(
// How far the player is open, 0 to 1. A value rather than a destination:
// see NowPlayingSheet for why the player stopped being a route.
val expand = remember { Animatable(if (preferences.playerWasOpen()) 1f else 0f) }
+
+ // Open and standing still. Derived rather than read straight, so what
+ // depends on it recomposes twice a journey instead of on every frame of
+ // one; see the player's ambient background.
+ val playerSettled by remember {
+ derivedStateOf { expand.value > 0.999f && !expand.isRunning }
+ }
val scope = rememberCoroutineScope()
// Remembered for the next launch. Written when the animation settles rather
@@ -1288,7 +1303,6 @@ fun SquareApp(
artworkUrl = nowPlayingArt?.heroUrl
?: nowPlayingArt?.coverUrl
?: playback.artworkUrl,
- asColor = true,
tintHex = nowPlayingArt?.bgColor,
)
}
@@ -1986,9 +2000,22 @@ fun SquareApp(
//
// The listener's own slider still sets how far it goes; only
// the direction is fixed here.
- val puckWash = Color.Black.copy(
- alpha = (glassConfig.puckOpacity.coerceIn(0f, 1f) * 1.3f).coerceAtMost(0.5f),
- )
+ // Far lighter on the light side. Sinking the lit slot works
+ // over a dark bar, where the glass around it is already
+ // dark; over a white film the same wash is a solid blob
+ // with the page's colour in it, and what should be a mark
+ // reads as a button someone pressed and left down.
+ val puckWash = if (dev.lelonio.square.ui.theme.lightPage()) {
+ Color.Black.copy(
+ alpha = (glassConfig.puckOpacity.coerceIn(0f, 1f) * 0.13f)
+ .coerceAtMost(0.11f),
+ )
+ } else {
+ Color.Black.copy(
+ alpha = (glassConfig.puckOpacity.coerceIn(0f, 1f) * 1.3f)
+ .coerceAtMost(0.5f),
+ )
+ }
// Searching opens the bar and keeps it open.
//
@@ -2444,7 +2471,67 @@ fun SquareApp(
Box(Modifier.fillMaxSize().graphicsLayer { alpha = chrome }) {
NowPlayingSheet(
progress = expand,
- background = { AppBackdrop(playback.artworkUrl) },
+ background = {
+ Box(Modifier.fillMaxSize().layerBackdrop(playerBackdrop)) {
+ // The player's own room, out of the record it is
+ // playing: see AmbientArtworkBackground. The tone
+ // is the catalogue's where it gave one and the
+ // picture's own where it did not, which is the same
+ // rule every page in the app follows.
+ val ambientArt = nowPlayingArt?.heroUrl
+ ?: nowPlayingArt?.coverUrl
+ ?: playback.artworkUrl
+ // The band the fade actually meets, so the screen
+ // below the cover carries on from where the cover
+ // stopped rather than jumping to the colour that
+ // happens to identify the record. See
+ // rememberArtworkFootColor.
+ val ambientFoot by rememberArtworkFootColor(ambientArt)
+ val ambientAccent by rememberArtworkColor(
+ ambientArt.takeIf { nowPlayingArt?.bgColor == null },
+ )
+ dev.lelonio.square.ui.components.AmbientArtworkBackground(
+ artworkModel = ambientArt,
+ // The shape the cover above is drawn at, so
+ // this lies exactly under it; see PlayerScreen.
+ coverAspect = 3f / 4f,
+ // The catalogue's colour first, and used the
+ // way it was filed rather than taken towards
+ // the theme's paper: it was picked for this
+ // record, and it is what the reference puts
+ // behind the same cover. The colour read off
+ // the picture is the fallback for the records
+ // it has never heard of.
+ tone = when {
+ nowPlayingArt?.bgColor != null ->
+ pageColorForHex(nowPlayingArt?.bgColor, lift = false)
+ ambientFoot != null ->
+ footToneFor(ambientFoot, lift = false)
+ else -> pageColorFor(ambientAccent)
+ },
+ // Barely any colour over the picture.
+ //
+ // The reference does not put a tone behind its
+ // player at all: what fills the screen above and
+ // below the cover is the cover, blurred and
+ // carried past its edges — dark grey at the top
+ // because the sleeve's top is dark grey, red at
+ // the foot because the sleeve ends in a red
+ // coat. A wash of a chosen colour over that is
+ // the thing that made ours stop looking like the
+ // record. What is left is enough to keep the
+ // controls legible.
+ toneFloor = 0.08f,
+ scrimFloor = 0.22f,
+ // Still while the sheet is travelling: under a
+ // moving, scaling, fading layer the drift
+ // cannot be seen, and it is the one moment in
+ // the app where an always-invalidating
+ // background would be competing for the frame.
+ motion = playerSettled,
+ )
+ }
+ },
expandedContent = {
// The player is the largest glass surface in the app by
// a wide margin, so the settings' switch for it is the
@@ -2603,13 +2690,16 @@ fun SquareApp(
)
},
onDeletePreset = viewModel::deleteEffectPreset,
- backdrop = artBackdrop,
+ backdrop = playerBackdrop,
canvas = canvas,
// The record's own artwork from the other
// catalogue, where it has any: the tall picture
// and the moving cover a song inherits from its
// album. Null leaves the player with the square
// cover it always had.
+ // The colours filed with this artwork, for the
+ // light that moves behind it; see CoverAura.
+ catalogPalette = nowPlayingArt?.inkPalette.orEmpty(),
coverHeroUrl = nowPlayingArt?.heroUrl,
coverMotionUrl = nowPlayingArt?.motionUrl,
coverSquareUrl = nowPlayingArt?.coverUrl,
@@ -3177,101 +3267,31 @@ fun SquareApp(
}
/**
- * The blurred artwork every screen sits on.
+ * The colour every screen sits on, taken from what is playing.
*
- * Blurred here rather than by the backdrop library: this is the *page*
- * background, not a glass pane, and it has to be soft even where no glass is
- * drawn over it. The scrim on top is what keeps text legible over a bright
- * cover — the palette is built for a dark page.
+ * The player is the exception and has its own: there the record is the subject
+ * and the screen is made of the picture itself — see AmbientArtworkBackground,
+ * which is where the blurred copy of the artwork went.
*/
@Composable
private fun AppBackdrop(
artworkUrl: String?,
- asColor: Boolean = false,
/** The catalogue's own page colour for what is playing; see pageColorForHex. */
tintHex: String? = null,
) {
- // The pages are the colour of what is playing, not a picture of it.
- //
- // A blurred cover behind a home page full of covers is a picture behind
- // pictures: every shelf sits on a different smear of the same artwork, and
- // nothing on the page is helped by it. The detail pages already answer this
- // properly — one tone taken from the record, falling away down the screen —
- // and this is that same treatment for everywhere else, which is also what
- // makes moving between them feel like one app rather than two.
- //
- // The player keeps the picture: there the cover is the subject, and a wash
- // of its colour behind the very artwork it was taken from says nothing.
- if (asColor) {
- val accent by rememberArtworkColor(artworkUrl.takeIf { tintHex == null })
- // Eased rather than cut: a track change would otherwise repaint the
- // whole window in one frame, which reads as a flash.
- val tone by animateColorAsState(
- targetValue = tintHex?.let(::pageColorForHex) ?: pageColorFor(accent),
- animationSpec = tween(durationMillis = 700),
- label = "pageTone",
- )
- Box(
- Modifier
- .fillMaxSize()
- .background(
- Brush.verticalGradient(
- 0f to tone,
- 0.45f to tone,
- 1f to PageFloor,
- ),
- ),
- )
- return
- }
-
- Box(
- Modifier
- .fillMaxSize()
- .background(Color(0xFF0A0A0C)),
- ) {
- if (artworkUrl != null) {
- // Blurred at decode time rather than by `Modifier.blur`. That
- // modifier is a RenderEffect over the whole window, re-run whenever
- // the layer changes — every frame while the player expands, which is
- // most of what made it stutter. Stretching a 32px bitmap instead was
- // free and looked it: bilinear upscaling from that size shows square
- // blocks, not a wash. This does the blur once per cover, on a small
- // bitmap, and Coil caches it.
- AsyncImage(
- model = ImageRequest.Builder(LocalContext.current)
- .data(artworkUrl)
- .size(BACKDROP_DECODE_PX)
- .transformations(BackdropBlur)
- .allowHardware(false)
- .crossfade(true)
- .build(),
- contentDescription = null,
- contentScale = ContentScale.Crop,
- modifier = Modifier.fillMaxSize(),
- )
- }
-
- Box(
- Modifier
- .fillMaxSize()
- .background(
- Brush.verticalGradient(
- // Light enough that the cover's colour survives it.
- //
- // At 0.45 to 0.78 the blurred artwork under the player
- // arrived as grey: a red sleeve gave a grey-green
- // field, which is neither the record's colour nor
- // anything the sharp copy above could dissolve into.
- // The glass over the controls does its own darkening,
- // and the hero's scrim adds the rest at the foot.
- 0f to Color.Black.copy(alpha = 0.18f),
- 0.5f to Color.Black.copy(alpha = 0.24f),
- 1f to Color.Black.copy(alpha = 0.34f),
- ),
- ),
- )
- }
+ val accent by rememberArtworkColor(artworkUrl.takeIf { tintHex == null })
+ // Eased rather than cut: a track change would otherwise repaint the
+ // whole window in one frame, which reads as a flash.
+ val tone by animateColorAsState(
+ targetValue = if (tintHex != null) pageColorForHex(tintHex) else pageColorFor(accent),
+ animationSpec = tween(durationMillis = 700),
+ label = "pageTone",
+ )
+ // One colour, held. It used to slide to the floor over the lower half,
+ // which read as the page running out of light rather than as a page with a
+ // colour — and under a screen of shelves there is nothing for a gradient to
+ // describe anyway.
+ Box(Modifier.fillMaxSize().background(tone))
}
@Composable
diff --git a/app/src/main/java/dev/lelonio/square/ui/components/AmbientArtworkBackground.kt b/app/src/main/java/dev/lelonio/square/ui/components/AmbientArtworkBackground.kt
new file mode 100644
index 0000000..d7295f0
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/components/AmbientArtworkBackground.kt
@@ -0,0 +1,598 @@
+package dev.lelonio.square.ui.components
+
+import androidx.compose.animation.animateColorAsState
+import androidx.compose.animation.core.Animatable
+import androidx.compose.animation.core.FastOutSlowInEasing
+import androidx.compose.animation.core.LinearEasing
+import androidx.compose.animation.core.RepeatMode
+import androidx.compose.animation.core.animateFloat
+import androidx.compose.animation.core.infiniteRepeatable
+import androidx.compose.animation.core.rememberInfiniteTransition
+import androidx.compose.animation.core.tween
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.BoxWithConstraints
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.State
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.clipToBounds
+import androidx.compose.ui.graphics.Brush
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.GraphicsLayerScope
+import androidx.compose.ui.graphics.TransformOrigin
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.layout.ContentScale
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.unit.Dp
+import coil.compose.AsyncImage
+import coil.imageLoader
+import coil.request.ImageRequest
+import dev.lelonio.square.ui.theme.warmArtworkColor
+import kotlinx.coroutines.coroutineScope
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withTimeoutOrNull
+
+/**
+ * The room the player is in, made out of the record that is playing.
+ *
+ * Not a blurred cover behind a cover. The same picture is drawn much larger
+ * than the screen, blurred past the point where anything in it can be made
+ * out, and left as light and colour: what reaches the eye is the record's
+ * palette filling the window, with the sharp copy above dissolving into it —
+ * see [HeroBackdrop]'s `fadeToPage`, which is the other half of this.
+ *
+ * Three things make it read as a room rather than as a wallpaper:
+ *
+ * - two copies at different blurs, the softer one filling the frame and the
+ * sharper one over it at low opacity, which gives the field a near and a far
+ * and stops it looking like flat paper;
+ * - a drift so slow it is never caught moving, which is what keeps a still
+ * screen from looking switched off;
+ * - a crossfade on a track change that is slower than the cover's own, so the
+ * room changes around the picture instead of with it.
+ *
+ * ## What this deliberately does not do
+ *
+ * There is no `Modifier.blur` here and no `RenderEffect`. Both are render
+ * effects over a layer, re-run every frame that layer changes — and this layer
+ * changes on every frame of the drift, of the crossfade, and of the player
+ * opening. The blur is done once per cover, at decode, on an image small enough
+ * that the work is trivial, and Coil keeps the result: see [BlurTransformation].
+ * That also settles the compatibility question, since it is ordinary bitmap
+ * work on every version the app runs on.
+ *
+ * Everything that animates is read inside a `graphicsLayer` block, which the
+ * compose runtime defers to the draw phase: the drift and the crossfade never
+ * recompose anything and never re-decode anything. They move a texture the GPU
+ * already has.
+ */
+@Composable
+fun AmbientArtworkBackground(
+ /** Usually a url; anything Coil can load. */
+ artworkModel: Any?,
+ /**
+ * The colour taken from this same picture, which the field settles onto at
+ * the foot of the screen and which is what is showing before it loads.
+ */
+ tone: Color,
+ modifier: Modifier = Modifier,
+ /** Off leaves the tone alone, which is the whole of the fallback. */
+ enabled: Boolean = true,
+ /**
+ * The proportions the sharp cover above is drawn at, width over height.
+ *
+ * Given, this copy is laid over that cover exactly and its foot carried on
+ * down the rest of the screen. Null fills the window with the picture
+ * instead, which is right where there is no cover over this to match.
+ */
+ coverAspect: Float? = null,
+ /**
+ * The height of the picture above, where the page fixes it rather than
+ * letting it take its own proportions. Wins over [coverAspect].
+ */
+ coverHeight: Dp? = null,
+ /**
+ * How the copy is framed, which has to be how the sharp picture above is
+ * framed.
+ *
+ * The player draws its cover at its own proportions and fills the window,
+ * so stretching to the bounds keeps every row under the row above it. A
+ * page lays the picture across a short wide header and crops it, and a copy
+ * stretched instead of cropped is a different framing of the same photo —
+ * which arrives as a band of blurred something-else under the header.
+ */
+ coverScale: ContentScale = ContentScale.FillBounds,
+ /**
+ * Where the field starts settling — usually the foot of the picture.
+ *
+ * A page carries a list over this and needs to be darker than a player
+ * does, and it needs to be darker from where its header ends rather than
+ * from halfway down a screen it does not control.
+ */
+ settleFrom: Float = 0.55f,
+ /**
+ * Where the settling is complete, after which the field is one flat colour
+ * and stays it.
+ *
+ * A page holds a single tone under its lists rather than sliding towards
+ * black: the slide is what made every page look like it was running out of
+ * light towards the bottom.
+ */
+ settleTo: Float = 1f,
+ /** How much of the tone, and of black, has arrived by [settleTo]. */
+ toneFloor: Float = 0.26f,
+ scrimFloor: Float = 0.34f,
+ /**
+ * Whether the field drifts.
+ *
+ * Worth switching off while the player is arriving or leaving: the drift is
+ * cheap, but it is also invisible under a travelling sheet, and a
+ * continuously invalidating background during that travel is the one moment
+ * this could cost a frame.
+ */
+ motion: Boolean = true,
+) {
+ val context = LocalContext.current
+
+ // Which picture is showing, and which one is on its way out.
+ //
+ // Held here rather than handed to Crossfade or AnimatedContent: both of
+ // those keep whole subtrees alive and recompose them across the change, and
+ // what is crossfading is two images and nothing else. This is the same
+ // effect as two alphas.
+ var shown by remember { mutableStateOf(artworkModel) }
+ var leaving by remember { mutableStateOf<Any?>(null) }
+ val swap = remember { Animatable(1f) }
+
+ // The colour the field is actually on, which is not always the colour it
+ // has been given.
+ //
+ // A track change reaches this composable as several separate arrivals: the
+ // address of the new cover first, then its colour once a bitmap has been
+ // read, then the picture itself once it has been decoded and blurred. Taken
+ // as they come, they are three visible events in a row — and the middle one
+ // is the worst of them, a whole screen of colour changing under a picture
+ // that has not changed yet. That is the flash. This holds the colour where
+ // it is until the picture is ready, and then moves both together.
+ var held by remember { mutableStateOf(tone) }
+ var holding by remember { mutableStateOf(false) }
+ if (!holding && held != tone) held = tone
+
+ // Eased, and slower than everything else here: the tone is the one thing on
+ // screen with no picture in it, so a cut in it reads as the lights being
+ // switched rather than as the record changing.
+ val settledTone by animateColorAsState(
+ targetValue = held,
+ animationSpec = tween(durationMillis = TONE_MS),
+ label = "ambientTone",
+ )
+
+ LaunchedEffect(artworkModel) {
+ if (artworkModel == shown) return@LaunchedEffect
+ // Nothing to fade from on the first picture of all: fading up from the
+ // tone is what the colour animation above is already doing.
+ if (shown == null || artworkModel == null) {
+ shown = artworkModel
+ leaving = null
+ swap.snapTo(1f)
+ return@LaunchedEffect
+ }
+
+ // Wait for the new picture before starting to leave the old one.
+ //
+ // Without this the fade ran on the clock and the image ran on the
+ // network: the old copy was already half gone when the new one had
+ // nothing to draw, so what showed through the middle of the change was
+ // the bare tone — a flash of flat colour between two covers. Waiting
+ // costs nothing visible, because what is on screen in the meantime is
+ // the picture that was already there.
+ //
+ // Timed out rather than awaited for ever: a cover that never arrives
+ // must not leave the player on the wrong record's colours.
+ holding = true
+ withTimeoutOrNull(READY_MS.toLong()) {
+ coroutineScope {
+ // Exactly the requests the copies below will make, so what this
+ // waits for is what they will find already in the cache.
+ launch { warm(context, artworkModel, FAR_PX, FarBlur) }
+ launch { warm(context, artworkModel, NEAR_PX, NearBlur) }
+ // And the colour read off the same picture, so it cannot arrive
+ // on its own afterwards.
+ launch { (artworkModel as? String)?.let { warmArtworkColor(context, it) } }
+ }
+ }
+ holding = false
+
+ leaving = shown
+ shown = artworkModel
+ swap.snapTo(0f)
+ swap.animateTo(
+ targetValue = 1f,
+ animationSpec = tween(durationMillis = SWAP_MS, easing = FastOutSlowInEasing),
+ )
+ leaving = null
+ }
+
+ // One clock for the drift, shared by both copies so they cannot beat
+ // against each other.
+ val drift: State<Float> = if (motion && enabled) {
+ rememberInfiniteTransition(label = "ambientDrift").animateFloat(
+ initialValue = 0f,
+ targetValue = 1f,
+ animationSpec = infiniteRepeatable(
+ // Linear, and reversed rather than restarted: an eased drift has
+ // a moment where it visibly slows, and a restarted one has a
+ // jump. Neither survives being watched for a whole song.
+ animation = tween(durationMillis = DRIFT_MS, easing = LinearEasing),
+ repeatMode = RepeatMode.Reverse,
+ ),
+ label = "ambientDriftValue",
+ )
+ } else {
+ remember { mutableStateOf(0f) }
+ }
+
+ BoxWithConstraints(modifier.fillMaxSize().background(settledTone)) {
+ if (enabled) {
+ // The far copy, laid over the sharp one exactly.
+ //
+ // Same width, same top, same proportions, so every row of it is the
+ // blur of the row of cover above it. That is what the fade needs:
+ // it is not crossing from one picture to another, it is taking the
+ // sharpness out of the one picture.
+ val slot = coverHeight ?: coverAspect?.let { maxWidth / it }
+ Box(
+ Modifier
+ .fillMaxWidth()
+ .then(
+ if (slot != null) Modifier.height(slot) else Modifier.fillMaxSize(),
+ )
+ .align(Alignment.TopCenter),
+ ) {
+ AmbientCopy(
+ leaving = leaving,
+ shown = shown,
+ progress = { swap.value },
+ drift = { drift.value },
+ decodePx = FAR_PX,
+ blur = FarBlur,
+ baseScale = 1f,
+ travel = 0f,
+ opacity = 1f,
+ scale = coverScale,
+ )
+ }
+
+ // And below the cover, the cover's own bottom edge carried down.
+ //
+ // There is nothing under the last row of a picture, so a "picture
+ // continuing" past its own end can only be that row going on. The
+ // copy here is stretched vertically by a large factor about its
+ // foot, which leaves the bottom fiftieth of the artwork spread over
+ // the rest of the screen: the seam matches because the row that
+ // meets it is the row that ended the cover, and what fills the
+ // screen still varies across the width the way the sleeve does —
+ // warm at one side, dark at the other — instead of being one tone.
+ if (slot != null && slot < maxHeight) {
+ Box(
+ Modifier
+ .fillMaxWidth()
+ .height(maxHeight - slot)
+ .align(Alignment.BottomCenter)
+ .clipToBounds(),
+ ) {
+ // A copy the size of the picture's own slot, so it is
+ // framed exactly as the picture is, sunk to the foot of
+ // this box and stretched about that foot. What is left in
+ // view is the sleeve's last rows and nothing else.
+ Box(
+ Modifier
+ .fillMaxWidth()
+ .height(slot)
+ .align(Alignment.BottomCenter),
+ ) {
+ AmbientCopy(
+ leaving = leaving,
+ shown = shown,
+ progress = { swap.value },
+ drift = { drift.value },
+ decodePx = FAR_PX,
+ blur = FarBlur,
+ baseScale = 1f,
+ travel = 0f,
+ opacity = 1f,
+ stretch = SMEAR,
+ scale = coverScale,
+ )
+ }
+ }
+ }
+
+ // And the near one over it, sharper and barely there. It is what
+ // gives the field somewhere to be: a single blur at a single scale
+ // is flat no matter how well it is made, and two of them at
+ // different sizes moving against each other are a depth.
+ AmbientCopy(
+ leaving = leaving,
+ shown = shown,
+ progress = { swap.value },
+ drift = { drift.value },
+ decodePx = NEAR_PX,
+ blur = NearBlur,
+ baseScale = NEAR_SCALE,
+ // The only thing here that moves. The far copy is in register
+ // with the sharp cover above and has to stay there; drifting
+ // this one is what keeps the field alive without ever moving
+ // the picture out from under the fade.
+ travel = -NEAR_TRAVEL,
+ opacity = NEAR_ALPHA,
+ )
+ }
+
+ // A trace of the cover's own foot colour on the way down, and a scrim
+ // under that for the controls.
+ //
+ // Both kept light on purpose, and the tone lighter than the scrim. What
+ // fills the bottom of this screen is meant to be the picture carrying
+ // on; a tone heavy enough to be seen is a panel over it, however well it
+ // was chosen, and it was that — at more than half — which had every
+ // record ending on the same lilac. The darkening that legibility needs
+ // is black, which takes the light out without taking the hue with it.
+ Box(
+ Modifier
+ .fillMaxSize()
+ .background(
+ Brush.verticalGradient(
+ *tonalSettle(settleFrom, settleTo, settledTone, toneFloor),
+ ),
+ ),
+ )
+ val scrim = dev.lelonio.square.ui.theme.scrimColor()
+ if (scrimFloor > 0f) {
+ Box(
+ Modifier
+ .fillMaxSize()
+ .background(
+ Brush.verticalGradient(
+ 0f to scrim.copy(alpha = 0.16f),
+ (settleFrom * 0.64f) to Color.Transparent,
+ (settleFrom + (1f - settleFrom) * 0.5f)
+ to scrim.copy(alpha = scrimFloor * 0.4f),
+ 1f to scrim.copy(alpha = scrimFloor),
+ ),
+ ),
+ )
+ }
+ }
+}
+
+/**
+ * One blurred copy of the artwork, and the one leaving fading out under it.
+ *
+ * [progress] and [drift] are functions rather than values: read as parameters
+ * they would recompose this on every frame of both animations, and read inside
+ * the `graphicsLayer` block they are draw-phase reads, which is a re-record of
+ * one layer and nothing else.
+ */
+@Composable
+private fun AmbientCopy(
+ leaving: Any?,
+ shown: Any?,
+ progress: () -> Float,
+ drift: () -> Float,
+ decodePx: Int,
+ blur: BlurTransformation,
+ baseScale: Float,
+ travel: Float,
+ opacity: Float,
+ /** Vertical stretch about the foot; see SMEAR. */
+ stretch: Float = 1f,
+ /** How the picture is framed in its box; see coverScale. */
+ scale: ContentScale = ContentScale.FillBounds,
+) {
+ if (leaving != null) {
+ AmbientImage(
+ model = leaving,
+ decodePx = decodePx,
+ blur = blur,
+ scale = scale,
+ layer = {
+ val p = progress()
+ alpha = (1f - p) * opacity
+ // The picture leaving grows very slightly as it goes, which
+ // reads as it receding rather than as it being switched off.
+ val scale = baseScale * (1f + LEAVE_SWELL * p)
+ scaleX = scale
+ scaleY = scale * stretch
+ transformOrigin = if (stretch > 1f) SmearAnchor else FootAnchor
+ translationY = size.height * travel * drift()
+ },
+ )
+ }
+ if (shown != null) {
+ AmbientImage(
+ model = shown,
+ decodePx = decodePx,
+ blur = blur,
+ scale = scale,
+ layer = {
+ val p = progress()
+ alpha = p * opacity
+ // And the one arriving settles inward to its own size.
+ val scale = baseScale * (1f + ARRIVE_SWELL * (1f - p))
+ scaleX = scale
+ scaleY = scale * stretch
+ transformOrigin = if (stretch > 1f) SmearAnchor else FootAnchor
+ translationY = size.height * travel * drift()
+ },
+ )
+ }
+}
+
+/**
+ * The tone coming up under the picture, eased, and then holding.
+ *
+ * Smoothstepped for the same reason the picture's own fade is: a straight ramp
+ * between two stops has a corner at each end, and a corner in a field this
+ * large is a band across the page. Past [to] the colour is simply itself, which
+ * is what makes the lower half of a page one colour rather than a slide into
+ * the dark.
+ */
+private fun tonalSettle(
+ from: Float,
+ to: Float,
+ colour: Color,
+ ceiling: Float,
+): Array<Pair<Float, Color>> {
+ val steps = 8
+ val end = to.coerceIn(from + 0.01f, 1f)
+ // The flat run past the end of the ramp, unless the ramp already ends at
+ // the bottom of the screen: two stops at the same place is a hard edge.
+ val hold = if (end < 0.999f) 1 else 0
+ return Array(steps + 1 + hold) { index ->
+ if (index > steps) return@Array 1f to colour.copy(alpha = ceiling)
+ val t = index.toFloat() / steps
+ val eased = t * t * (3f - 2f * t)
+ (from + (end - from) * t) to colour.copy(alpha = ceiling * eased)
+ }
+}
+
+/**
+ * Puts a copy in Coil's cache, at the size and blur a copy below will ask for.
+ *
+ * The result is thrown away on purpose: what is wanted is the cache entry, so
+ * that the image the crossfade is about to draw is there on the first frame of
+ * it rather than somewhere in the middle.
+ */
+private suspend fun warm(
+ context: android.content.Context,
+ model: Any,
+ decodePx: Int,
+ blur: BlurTransformation,
+) {
+ runCatching {
+ context.imageLoader.execute(
+ ImageRequest.Builder(context)
+ .data(if (model is String) artSource(model) else model)
+ .size(decodePx)
+ .transformations(blur)
+ .allowHardware(false)
+ .build(),
+ )
+ }
+}
+
+@Composable
+private fun AmbientImage(
+ model: Any,
+ decodePx: Int,
+ blur: BlurTransformation,
+ scale: ContentScale,
+ layer: GraphicsLayerScope.() -> Unit,
+) {
+ AsyncImage(
+ model = ImageRequest.Builder(LocalContext.current)
+ // Offline this is the file on the disk rather than the address it
+ // came from; the same resolution the sharp copy uses.
+ .data(if (model is String) artSource(model) else model)
+ .size(decodePx)
+ .transformations(blur)
+ // A hardware bitmap cannot be read back and the blur reads every
+ // pixel of it.
+ .allowHardware(false)
+ // Off deliberately: the fade between two covers is the one above,
+ // which knows about both of them. Coil's own also skips itself on a
+ // cache hit, so with it on a prefetched cover arrives as a cut.
+ .crossfade(false)
+ .build(),
+ contentDescription = null,
+ // Stretched to the window rather than cropped to it, which is the
+ // whole of why this reads as the cover carrying on.
+ //
+ // The cover is drawn across the top at its own proportions, and the
+ // screen is much taller than that. Cropping to fill leaves the bottom
+ // of the screen showing the middle of the sleeve, so the picture and
+ // the field below it are two different parts of the same artwork
+ // meeting at the fade — which is a seam however well the fade is made.
+ // Filling the bounds keeps every row of this copy under the same row of
+ // the sharp one and carries the last of it down to the foot of the
+ // screen. The vertical stretch is real and, under this much blur,
+ // unfindable.
+ contentScale = scale,
+ modifier = Modifier
+ .fillMaxSize()
+ .graphicsLayer(layer),
+ )
+}
+
+/**
+ * Enlargement from the top, where the sharp copy starts.
+ *
+ * Anything anchored at the centre slides the picture out of register with the
+ * cover above it, and out of register is the whole of what a seam is.
+ */
+private val FootAnchor = TransformOrigin(0.5f, 0f)
+
+/** And for the smear, which grows upward out of the bottom of its own box. */
+private val SmearAnchor = TransformOrigin(0.5f, 1f)
+
+/**
+ * How far the copy below the cover is stretched.
+ *
+ * Very large on purpose. The band left in view is the last 1/[SMEAR] of the
+ * picture, and it is drawn bottom-row-last — so the row that meets the seam is
+ * not quite the row that ended the picture, and the difference between the two
+ * is a line across the screen. At fifty that gap was two percent of the image
+ * and findable; at four hundred it is a quarter of a percent, which is under
+ * the blur. What is drawn is still the sleeve's own foot, varying across the
+ * width the way the sleeve does.
+ */
+private const val SMEAR = 400f
+
+/** How far past its own size the near copy is drawn. */
+private const val NEAR_SCALE = 1.06f
+
+/** How much of the near copy shows. */
+private const val NEAR_ALPHA = 0.30f
+
+/** How far the near copy drifts, as a fraction of the screen's height. */
+private const val NEAR_TRAVEL = 0.014f
+
+/** How long the drift takes to cross, one way. */
+private const val DRIFT_MS = 12_000
+
+/** How long the room takes to become a different room. */
+private const val SWAP_MS = 720
+
+/**
+ * How long the change will wait for the new picture before going without it.
+ *
+ * Long enough for a cover to come off the network on a poor connection, short
+ * enough that a cover which is not coming at all does not hold the screen on
+ * the last record for longer than the song took to change.
+ */
+private const val READY_MS = 1_800
+
+/** And the colour under it, which is slower still. */
+private const val TONE_MS = 900
+
+/** How much the picture leaving grows, and the one arriving shrinks. */
+private const val LEAVE_SWELL = 0.05f
+private const val ARRIVE_SWELL = 0.06f
+
+/** Blurred at decode, once per cover, and kept by Coil. */
+private val FarBlur = BlurTransformation(radius = 16, passes = 3)
+private val NearBlur = BlurTransformation(radius = 10, passes = 2)
+
+/** How small each copy is decoded before it is blurred and stretched. */
+private const val FAR_PX = 96
+private const val NEAR_PX = 192
diff --git a/app/src/main/java/dev/lelonio/square/ui/components/GlassMenu.kt b/app/src/main/java/dev/lelonio/square/ui/components/GlassMenu.kt
index 8aa4235..abebe29 100644
--- a/app/src/main/java/dev/lelonio/square/ui/components/GlassMenu.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/components/GlassMenu.kt
@@ -39,6 +39,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.isSpecified
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.IntOffset
@@ -146,10 +147,24 @@ val MENU_WIDTH = 244.dp
private val TopEnd = TransformOrigin(1f, 0f)
/** Dark enough that a list of track titles does not read through it. */
-private val MenuSurface = Color(0xFF16161A)
+private val MenuSurfaceDark = Color(0xFF16161A)
+private val MenuSurfaceLight = Color(0xFFF6F6FA)
+
+/** The base a menu is built on, on whichever side of the app it opens. */
+private val MenuSurface: Color
+ @Composable get() = if (dev.lelonio.square.ui.theme.lightPage()) {
+ MenuSurfaceLight
+ } else {
+ MenuSurfaceDark
+ }
/** The hairline every other surface in the app catches light with. */
-private val MenuEdge = Color.White.copy(alpha = 0.14f)
+private val MenuEdge: Color
+ @Composable get() = if (dev.lelonio.square.ui.theme.lightPage()) {
+ Color.Black.copy(alpha = 0.12f)
+ } else {
+ Color.White.copy(alpha = 0.14f)
+ }
/**
* The compact form: one row of icons in a glass capsule.
@@ -353,7 +368,16 @@ fun Modifier.menuSkin(shape: androidx.compose.ui.graphics.Shape): Modifier =
private fun menuFilm(): Color {
val config = dev.lelonio.square.ui.glass.LocalGlassEffectConfig.current
val missing = (MENU_FLOOR_OPACITY - config.surfaceOpacity).coerceAtLeast(0f)
- return config.surfaceTintColor.copy(alpha = missing)
+ // The listener's own tint where they set one, and the adaptive film
+ // otherwise — the same rule the glass itself follows; see GlassEffect.
+ val tint = if (config.surfaceTintColor.isSpecified) {
+ config.surfaceTintColor
+ } else if (dev.lelonio.square.ui.theme.lightPage()) {
+ Color(0xFFFAFAFA)
+ } else {
+ Color(0xFF23232A)
+ }
+ return tint.copy(alpha = missing)
}
/** The coverage a menu needs before its own rows stop competing with the page. */
diff --git a/app/src/main/java/dev/lelonio/square/ui/components/HeroBackdrop.kt b/app/src/main/java/dev/lelonio/square/ui/components/HeroBackdrop.kt
index 760a663..a6ea4b9 100644
--- a/app/src/main/java/dev/lelonio/square/ui/components/HeroBackdrop.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/components/HeroBackdrop.kt
@@ -83,6 +83,8 @@ fun HeroBackdrop(
*/
imageAspect: Float? = null,
) {
+ // Black over a dark page and white over a light one; see scrimColor.
+ val scrim = dev.lelonio.square.ui.theme.scrimColor()
Box(modifier) {
if (imageAspect != null && fadeToPage) {
// The colour first, because the picture no longer covers the slot.
@@ -224,7 +226,7 @@ fun HeroBackdrop(
// out from halfway — the colour arrived on its own
// schedule and paled the very part that was meant to be
// legible.
- 0f to Color.Black.copy(alpha = 0.22f),
+ 0f to scrim.copy(alpha = 0.22f),
(softenFrom * 0.45f) to Color.Transparent,
// The colour comes up behind the blur rather than with
// it, and on the same eased curve. The picture going
@@ -263,15 +265,21 @@ fun HeroBackdrop(
val ends = imageAspect
?.let { (size.width / it / size.height).coerceIn(0f, 1f) }
?: 1f
- drawRect(
- brush = Brush.verticalGradient(
- 0f to Color.Black.copy(alpha = 0.20f),
- (ends * 0.45f) to Color.Transparent,
- (ends * 0.92f) to Color.Black.copy(alpha = 0.05f),
- ends to Color.Black.copy(alpha = 0.12f),
- 1f to Color.Black.copy(alpha = 0.30f),
- ),
- )
+ // The last two stops collapse onto each other where the
+ // picture reaches the bottom of its own box, which is a
+ // hard edge rather than a gradient.
+ val stops = buildList {
+ add(0f to scrim.copy(alpha = 0.20f))
+ add((ends * 0.45f) to Color.Transparent)
+ add((ends * 0.92f) to scrim.copy(alpha = 0.05f))
+ if (ends < 0.999f) {
+ add(ends to scrim.copy(alpha = 0.12f))
+ add(1f to scrim.copy(alpha = 0.30f))
+ } else {
+ add(1f to scrim.copy(alpha = 0.12f))
+ }
+ }
+ drawRect(brush = Brush.verticalGradient(*stops.toTypedArray()))
},
)
}
diff --git a/app/src/main/java/dev/lelonio/square/ui/components/UpdateSheet.kt b/app/src/main/java/dev/lelonio/square/ui/components/UpdateSheet.kt
index fb9d774..0a39f74 100644
--- a/app/src/main/java/dev/lelonio/square/ui/components/UpdateSheet.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/components/UpdateSheet.kt
@@ -145,7 +145,11 @@ fun UpdateSheet(
}
if (notes.isNotBlank()) {
- val text = remember(notes) { releaseNotes(notes) }
+ // The emphasis colour is handed in rather than read
+ // inside: this builds a string, not a composition, and
+ // the ink now depends on the theme.
+ val emphasis = GlassInk
+ val text = remember(notes, emphasis) { releaseNotes(notes, emphasis) }
Text(
text,
style = MaterialTheme.typography.bodyMedium,
@@ -246,7 +250,7 @@ private fun DialogAction(
* things release notes are actually written with, and leaves anything else as
* the text it already is.
*/
-private fun releaseNotes(source: String): AnnotatedString = buildAnnotatedString {
+private fun releaseNotes(source: String, emphasis: Color): AnnotatedString = buildAnnotatedString {
val lines = source.trim().lines()
lines.forEachIndexed { index, raw ->
val line = raw.trim()
@@ -267,17 +271,17 @@ private fun releaseNotes(source: String): AnnotatedString = buildAnnotatedString
if (bullet) append("• ")
if (heading) {
- withStyle(SpanStyle(color = GlassInk, fontWeight = FontWeight.SemiBold)) {
- appendInline(body)
+ withStyle(SpanStyle(color = emphasis, fontWeight = FontWeight.SemiBold)) {
+ appendInline(body, emphasis)
}
} else {
- appendInline(body)
+ appendInline(body, emphasis)
}
}
}
/** Bold spans and code ticks, which is all the emphasis the notes ever use. */
-private fun AnnotatedString.Builder.appendInline(text: String) {
+private fun AnnotatedString.Builder.appendInline(text: String, emphasis: Color) {
var rest = text
while (true) {
val open = rest.indexOf("**")
@@ -285,7 +289,7 @@ private fun AnnotatedString.Builder.appendInline(text: String) {
val close = rest.indexOf("**", open + 2)
if (close < 0) break
append(rest.substring(0, open).replace("`", ""))
- withStyle(SpanStyle(color = GlassInk, fontWeight = FontWeight.SemiBold)) {
+ withStyle(SpanStyle(color = emphasis, fontWeight = FontWeight.SemiBold)) {
append(rest.substring(open + 2, close).replace("`", ""))
}
rest = rest.substring(close + 2)
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/GlassEffect.kt b/app/src/main/java/dev/lelonio/square/ui/glass/GlassEffect.kt
index fc2d201..69cf690 100644
--- a/app/src/main/java/dev/lelonio/square/ui/glass/GlassEffect.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/GlassEffect.kt
@@ -57,8 +57,16 @@ data class GlassEffectConfig(
val lensAmount: Float = 0.6f,
val chromaticAberration: Boolean = false,
val depthEffect: Boolean = false,
- /** [Color.Unspecified] means adaptive: dark grey on dark. */
- val surfaceTintColor: Color = Color(0xFF1A1A1A),
+ /**
+ * [Color.Unspecified] means adaptive, which is the default.
+ *
+ * It used to default to a fixed dark grey, which meant the adaptive branch
+ * below was dead code: the film stayed dark over a light page, so in the
+ * system's light setting every pill in the app was a dark slab with dark
+ * ink on it. A colour set by hand in the settings still wins over the
+ * adaptive answer — that is what setting it is for.
+ */
+ val surfaceTintColor: Color = Color.Unspecified,
/** Specular rim ("pluck") colour. [Color.Unspecified] keeps the default white. */
val highlightColor: Color = Color.Unspecified,
/** Specular rim opacity, 0..1. */
@@ -444,7 +452,7 @@ fun Modifier.liquidGlass(
val backdropLuminance = LocalBackdropLuminance.current
val surfaceTintColor = if (config.surfaceTintColor.isSpecified) {
config.surfaceTintColor
- } else if (MaterialTheme.colorScheme.surface.luminance() > 0.5f) {
+ } else if (dev.lelonio.square.ui.theme.LocalLightTheme.current) {
Color(0xFFFAFAFA)
} else {
// Between the two across the middle of the range rather than at a line,
diff --git a/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt b/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt
index 93982e1..69f4249 100644
--- a/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt
@@ -47,6 +47,7 @@ import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.luminance
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.graphics.Shadow
import androidx.compose.ui.graphics.lerp
@@ -100,9 +101,11 @@ import dev.lelonio.square.ui.glass.LiquidButton
import dev.lelonio.square.ui.glass.shapes.ContinuousCapsule
import dev.lelonio.square.ui.glass.pressable
import dev.lelonio.square.ui.theme.InkDim
+import dev.lelonio.square.ui.theme.footToneFor
import dev.lelonio.square.ui.theme.rememberArtworkColor
-import dev.lelonio.square.ui.theme.PageFloor
+import dev.lelonio.square.ui.theme.rememberArtworkFootColor
import dev.lelonio.square.ui.theme.pageColorFor
+import dev.lelonio.square.ui.theme.pageColorForHex
import dev.lelonio.square.ui.theme.softShadow
import java.util.Locale
import java.util.concurrent.TimeUnit
@@ -110,6 +113,7 @@ import com.adamglin.PhosphorIcons
import com.adamglin.phosphoricons.Fill
import com.adamglin.phosphoricons.Bold
import com.adamglin.phosphoricons.Regular
+import com.adamglin.phosphoricons.regular.CaretRight
import com.adamglin.phosphoricons.fill.ArrowCircleDown
import com.adamglin.phosphoricons.fill.Check
import com.adamglin.phosphoricons.fill.MagnifyingGlass
@@ -272,6 +276,13 @@ fun PlaylistScreen(
// one on screen.
val asContext = sort == TrackSort.ORIGINAL && !descending && query.isBlank()
+ // Whether the top songs are shown in full.
+ //
+ // An artist page is several sections and the songs are one of them, so it
+ // opens on the handful the reference shows and the heading is the way to
+ // the rest. Kept per artist: opening a second artist starts closed again.
+ var topSongsOpen by remember(state.uri) { mutableStateOf(false) }
+
// Derived, not stored: keeping a second list in state would leave the two
// able to disagree after a reload.
val visible = remember(state.tracks, query, sort, descending) {
@@ -314,6 +325,13 @@ fun PlaylistScreen(
// image it is not displaying is what leaves the header and the page below it
// visibly two different browns.
val accent by rememberArtworkColor(state.heroUrl ?: state.coverUrl ?: state.artworkUrl)
+
+ // The colour of the picture's own bottom edge, which is what the page below
+ // it carries on in; see rememberArtworkFootColor.
+ val heroFoot by rememberArtworkFootColor(
+ (state.heroUrl ?: state.coverUrl ?: state.artworkUrl)
+ .takeIf { state.heroUrl != null || !state.heroPending },
+ )
// The catalogue's own colour for the page where there is one, and a colour
// worked out from the cover where there is not. Theirs is chosen for the
// record; ours is the most common colour in a photograph, which on a
@@ -324,16 +342,45 @@ fun PlaylistScreen(
// its icons are a green-tinted white, and that is most of why the controls
// look like part of the picture rather than pasted onto it. A sixth of the
// page colour is enough to see and not enough to read as grey.
- val pageInk = remember(accent, state.tintHex) {
- val source = state.tintHex
+ // Not remembered: the tint it is built from now depends on which way the
+ // app is being read, and that changes under the composition rather than
+ // with the record.
+ val inkSource = remember(accent, state.tintHex) {
+ state.tintHex
?.let { hex -> runCatching { Color(android.graphics.Color.parseColor("#$hex")) }.getOrNull() }
?: accent
- source?.let(::inkTintedBy) ?: Color.White
}
- val pageColor = remember(accent, state.tintHex) {
- state.tintHex?.let(::tintOf) ?: pageColorFor(accent)
+ // Not remembered: both halves of this read the theme now, so the answer
+ // changes when the system does. It is two lerps.
+ // The record's own colour, as dark or as light as it is.
+ //
+ // Not taken up towards paper on the light side, which is what had a page
+ // the reference draws in dark brown coming out pink: the catalogue picked
+ // that colour to be a page, and the reference uses it the same way whether
+ // the phone is set to light or dark. The app's own chrome still follows the
+ // system; this is the record's, and it owns its ground.
+ val pageColor = if (state.tintHex != null) {
+ pageColorForHex(state.tintHex, lift = false)
+ } else {
+ footToneFor(heroFoot ?: accent, mix = 0.5f, lift = false)
+ }
+
+ // And the ink this page needs, which its own ground decides — not the
+ // system's setting. A brown page wants light letters in both settings, and
+ // that is exactly what the reference does; see inkOn.
+ // The catalogue's own ink for this page where it gave one — which is what
+ // makes the letters the same letters as the reference's, rather than a
+ // near-white we worked out ourselves and got slightly pink.
+ val catalogueInk = remember(state.inkHex) {
+ state.inkHex?.let { hex ->
+ runCatching { Color(android.graphics.Color.parseColor("#$hex")) }.getOrNull()
+ }
}
+ val baseInk = dev.lelonio.square.ui.theme.inkOn(pageColor)
+ val pageInk = catalogueInk
+ ?: inkSource?.let { inkTintedBy(it, baseInk) }
+ ?: baseInk
// What the glass on this screen refracts.
//
@@ -397,6 +444,39 @@ fun PlaylistScreen(
val screenHeight = androidx.compose.ui.platform.LocalConfiguration.current.screenHeightDp.dp
val floorStart = ((heroHeight + 40.dp) / screenHeight).coerceIn(0.35f, 0.95f)
+ // How tall the picture itself is, which is not the same as how tall the
+ // header is: the catalogue files some artists as a tall portrait and some
+ // as a square, and each is drawn at the shape it was made in. What is left
+ // of the header below it is the picture carrying on, blurred.
+ val screenWidth = androidx.compose.ui.platform.LocalConfiguration.current.screenWidthDp.dp
+ val artHeight = state.heroAspect
+ ?.let { (screenWidth / it).coerceIn(200.dp, heroHeight) }
+ ?: heroHeight
+
+ /** Where the picture's own bottom edge falls, as a fraction of the screen. */
+ val heroFraction = (artHeight / screenHeight).coerceIn(0.3f, 0.95f)
+
+
+ // Everything on this page reads the app's ink, and on this page the app's
+ // ink is the page's own: see LocalInkOverride. It saves every row, label
+ // and icon here from having to know that a record's page does not follow
+ // the system's light and dark.
+ // Everything here reads either the app's ink or Material's own colours, and
+ // on this page both have to come from the record rather than from the
+ // phone: a dark brown page in the system's light setting was drawing its
+ // track titles in the light theme's near-black.
+ androidx.compose.runtime.CompositionLocalProvider(
+ dev.lelonio.square.ui.theme.LocalInkOverride provides pageInk,
+ androidx.compose.material3.LocalContentColor provides pageInk,
+ ) {
+ MaterialTheme(
+ colorScheme = MaterialTheme.colorScheme.copy(
+ onSurface = pageInk,
+ onSurfaceVariant = pageInk.copy(alpha = 0.66f),
+ onBackground = pageInk,
+ ),
+ typography = MaterialTheme.typography,
+ ) {
Box(Modifier.fillMaxSize()) {
// The page, without the things that sample it.
//
@@ -413,24 +493,16 @@ fun PlaylistScreen(
Box(
Modifier
.fillMaxSize()
- // Opaque, so the app-wide blurred artwork of the playing track
- // does not show through and re-tint the page.
- .background(
- Brush.verticalGradient(
- // Held flat until below the header, then falling away.
- //
- // Not a fixed fraction, which is what this was: the
- // header's last row is opaque page colour, so wherever
- // the fall starts above its bottom edge the page under
- // it is already darker — and the two meet as a line
- // across the screen. Starting the fall where the header
- // ends is what makes the picture and the page one
- // surface.
- 0f to pageColor,
- floorStart to pageColor,
- 1f to PageFloor,
- ),
- )
+ // One colour, held all the way down, and the picture ends on it.
+ //
+ // The player is the screen made of the record — there the cover
+ // is carried past its own edge and nothing covers it. A page is
+ // not that: it is a list with a picture at the top, and the
+ // reference gives it a single flat ground, the colour the
+ // catalogue filed for this record, with the photograph
+ // dissolving into that colour rather than into a blurred
+ // continuation of itself.
+ .background(pageColor)
.layerBackdrop(pageBackdrop),
) {
// Every page is its own picture, filling the top of the screen:
@@ -454,6 +526,7 @@ fun PlaylistScreen(
heroPx = heroPx,
collapsedPx = collapsedPx,
collapse = collapseFraction,
+ imageAspect = state.heroAspect,
)
}
@@ -527,22 +600,6 @@ fun PlaylistScreen(
)
}
- // Behind the "i", and above the list rather than inside it. On the
- // reference this is a screen of its own; unfolding it under the
- // photograph says the same thing without taking the reader off the page
- // they came for — and outside the lazy list, because a row that is not
- // currently composed does not notice the button being pressed.
- if (isArtist) {
- AnimatedVisibility(visible = infoOpen) {
- ArtistAbout(
- followers = state.followers,
- genres = state.genres,
- origin = state.origin,
- bio = state.notes,
- )
- }
- }
-
LazyColumn(
state = listState,
// Recorded so the sort menu has something to blur. It opens over
@@ -555,6 +612,29 @@ fun PlaylistScreen(
.nestedScroll(headerScroll),
contentPadding = PaddingValues(bottom = contentPadding.calculateBottomPadding()),
) {
+ // Behind the "i". On the reference this is a screen of its own;
+ // unfolding it under the photograph says the same thing without
+ // taking the reader off the page they came for.
+ //
+ // Inside the list, not above it. Above it, in the column that holds
+ // the header, it took its height out of the list's — and a bio long
+ // enough to fill the rest of the screen left the list with none, so
+ // opening the "i" stopped the page scrolling entirely. The button
+ // that opens it is still outside the list, which is what the old
+ // note here was actually about.
+ if (isArtist) {
+ item(contentType = "about") {
+ AnimatedVisibility(visible = infoOpen) {
+ ArtistAbout(
+ followers = state.followers,
+ genres = state.genres,
+ origin = state.origin,
+ bio = state.notes,
+ )
+ }
+ }
+ }
+
if (isArtist) {
state.latest?.let { release ->
item(contentType = "latestRelease") {
@@ -599,6 +679,12 @@ fun PlaylistScreen(
sort = sort,
onSortOpen = { sortOpen = it },
onAnchor = { sortAnchor = it },
+ // Only where there is more than what is shown.
+ expandable = isArtist &&
+ query.isBlank() &&
+ visible.size > TOP_SONGS,
+ expanded = topSongsOpen,
+ onToggle = { topSongsOpen = !topSongsOpen },
)
}
@@ -681,7 +767,13 @@ fun PlaylistScreen(
}
else -> itemsIndexed(
- items = visible,
+ // Cut to the first few on an artist, unless the heading has
+ // been opened; every other page shows what it holds.
+ items = if (isArtist && !topSongsOpen && query.isBlank()) {
+ visible.take(TOP_SONGS)
+ } else {
+ visible
+ },
// Index in the key as well as the URI: a playlist may hold
// the same track twice, and duplicate keys crash the list.
key = { index, track -> "$index ${track.uri}" },
@@ -947,6 +1039,8 @@ fun PlaylistScreen(
}
}
+ }
+ }
}
/**
@@ -1273,6 +1367,8 @@ private fun HeroArt(
heroPx: Int,
collapsedPx: Int,
collapse: () -> Float,
+ /** The picture's own proportions, where the catalogue gave them. */
+ imageAspect: Float? = null,
) {
// The picture and its fade are the same everywhere the app shows a cover
// large — here and in the player; see HeroBackdrop. What belongs to this
@@ -1282,6 +1378,33 @@ private fun HeroArt(
title = name,
pageColor = pageColor,
motionUrl = motionUrl,
+ imageAspect = imageAspect,
+ // Measured against the reference rather than chosen.
+ //
+ // Ours was flat page colour by 38% of the way down the screen; theirs
+ // still has the curtain behind the name at 44% and does not finish
+ // until past halfway. A picture that ends above the title leaves the
+ // title sitting on a panel, which is the difference you can see between
+ // the two screens even when the colour underneath is identical.
+ // Late, now that the picture is drawn at its own shape rather than
+ // cropped into the header's.
+ //
+ // These are fractions of the picture, not of the screen. While it was
+ // stretched over the whole header, starting at 44% put the fade
+ // somewhere near the bottom of the frame; at its own height that same
+ // number has the photograph half gone by its middle. What is wanted is
+ // a picture that reads as a picture and gives way in its last stretch —
+ // which is what the player does, and the reference with it.
+ softenFrom = if (imageAspect != null) 0.58f else 0.44f,
+ // Finished before the edge, not on it: a picture that is one percent
+ // still there where it stops has a border, and that border is the line.
+ // A long tail. The reference still has the curtain faintly behind its
+ // name and buttons at 48% of the screen and only settles past 60%; ours
+ // was flat page colour by 42%, which is the picture ending rather than
+ // giving way. Past the picture's own foot the fade has nothing left to
+ // thin, so the length has to come from starting it earlier and taking
+ // it all the way to the edge.
+ softenTo = if (imageAspect != null) 1f else 0.96f,
modifier = Modifier
.fillMaxWidth()
.heroCollapse(heroPx, collapsedPx, collapse),
@@ -1375,10 +1498,25 @@ private fun ArtistHeader(
// The photo behind it is somebody's face and cannot be
// relied on for contrast. A soft shadow costs nothing
// and keeps the name readable over a white shirt.
- shadow = Shadow(Color.Black.copy(alpha = 0.5f), Offset(0f, 2f), 18f),
+ // Cast the other way on a light page, where a black
+ // shadow under dark letters is a smudge and what the
+ // name needs is a halo.
+ shadow = Shadow(
+ if (ink.luminance() > 0.5f) {
+ Color.Black.copy(alpha = 0.5f)
+ } else {
+ Color.White.copy(alpha = 0.75f)
+ },
+ Offset(0f, 2f),
+ 18f,
+ ),
),
fontWeight = FontWeight.Black,
- color = Color.White,
+ // The name sits partly on the photograph and partly on the
+ // page, so it takes the page's ink rather than a fixed
+ // white: on a light page a white name over a pale ground is
+ // not a name.
+ color = ink,
textAlign = TextAlign.Center,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
@@ -1416,11 +1554,17 @@ private fun ArtistHeader(
contentDescription = stringResource(R.string.play),
tint = pageColor,
modifier = Modifier
- .size(28.dp)
- // The glyph's own weight sits left of the circle's
- // centre; nudged back, or the triangle looks like it
- // is falling out of the button.
- .padding(start = 3.dp),
+ // Measured off the reference: their triangle is
+ // about 45% of the circle across, and ours was 30%
+ // — a small mark in a large button, which reads as
+ // the button being empty. The glyph carries its own
+ // margin inside the icon's box, so the box has to be
+ // larger than the triangle wanted.
+ .size(40.dp)
+ // The triangle's weight sits left of its own centre;
+ // nudged back so it looks centred rather than
+ // measuring centred.
+ .padding(start = 2.dp),
)
}
@@ -1829,6 +1973,10 @@ private fun SectionHeader(
onSortOpen: (Boolean) -> Unit,
/** Where the sort button is, for the menu drawn above the list. */
onAnchor: (IntOffset) -> Unit,
+ /** Whether there is more of this section than the page is showing. */
+ expandable: Boolean = false,
+ expanded: Boolean = false,
+ onToggle: () -> Unit = {},
) {
Row(
Modifier
@@ -1836,6 +1984,23 @@ private fun SectionHeader(
.padding(start = 24.dp, end = 14.dp, top = 22.dp, bottom = 6.dp),
verticalAlignment = Alignment.CenterVertically,
) {
+ // The heading itself is the way in, which is how the reference does it:
+ // the title and the mark after it are one target, and there is no
+ // separate "see all" anywhere on the page.
+ Row(
+ Modifier
+ .weight(1f)
+ .then(
+ if (expandable) {
+ Modifier
+ .clip(RoundedCornerShape(8.dp))
+ .pressable(onToggle, pressedScale = 0.97f)
+ } else {
+ Modifier
+ },
+ ),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
Text(
title,
style = if (large) {
@@ -1844,9 +2009,30 @@ private fun SectionHeader(
MaterialTheme.typography.titleMedium
},
fontWeight = FontWeight.Bold,
- modifier = Modifier.weight(1f),
)
+ if (expandable) {
+ // Pointing on, and turning down once the rest is out: the same mark
+ // saying both "there is more" and "this is all of it".
+ val turn by animateFloatAsState(
+ targetValue = if (expanded) 90f else 0f,
+ animationSpec = tween(220),
+ label = "sectionCaret",
+ )
+ Icon(
+ PhosphorIcons.Regular.CaretRight,
+ contentDescription = stringResource(
+ if (expanded) R.string.show_less else R.string.show_all,
+ ),
+ tint = MaterialTheme.colorScheme.onSurfaceVariant,
+ modifier = Modifier
+ .padding(start = 6.dp)
+ .size(16.dp)
+ .graphicsLayer { rotationZ = turn },
+ )
+ }
+ }
+
IconButton(
onClick = { onSortOpen(true) },
modifier = Modifier.onGloballyPositioned {
@@ -1870,6 +2056,9 @@ private fun SectionHeader(
}
}
+/** How many songs an artist page opens on; the heading holds the rest. */
+private const val TOP_SONGS = 5
+
/** What the hero shrinks to: a bar, under the status bar's own inset. */
private val COLLAPSED_BAR_HEIGHT = 56.dp
@@ -1892,16 +2081,6 @@ private const val HERO_BLUR_PX = 240
/** Soft enough to be a wash, sharp enough to keep the picture's shapes. */
private val HeroBlur = BlurTransformation(radius = 10, passes = 2)
-/**
- * A page tone from the six hex digits the catalogue files with the artwork.
- *
- * Darkened, but much less than a colour taken out of a photograph: this one was
- * picked to be a background and is already the right kind of colour, where a
- * dominant colour arrives at whatever saturation the picture had.
- */
-private fun tintOf(hex: String): Color =
- dev.lelonio.square.ui.theme.pageColorForHex(hex)
-
/**
* White, carrying a colour's hue and none of its darkness.
*
@@ -1911,13 +2090,15 @@ private fun tintOf(hex: String): Color =
* tint belongs, and only then mixing gives a purple-white on a purple page and a
* green-white on a green one.
*/
-private fun inkTintedBy(color: Color): Color {
+private fun inkTintedBy(color: Color, ink: Color): Color {
val hsv = FloatArray(3)
android.graphics.Color.colorToHSV(color.toArgb(), hsv)
- if (hsv[1] < 0.06f) return Color.White
+ if (hsv[1] < 0.06f) return ink
hsv[1] = hsv[1].coerceIn(0.5f, 1f)
- hsv[2] = 0.92f
- return lerp(Color.White, Color(android.graphics.Color.HSVToColor(hsv)), 0.26f)
+ // Bright where the ink is light and deep where it is dark: the tint is the
+ // page's either way, and only the direction changes.
+ hsv[2] = if (ink.luminance() > 0.5f) 0.92f else 0.36f
+ return lerp(ink, Color(android.graphics.Color.HSVToColor(hsv)), 0.26f)
}
@@ -2394,13 +2575,17 @@ private fun ArtistAbout(
@Composable
private fun FollowPill(following: Boolean, onClick: () -> Unit) {
val shape = RoundedCornerShape(percent = 50)
+ // Filled with the ink and lettered in whatever the ink is not: white on
+ // black over a dark page, black on white over a light one.
+ val pillInk = dev.lelonio.square.ui.theme.Ink
+ val onPillInk = if (dev.lelonio.square.ui.theme.lightPage()) Color.White else Color.Black
Row(
Modifier
.clip(shape)
- .background(if (following) Color.Transparent else Color.White, shape)
+ .background(if (following) Color.Transparent else pillInk, shape)
.then(
if (following) {
- Modifier.border(1.dp, Color.White.copy(alpha = 0.4f), shape)
+ Modifier.border(1.dp, pillInk.copy(alpha = 0.4f), shape)
} else {
Modifier
},
@@ -2413,7 +2598,7 @@ private fun FollowPill(following: Boolean, onClick: () -> Unit) {
stringResource(if (following) R.string.following else R.string.follow),
style = MaterialTheme.typography.labelLarge,
fontWeight = FontWeight.SemiBold,
- color = if (following) Color.White else Color.Black,
+ color = if (following) pillInk else onPillInk,
maxLines = 1,
)
}
diff --git a/app/src/main/java/dev/lelonio/square/ui/player/MiniPlayer.kt b/app/src/main/java/dev/lelonio/square/ui/player/MiniPlayer.kt
index 62a4674..29c5733 100644
--- a/app/src/main/java/dev/lelonio/square/ui/player/MiniPlayer.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/player/MiniPlayer.kt
@@ -286,11 +286,17 @@ fun MiniPlayer(
}
/**
- * Fixed light, like everything else on the glass: what sits behind this bar is
- * the darkened artwork, not a page colour.
+ * The ink on the glass, on whichever side of the app it is.
+ *
+ * Fixed light is what this was, on the reasoning that behind the bar is the
+ * darkened artwork rather than a page colour. That stopped being true with the
+ * light setting: there the film over the artwork is white, and near-white text
+ * on it is not text. It is the app's own ink, like everywhere else.
*/
-internal val MiniPlayerInk = Color(0xFFF7F8FA)
-internal val MiniPlayerInkDim = Color(0xFFF7F8FA).copy(alpha = 0.66f)
+internal val MiniPlayerInk: Color
+ @Composable get() = dev.lelonio.square.ui.theme.Ink
+internal val MiniPlayerInkDim: Color
+ @Composable get() = dev.lelonio.square.ui.theme.InkDim
/**
* The green everyone already reads as "this is coming out of something else".
diff --git a/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt b/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt
index 89be81a..2547885 100644
--- a/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt
@@ -220,6 +220,8 @@ fun PlayerScreen(
* belongs to its album, which is where the reference's own player takes it
* from as well. Null falls back to the square cover.
*/
+ /** The colours the catalogue filed with this artwork; see CoverAura. */
+ catalogPalette: List<String> = emptyList(),
coverHeroUrl: String? = null,
/** And the moving version of it, for the records that have one. */
coverMotionUrl: String? = null,
@@ -378,10 +380,24 @@ fun PlayerScreen(
var ambient by remember { mutableStateOf<AmbientEdges?>(null) }
LaunchedEffect(videoOn) { if (!videoOn) ambient = null }
- val auraColors by dev.lelonio.square.ui.theme.rememberArtworkPalette(
+ val readPalette by dev.lelonio.square.ui.theme.rememberArtworkPalette(
state.artworkUrl.takeIf { canvas == null },
)
+ // The catalogue's own colours for this artwork where it has them.
+ //
+ // Ours are swatches pulled out of the bitmap by whatever reads as most
+ // vivid, and on a crimson sleeve with a black rose on it that came back
+ // blue — a light behind the cover in a colour the cover does not contain.
+ // Theirs were chosen to sit on this picture, and they are the four the
+ // reference itself uses.
+ val catalogAura = remember(catalogPalette) {
+ catalogPalette.mapNotNull { hex ->
+ runCatching { Color(android.graphics.Color.parseColor("#$hex")) }.getOrNull()
+ }
+ }
+ val auraColors = if (canvas == null && catalogAura.isNotEmpty()) catalogAura else readPalette
+
// The tone the cover fades into, worked out the same way the pages do it.
val coverAccent by dev.lelonio.square.ui.theme.rememberArtworkColor(state.artworkUrl)
val coverTone = dev.lelonio.square.ui.theme.pageColorFor(coverAccent)
@@ -527,7 +543,22 @@ fun PlayerScreen(
)
},
) {
- CoverAura(colors = auraColors, playing = state.isPlaying)
+ // Only where there is no picture to expand.
+ //
+ // The reference puts no invented light on this screen at
+ // all: what fills it above and below the cover is the cover
+ // itself, blurred and carried past its own edges. Coloured
+ // beams over that are a second, competing source — and being
+ // colours *chosen* rather than colours present, they can be
+ // ones the sleeve does not contain. A crimson cover was
+ // reading blue at the foot of the screen for exactly that
+ // reason. So this is now the stand-in for a screen with no
+ // artwork behind it, and nothing else.
+ if (coverHeroUrl == null && coverSquareUrl == null &&
+ state.artworkUrl == null
+ ) {
+ CoverAura(colors = auraColors, playing = state.isPlaying)
+ }
}
}
}
@@ -1851,13 +1882,13 @@ private fun KaraokeBadge(amount: Float, backdrop: Backdrop, onClick: () -> Unit)
contentDescription = null,
// White, like the control it refers to: an accent pulled from the
// cover lands anywhere, including on the cover itself.
- tint = Color.White,
+ tint = GlassInk,
modifier = Modifier.size(13.dp),
)
Text(
stringResource(R.string.karaoke_on, (amount * 100).toInt()),
style = MaterialTheme.typography.labelMedium,
- color = Color.White,
+ color = GlassInk,
modifier = Modifier.padding(start = 6.dp),
)
}
@@ -1928,14 +1959,19 @@ private fun ToggleIcon(
}
/**
- * Fixed light, not themed.
+ * The ink on every glass surface in the app.
*
- * What sits behind every control here is album art under a dark wash, not the
- * app's page colour, so the light/dark scheme says nothing about what is
- * readable.
+ * Fixed white was the reasoning here for a long time, and it held while the
+ * only thing behind a control was album art under a *dark* wash. With the
+ * system's light setting that wash goes the other way — the artwork is taken up
+ * towards paper, and the film over it is white — so white ink on it is nothing
+ * at all. It follows the app's own ink now, which is what decides that
+ * direction; see SquareTheme.
*/
-internal val GlassInk = Color.White
-internal val GlassInkDim = Color.White.copy(alpha = 0.68f)
+internal val GlassInk: Color
+ @Composable get() = dev.lelonio.square.ui.theme.Ink
+internal val GlassInkDim: Color
+ @Composable get() = dev.lelonio.square.ui.theme.Ink.copy(alpha = 0.68f)
/**
* The film every glass surface is tinted with.
@@ -1944,7 +1980,14 @@ internal val GlassInkDim = Color.White.copy(alpha = 0.68f)
* each picked its own: the tab bar came out noticeably paler than the mini
* player and the search button beside it.
*/
-internal val GlassFilm = Color.White.copy(alpha = 0.12f)
+internal val GlassFilm: Color
+ @Composable get() = if (dev.lelonio.square.ui.theme.lightPage()) {
+ // More of it on the light side: a twelfth of white over a pale page is
+ // not a surface, and the controls have to sit on something.
+ Color.White.copy(alpha = 0.45f)
+ } else {
+ Color.White.copy(alpha = 0.12f)
+ }
/**
* The lyrics, centre stage.
diff --git a/app/src/main/java/dev/lelonio/square/ui/theme/ArtworkColor.kt b/app/src/main/java/dev/lelonio/square/ui/theme/ArtworkColor.kt
index 7fa24a7..cd17950 100644
--- a/app/src/main/java/dev/lelonio/square/ui/theme/ArtworkColor.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/theme/ArtworkColor.kt
@@ -9,6 +9,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.luminance
+import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.palette.graphics.Palette
import coil.imageLoader
@@ -25,6 +27,78 @@ import kotlinx.coroutines.withContext
*/
val PageFloor = Color(0xFF0A0A0C)
+/**
+ * And where it ends up on the other side, when the system is set to light.
+ *
+ * Not pure white, for the same reason the floor is not pure black: a page that
+ * ends on #FFF has no edge against a white status bar or a white sheet over it.
+ */
+val PageCeiling = Color(0xFFF1F1F5)
+
+/**
+ * The same colour, taken up towards paper instead of down towards the floor.
+ *
+ * Mixing towards a neutral ceiling is what this did first, and it bleaches:
+ * a page that measured 45% saturated on the reference came out at 14%, which is
+ * a grey with a rumour of pink in it rather than the record's colour. Holding
+ * the hue, easing the saturation down by as much as the mix asks for and
+ * setting the brightness where paper belongs keeps a light page recognisably
+ * the colour of what is playing.
+ */
+private fun liftedTone(colour: Color, mix: Float): Color {
+ val hsv = FloatArray(3)
+ android.graphics.Color.colorToHSV(colour.toArgb(), hsv)
+ return Color(
+ android.graphics.Color.HSVToColor(
+ floatArrayOf(
+ hsv[0],
+ (hsv[1] * (1f - mix * 0.55f)).coerceIn(0.08f, 0.46f),
+ (0.97f - mix * 0.10f).coerceIn(0.82f, 0.97f),
+ ),
+ ),
+ )
+}
+
+/**
+ * The ink a surface needs, given the colour it is actually sitting on.
+ *
+ * Two different things decide ink in this app, and conflating them is what put
+ * white letters on a pale pink page. The app's own chrome — bars, sheets, the
+ * pages made of shelves — follows the system's setting. A record's page and the
+ * player do not: those are the colour of the artwork, chosen by the catalogue
+ * or read off the picture, and that colour is as dark as it is whichever way
+ * the phone is set. What can be read on it is decided by it, not by the phone.
+ */
+fun inkOn(ground: Color): Color =
+ if (ground.luminance() > 0.42f) Color(0xFF15161A) else Color(0xFFF7F8FA)
+
+/**
+ * An ink that overrides the theme's, for the surfaces that own their colour.
+ *
+ * Provided by a record's page and by the player, read by [Ink] — so every
+ * caller that already asks for the app's ink gets the right one on those
+ * screens without knowing anything about them.
+ */
+val LocalInkOverride = androidx.compose.runtime.compositionLocalOf<Color?> { null }
+
+/** Which way this app's colours are being taken; see SquareTheme. */
+@Composable
+fun lightPage(): Boolean = LocalLightTheme.current
+
+/**
+ * What a scrim is made of on this side of the app.
+ *
+ * A scrim exists to put distance between a picture and the text over it, and
+ * which way that distance goes depends on the ink: black under light ink, white
+ * under dark. The same gradient with this colour in it works both ways round.
+ */
+@Composable
+fun scrimColor(): Color = if (lightPage()) Color.White else Color.Black
+
+/** The colour every page's own colour is mixed towards. */
+@Composable
+fun pageGround(): Color = if (lightPage()) PageCeiling else PageFloor
+
/**
* The page tone for a cover.
*
@@ -33,8 +107,20 @@ val PageFloor = Color(0xFF0A0A0C)
* fluorescent field. Most of the way to the floor keeps the hue recognisable
* and nothing else. A null cover falls back to the floor rather than to grey.
*/
-fun pageColorFor(accent: Color?): Color =
- accent?.let { androidx.compose.ui.graphics.lerp(it, PageFloor, 0.7f) } ?: PageFloor
+@Composable
+fun pageColorFor(accent: Color?): Color {
+ val ground = pageGround()
+ // Less of the ground on the light side. Taken as far towards paper as it is
+ // taken towards the floor, a colour arrives as a pastel with no record left
+ // in it — and the whole point of these pages is that they are the colour of
+ // what is playing.
+ if (accent == null) return ground
+ return if (lightPage()) {
+ liftedTone(accent, 0.62f)
+ } else {
+ androidx.compose.ui.graphics.lerp(accent, ground, 0.7f)
+ }
+}
/**
* The page tone the other catalogue chose for a record, as six hex digits.
@@ -48,10 +134,25 @@ fun pageColorFor(accent: Color?): Color =
*
* Null, or anything unparseable, ends on the floor like everything else.
*/
-fun pageColorForHex(hex: String?): Color = hex
- ?.let { runCatching { Color(android.graphics.Color.parseColor("#$it")) }.getOrNull() }
- ?.let { androidx.compose.ui.graphics.lerp(it, PageFloor, 0.42f) }
- ?: PageFloor
+@Composable
+fun pageColorForHex(hex: String?, lift: Boolean = true): Color {
+ // A surface that owns its colour mixes towards the floor whichever way the
+ // phone is set. Reading the ground from the theme is what put a page the
+ // catalogue files as #311a1a on screen at (125,108,109): the mix was right
+ // and it was being made towards paper.
+ val ground = if (lift) pageGround() else PageFloor
+ val picked = hex
+ ?.let { runCatching { Color(android.graphics.Color.parseColor("#$it")) }.getOrNull() }
+ ?: return ground
+ return when {
+ lift && lightPage() -> liftedTone(picked, 0.34f)
+ // Barely touched where the page owns it: the catalogue chose this
+ // colour to be a page and the reference draws it as it is. The little
+ // that is taken off is for the ink, which has to sit on it.
+ !lift -> androidx.compose.ui.graphics.lerp(picked, ground, 0.12f)
+ else -> androidx.compose.ui.graphics.lerp(picked, ground, 0.42f)
+ }
+}
/**
* The dominant colour of an artwork URL, for seeding the theme.
@@ -94,8 +195,15 @@ private val cached = object : LinkedHashMap<String, Color>(16, 0.75f, true) {
* will look for it, at the same time as the picture.
*/
suspend fun warmArtworkColor(context: Context, url: String) {
- if (cached.containsKey(url)) return
- extractDominant(context, url)?.let { cached[url] = it }
+ if (!cached.containsKey(url)) {
+ extractDominant(context, url)?.let { cached[url] = it }
+ }
+ // And the foot of it, for the same reason and off the same decode: the
+ // player's whole background is that colour, so arriving without it is the
+ // screen changing twice.
+ if (!cachedFeet.containsKey(url)) {
+ extractFoot(context, url)?.let { cachedFeet[url] = it }
+ }
}
/**
@@ -189,3 +297,131 @@ private suspend fun extractDominant(context: Context, url: String): Color? =
Color(rgb)
}.getOrNull()
}
+
+/**
+ * The colour the bottom of a cover actually is.
+ *
+ * [rememberArtworkColor] answers with the colour that *identifies* a record —
+ * the loudest thing in it, wherever it happens to sit. That is right for
+ * tinting a page and wrong for continuing a picture: a sleeve whose lower half
+ * is a sunset identifies as the bright pink at the top of it, so a screen
+ * ending on that pink has the picture and the ground disagreeing across the
+ * seam even when the fade itself is perfect.
+ *
+ * This reads the band the fade actually meets, so the screen below the artwork
+ * carries on from where the artwork left off — which is what the reference is
+ * doing, and why its fade reads as the cover continuing rather than as the
+ * cover ending.
+ *
+ * Averaged around the hue circle rather than in RGB. A straight mean of a busy
+ * band is grey — opposite hues cancel — so the hue is a vector mean weighted by
+ * how colourful each pixel is, and saturation and brightness are means of their
+ * own, clamped to what a background can be.
+ */
+@Composable
+fun rememberArtworkFootColor(artworkUrl: String?): State<Color?> {
+ val context = LocalContext.current
+ val state = remember { mutableStateOf<Color?>(null) }
+
+ LaunchedEffect(artworkUrl) {
+ if (artworkUrl == null) {
+ state.value = null
+ return@LaunchedEffect
+ }
+ cachedFeet[artworkUrl]?.let {
+ state.value = it
+ return@LaunchedEffect
+ }
+ state.value = extractFoot(context, artworkUrl)?.also { cachedFeet[artworkUrl] = it }
+ }
+ return state
+}
+
+private val cachedFeet = object : LinkedHashMap<String, Color>(16, 0.75f, true) {
+ override fun removeEldestEntry(eldest: Map.Entry<String, Color>?) = size > 64
+}
+
+/**
+ * The ground colour for a picture that is meant to carry on into it.
+ *
+ * Mixed down far less than [pageColorFor] does. That one is taming a colour
+ * picked for being loud; this one is already the colour of a piece of the
+ * picture, and taking it most of the way to the floor would undo the only
+ * thing it was read for.
+ */
+@Composable
+fun footToneFor(foot: Color?, mix: Float = 0.34f, lift: Boolean = true): Color {
+ val ground = if (lift) pageGround() else PageFloor
+ if (foot == null) return ground
+ return if (lift && lightPage()) {
+ liftedTone(foot, mix)
+ } else {
+ androidx.compose.ui.graphics.lerp(foot, ground, mix)
+ }
+}
+
+/** How much of the cover, from the bottom, counts as the band the fade meets. */
+private const val FOOT_BAND = 0.18f
+
+private suspend fun extractFoot(context: Context, url: String): Color? =
+ withContext(Dispatchers.IO) {
+ runCatching {
+ val request = ImageRequest.Builder(context)
+ // The same request the dominant colour makes, so the two share
+ // one decode and one cache entry.
+ .data(url)
+ .size(96)
+ .allowHardware(false)
+ .build()
+
+ val bitmap = (context.imageLoader.execute(request) as? SuccessResult)
+ ?.drawable
+ ?.let { (it as? android.graphics.drawable.BitmapDrawable)?.bitmap }
+ ?: return@runCatching null
+
+ val height = bitmap.height
+ val width = bitmap.width
+ val from = (height * (1f - FOOT_BAND)).toInt().coerceIn(0, height - 1)
+
+ var x = 0.0
+ var y = 0.0
+ var saturation = 0f
+ var value = 0f
+ var weight = 0f
+ var count = 0
+ val hsv = FloatArray(3)
+
+ for (py in from until height) {
+ for (px in 0 until width) {
+ android.graphics.Color.colorToHSV(bitmap.getPixel(px, py), hsv)
+ // Grey pixels still count towards the hue, but barely: the
+ // small constant is what keeps an all-grey band from
+ // dividing by nothing.
+ val w = hsv[1] * hsv[2] + 0.05f
+ val radians = Math.toRadians(hsv[0].toDouble())
+ x += kotlin.math.cos(radians) * w
+ y += kotlin.math.sin(radians) * w
+ saturation += hsv[1] * w
+ value += hsv[2]
+ weight += w
+ count++
+ }
+ }
+ if (count == 0 || weight <= 0f) return@runCatching null
+
+ val hue = ((Math.toDegrees(kotlin.math.atan2(y, x)).toFloat()) + 360f) % 360f
+ Color(
+ android.graphics.Color.HSVToColor(
+ floatArrayOf(
+ hue,
+ // Floors and ceilings, not the raw means: a band that
+ // is nearly white gives a background nothing can be
+ // read on, and one that is nearly black gives back the
+ // flat panel this whole treatment removed.
+ (saturation / weight).coerceIn(0.16f, 0.85f),
+ (value / count).coerceIn(0.18f, 0.72f),
+ ),
+ ),
+ )
+ }.getOrNull()
+ }
diff --git a/app/src/main/java/dev/lelonio/square/ui/theme/Theme.kt b/app/src/main/java/dev/lelonio/square/ui/theme/Theme.kt
index ac368f1..7766145 100644
--- a/app/src/main/java/dev/lelonio/square/ui/theme/Theme.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/theme/Theme.kt
@@ -8,6 +8,8 @@ import androidx.compose.material3.Typography
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
@@ -27,12 +29,12 @@ import androidx.core.view.WindowCompat
/**
* Glass over the album art.
*
- * The scheme is deliberately one-sided now. The paper version had a light and a
- * dark half because the page was opaque and had to match the system; here the
- * page *is* the artwork under a dark wash, so there is only ever dark glass with
- * light ink on it. Following the system theme would mean two backdrops and two
- * sets of legibility rules for a surface whose contrast does not depend on
- * either.
+ * The page is the record that is playing — a colour taken from the artwork,
+ * never a flat sheet — and the system's setting decides which way that colour
+ * is taken. Dark takes it down towards the floor and puts light ink and a dark
+ * film of glass on it; light takes the same colour up towards paper and puts
+ * dark ink and a white film on it. One palette, read in two directions, rather
+ * than two palettes.
*
* `background` is transparent on purpose: whatever draws the backdrop sits
* behind the whole tree, and an opaque page colour would cover it.
@@ -50,6 +52,16 @@ import androidx.core.view.WindowCompat
* colour is as likely to be near-black as near-white, and either one vanishes
* against the wrong background.
*/
+/**
+ * Which side the app is on, said plainly.
+ *
+ * Read off the scheme's own surface at first, and that was wrong in a way that
+ * only showed on the other side: every film in this design is a translucent
+ * *white*, so `surface.luminance()` is 1.0 in both settings — alpha is not part
+ * of luminance. Everything keyed on it would have called the dark theme light.
+ */
+val LocalLightTheme = staticCompositionLocalOf { false }
+
@Composable
fun SquareTheme(
/** Dominant colour of the current artwork, or null before anything plays. */
@@ -67,25 +79,50 @@ fun SquareTheme(
// Keyed on the accent: rebuilding a ColorScheme allocates dozens of colours
// and invalidates every composable that reads MaterialTheme, so doing it on
// each recomposition drags the whole tree along with the seek bar.
- val scheme = remember(animatedAccent) {
- darkColorScheme(
- primary = animatedAccent,
- onPrimary = Color(0xFF0B0D10),
- primaryContainer = GlassFill,
- onPrimaryContainer = Ink,
- secondary = InkDim,
- // See the note above: the backdrop shows through this.
- background = Color.Transparent,
- onBackground = Ink,
- // Glass, not a card: a translucent white film is what every surface
- // in this design is made of, and the refraction on top of it comes
- // from the backdrop library rather than from the colour.
- surface = GlassFill,
- onSurface = Ink,
- surfaceVariant = GlassFillStrong,
- onSurfaceVariant = InkDim,
- outlineVariant = Color.White.copy(alpha = 0.16f),
- )
+ val scheme = remember(animatedAccent, darkTheme) {
+ // The ink and the film are the two things that change side, and both are
+ // read back out of the scheme everywhere else in the app: `Ink` is the
+ // scheme's own onSurface, and the glass takes a white film whenever the
+ // scheme's surface is a light colour. So this is the only place that
+ // knows which way round the app is.
+ val ink = if (darkTheme) DarkInk else LightInk
+ val film = if (darkTheme) DarkFilm else LightFilm
+ val filmStrong = if (darkTheme) DarkFilmStrong else LightFilmStrong
+ if (darkTheme) {
+ darkColorScheme(
+ primary = animatedAccent,
+ onPrimary = Color(0xFF0B0D10),
+ primaryContainer = film,
+ onPrimaryContainer = ink,
+ secondary = ink.copy(alpha = 0.66f),
+ // See the note above: the backdrop shows through this.
+ background = Color.Transparent,
+ onBackground = ink,
+ // Glass, not a card: a translucent film is what every surface in
+ // this design is made of, and the refraction on top of it comes
+ // from the backdrop library rather than from the colour.
+ surface = film,
+ onSurface = ink,
+ surfaceVariant = filmStrong,
+ onSurfaceVariant = ink.copy(alpha = 0.66f),
+ outlineVariant = Color.White.copy(alpha = 0.16f),
+ )
+ } else {
+ lightColorScheme(
+ primary = animatedAccent,
+ onPrimary = Color(0xFFFFFFFF),
+ primaryContainer = film,
+ onPrimaryContainer = ink,
+ secondary = ink.copy(alpha = 0.66f),
+ background = Color.Transparent,
+ onBackground = ink,
+ surface = film,
+ onSurface = ink,
+ surfaceVariant = filmStrong,
+ onSurfaceVariant = ink.copy(alpha = 0.66f),
+ outlineVariant = Color.Black.copy(alpha = 0.14f),
+ )
+ }
}
// System bar icons have to flip with the theme; left alone they are drawn
@@ -94,28 +131,54 @@ fun SquareTheme(
if (!view.isInEditMode) {
SideEffect {
val window = (view.context as android.app.Activity).window
- // Always light icons: the bars sit over the darkened artwork, not
- // over the system's idea of a background.
+ // Dark icons over a light page and light ones over a dark page:
+ // the bars sit over the artwork's own colour, which is taken in
+ // whichever direction the system asked for.
WindowCompat.getInsetsController(window, view).apply {
- isAppearanceLightStatusBars = false
- isAppearanceLightNavigationBars = false
+ isAppearanceLightStatusBars = !darkTheme
+ isAppearanceLightNavigationBars = !darkTheme
}
}
}
- MaterialTheme(colorScheme = scheme, typography = SpotTypography, content = content)
+ CompositionLocalProvider(LocalLightTheme provides !darkTheme) {
+ MaterialTheme(colorScheme = scheme, typography = SpotTypography, content = content)
+ }
}
private val DarkBase = Color(0xFF0D0E11)
private val LightBase = Color(0xFFF1F2F6)
-/** The film every glass surface is tinted with. */
-private val GlassFill = Color.White.copy(alpha = 0.10f)
-private val GlassFillStrong = Color.White.copy(alpha = 0.16f)
+/**
+ * The film every glass surface is tinted with.
+ *
+ * White over a dark page and white-with-more-of-it over a light one: the
+ * material is the same, and what changes is how much of the page is left
+ * showing through. The glass code decides its own tint from whether this colour
+ * is light or dark, so these are also the switch for that; see GlassEffect.
+ */
+private val DarkFilm = Color.White.copy(alpha = 0.10f)
+private val DarkFilmStrong = Color.White.copy(alpha = 0.16f)
+private val LightFilm = Color.White.copy(alpha = 0.55f)
+private val LightFilmStrong = Color.White.copy(alpha = 0.72f)
-/** Text and icons, fixed light — see the note on [SquareTheme]. */
-val Ink = Color(0xFFF7F8FA)
-val InkDim = Color(0xFFF7F8FA).copy(alpha = 0.66f)
+/** Text and icons, on whichever side of the page they have to be read from. */
+private val DarkInk = Color(0xFFF7F8FA)
+private val LightInk = Color(0xFF15161A)
+
+/**
+ * The colour text and icons are drawn in.
+ *
+ * A composable getter rather than a constant, so the eighty-odd places that
+ * name it did not have to learn about the theme: it is the scheme's own
+ * onSurface, which is light over a dark page and dark over a light one.
+ */
+val Ink: Color
+ @Composable get() = LocalInkOverride.current ?: MaterialTheme.colorScheme.onSurface
+
+/** The same, for what is said quietly. */
+val InkDim: Color
+ @Composable get() = Ink.copy(alpha = 0.66f)
/**
* Fallback accent, used until artwork provides one.
@@ -138,11 +201,18 @@ private fun Color.liftFor(background: Color): Color {
)
}
-/** Darken until the colour reads against a near-white background. */
+/**
+ * Darken until the colour reads against a near-white background.
+ *
+ * Taken further than it was. At the old ceiling a mid-tan came out of this
+ * barely touched, and the accent is spent on exactly the things that have to be
+ * found at a glance — the lit tab, the play button, the row that is playing —
+ * so "technically darker than the page" is not enough for it.
+ */
private fun Color.deepenFor(background: Color): Color {
- val ceiling = background.luminance() - 0.42f
+ val ceiling = background.luminance() - 0.62f
if (luminance() <= ceiling) return this
- val amount = ((luminance() - ceiling) * 1.1f).coerceIn(0f, 0.8f)
+ val amount = ((luminance() - ceiling) * 1.6f).coerceIn(0f, 0.86f)
return Color(
red = red * (1f - amount),
green = green * (1f - amount),
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 905e012..0b802b1 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -398,4 +398,6 @@
<string name="canvas">Canvas</string>
<string name="canvas_show">Loop-Clips zeigen</string>
<string name="canvas_note">Das kurze Video, das manche Titel mitbringen. Aus wird es auch nicht geladen.</string>
+ <string name="show_all">Alle anzeigen</string>
+ <string name="show_less">Weniger anzeigen</string>
</resources>
diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml
index fc04aa6..9b7ce32 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -398,4 +398,6 @@
<string name="canvas">Canvas</string>
<string name="canvas_show">Mostrar clips en bucle</string>
<string name="canvas_note">El vídeo corto que traen algunas canciones. Desactivado, tampoco se descarga.</string>
+ <string name="show_all">Mostrar todo</string>
+ <string name="show_less">Mostrar menos</string>
</resources>
diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml
index a70be6e..deff340 100644
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -398,4 +398,6 @@
<string name="canvas">Canvas</string>
<string name="canvas_show">Afficher les clips en boucle</string>
<string name="canvas_note">La courte vidéo que portent certains titres. Désactivé, elle n\'est pas téléchargée non plus.</string>
+ <string name="show_all">Tout afficher</string>
+ <string name="show_less">Afficher moins</string>
</resources>
diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml
index 4597588..1e7ae40 100644
--- a/app/src/main/res/values-hi/strings.xml
+++ b/app/src/main/res/values-hi/strings.xml
@@ -413,4 +413,6 @@
<string name="canvas">Canvas</string>
<string name="canvas_show">लूप क्लिप दिखाएँ</string>
<string name="canvas_note">कुछ गानों के साथ आने वाला छोटा वीडियो. बंद होने पर डाउनलोड भी नहीं होता.</string>
+ <string name="show_all">सभी दिखाएँ</string>
+ <string name="show_less">कम दिखाएँ</string>
</resources>
diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml
index cc16d81..35e30c2 100644
--- a/app/src/main/res/values-it/strings.xml
+++ b/app/src/main/res/values-it/strings.xml
@@ -399,4 +399,6 @@
<string name="canvas">Canvas</string>
<string name="canvas_show">Mostra i video in loop</string>
<string name="canvas_note">Il breve video che alcuni brani portano con sé. Disattivato, non viene nemmeno scaricato.</string>
+ <string name="show_all">Mostra tutto</string>
+ <string name="show_less">Mostra meno</string>
</resources>
diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml
index 4615196..c328144 100644
--- a/app/src/main/res/values-pt/strings.xml
+++ b/app/src/main/res/values-pt/strings.xml
@@ -398,4 +398,6 @@
<string name="canvas">Canvas</string>
<string name="canvas_show">Mostrar clipes em loop</string>
<string name="canvas_note">O vídeo curto que algumas faixas trazem. Desligado, também não é baixado.</string>
+ <string name="show_all">Mostrar tudo</string>
+ <string name="show_less">Mostrar menos</string>
</resources>
diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml
index e4fd9e9..3297c1f 100644
--- a/app/src/main/res/values-tr/strings.xml
+++ b/app/src/main/res/values-tr/strings.xml
@@ -412,4 +412,6 @@
<string name="canvas">Canvas</string>
<string name="canvas_show">Döngü kliplerini göster</string>
<string name="canvas_note">Bazı şarkıların getirdiği kısa video. Kapalıyken indirilmez de.</string>
+ <string name="show_all">Tümünü göster</string>
+ <string name="show_less">Daha az göster</string>
</resources>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 75604e4..f35477e 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -419,4 +419,6 @@
<string name="canvas">Canvas</string>
<string name="canvas_show">Show looping clips</string>
<string name="canvas_note">The short video some tracks come with. Off, none is downloaded either.</string>
+ <string name="show_all">Show all</string>
+ <string name="show_less">Show less</string>
</resources>