Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.
Kotlin alternativeandroidandroid-applicationclientglassmorphisminnertubelibrespotliquid-glassspotifyspotify-connectspotifyapiyoutube-musicyoutube-playerytdlnis
Let the screen change its mind gently
Leloniod807235c2671
diff --git a/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt b/app/src/main/java/dev/lelonio/square/ui/SquareApp.ktindex 1f0fd67..e1585de 100644--- a/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt+++ b/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt@@ -2,6 +2,7 @@ package dev.lelonio.square.uiimport androidx.compose.animation.core.Animatableimport androidx.compose.animation.core.animateFloatAsState+import androidx.compose.ui.graphics.luminanceimport androidx.compose.animation.core.Springimport androidx.compose.animation.core.springimport androidx.compose.animation.core.tween@@ -343,6 +344,23 @@ fun SquareApp(}}val accent by rememberArtworkColor(playback.artworkUrl)++ // How bright the page behind the glass is, from the artwork rather than+ // from the screen.+ //+ // The library's own adaptive-luminance demo photographs its backdrop every+ // frame and reads the pixels back to average them, which on a bar that is+ // always on screen is a capture and a GPU-to-CPU copy for ever. The colours+ // of the cover playing are already extracted for the aura and the accent,+ // and they answer the same question: is what is behind this light or dark.+ val palette by dev.lelonio.square.ui.theme.rememberArtworkPalette(playback.artworkUrl)+ val backdropLuminance by animateFloatAsState(+ targetValue = remember(palette) {+ if (palette.isEmpty()) 0f else palette.map { it.luminance() }.average().toFloat()+ },+ animationSpec = tween(600),+ label = "backdropLuminance",+ )val recent by viewModel.recent.collectAsStateWithLifecycle()val search by viewModel.search.collectAsStateWithLifecycle()val searchHistory by viewModel.searchHistory.collectAsStateWithLifecycle()@@ -696,6 +714,9 @@ fun SquareApp(return}+ androidx.compose.runtime.CompositionLocalProvider(+ dev.lelonio.square.ui.glass.LocalBackdropLuminance provides backdropLuminance,+ ) {SquareTheme(seed = accent) {// Material's default content colour is black, and it used to arrive from// the Surface that wrapped this tree. That Surface is gone — it painteddiff --git a/app/src/main/java/dev/lelonio/square/ui/glass/GlassEffect.kt b/app/src/main/java/dev/lelonio/square/ui/glass/GlassEffect.ktindex 304743a..fc2d201 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@@ -276,6 +276,21 @@ fun glassContentColorFor(behind: Color, tint: Color, opacity: Float): Color {* 0.5 alpha) reads as near-invisible at typical density, but a wide bright rim* overshoots in the other direction, so this lands narrower and dimmer than that.*/+/**+ * How bright what is behind the glass has to be before the film darkens, and+ * where it has finished darkening. See the use of it in [liquidGlass].+ */+private const val BRIGHT_FROM = 0.42f+private const val BRIGHT_TO = 0.72f++/**+ * How bright the thing behind this app's glass is, 0 to 1.+ *+ * Provided once, near the top of the tree, from the palette of the artwork+ * playing. Anything drawn in glass can read it; nothing has to measure it.+ */+val LocalBackdropLuminance = androidx.compose.runtime.compositionLocalOf { 0f }+private val EdgeHighlightWidth = 0.8f.dpprivate const val EdgeHighlightAlpha = 0.55f@@ -418,12 +433,25 @@ fun Modifier.liquidGlass(// that blends into an OLED-black background. Honor an explicit user color,// otherwise use a proper adaptive glass gray rather than matching the theme// surface color 1:1 (which made the bar invisible over pure-black content).+ // The film follows what is actually behind the glass, not only the theme.+ //+ // A pane over a dark page wants a light film to read as glass at all; the+ // same film over a bright cover turns the whole control into a pale smear+ // with white text on it. What decides is the artwork playing, which the app+ // already reads a palette from — no per-frame readback of the screen, which+ // is how the library's own adaptive-luminance demo does it and why that+ // demo costs a capture and a pixel copy every frame.+ val backdropLuminance = LocalBackdropLuminance.currentval surfaceTintColor = if (config.surfaceTintColor.isSpecified) {config.surfaceTintColor} else if (MaterialTheme.colorScheme.surface.luminance() > 0.5f) {Color(0xFFFAFAFA)} else {- Color(0xFF4A4A4E)+ // Between the two across the middle of the range rather than at a line,+ // so a cover that is merely light does not flip the chrome.+ val bright = ((backdropLuminance - BRIGHT_FROM) / (BRIGHT_TO - BRIGHT_FROM))+ .coerceIn(0f, 1f)+ lerp(Color(0xFF4A4A4E), Color(0xFF23232A), bright)}// Translucent style short-circuits everything below: no backdrop is sampled anddiff --git a/app/src/main/java/dev/lelonio/square/ui/player/CoverAura.kt b/app/src/main/java/dev/lelonio/square/ui/player/CoverAura.ktindex 8e089d4..3daf12d 100644--- a/app/src/main/java/dev/lelonio/square/ui/player/CoverAura.kt+++ b/app/src/main/java/dev/lelonio/square/ui/player/CoverAura.kt@@ -52,6 +52,21 @@ fun CoverAura() {if (colors.isEmpty()) return+ // The colours cross over rather than cut.+ //+ // A track change replaces the whole palette at once, and the light behind+ // the player jumped from one record's colours to the next's in a single+ // frame — the one moment on this screen where nothing was moving smoothly.+ // Each lamp is animated to its new colour on its own, so the whole thing+ // turns rather than switches.+ val blended = colors.mapIndexed { index, target ->+ androidx.compose.animation.animateColorAsState(+ targetValue = target,+ animationSpec = tween(700),+ label = "aura$index",+ ).value+ }+val transition = rememberInfiniteTransition(label = "aura")// One phase read at several speeds below, rather than several animations:// they would drift apart on a dropped frame and this cannot.@@ -86,7 +101,7 @@ fun CoverAura(// The bed: wide, soft, and the only part meant to be looked at// directly. Everything after this is for the glass.repeat(3) { index ->- val color = colors[index % colors.size]+ val color = blended[index % blended.size]val angle = turn * DRIFT[index] + index * (TAU / 3f)val centre = Offset(x = size.width * (0.5f + 0.34f * cos(angle)),@@ -107,7 +122,7 @@ fun CoverAura(// The beams. Each is a band with one soft side and one abrupt one, and// the abrupt side is the whole point: that is the edge the panes bend.repeat(2) { index ->- val color = colors[(index + 1) % colors.size]+ val color = blended[(index + 1) % blended.size]val angle = turn * BEAM[index] + index * 1.7frotate(degrees = 20f * sin(angle) + index * 40f - 20f) {beam(@@ -124,7 +139,7 @@ fun CoverAura(// and few — under a lens each one throws a highlight far larger than// itself, and a dozen would be glitter.repeat(3) { index ->- val color = colors[(index + 2) % colors.size]+ val color = blended[(index + 2) % blended.size]val angle = turn * CAUSTIC[index] + index * 2.1fval centre = Offset(x = size.width * (0.5f + 0.40f * sin(angle)),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.ktindex 73d3781..ddb0878 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@@ -1,11 +1,15 @@package dev.lelonio.square.ui.playerimport androidx.compose.animation.AnimatedContent+import androidx.compose.animation.SizeTransform+import androidx.compose.animation.togetherWithimport androidx.compose.animation.AnimatedVisibilityimport androidx.compose.animation.scaleInimport androidx.compose.animation.scaleOutimport androidx.compose.animation.Crossfade+import androidx.compose.animation.expandVerticallyimport androidx.compose.animation.fadeIn+import androidx.compose.animation.shrinkVerticallyimport androidx.compose.animation.fadeOutimport androidx.compose.animation.slideInVerticallyimport androidx.compose.animation.slideOutVertically@@ -138,6 +142,12 @@ private const val PAUSED_DIM = 0.55f* back here as a full-bleed backdrop.*//** What occupies the middle of the player. */+/** How long each half of a change between the cover and a panel takes. */+private const val STAGE_FADE_MS = 180++/** And the whole of a change between the cover and a Canvas; see the use of it. */+private const val CLIP_FADE_MS = 460+private enum class Stage {COVER, LYRICS, EFFECTS, INFO, QUEUE, DEVICES, ADD_TO_PLAYLIST, CANVAS, VIDEO}@@ -643,29 +653,32 @@ fun PlayerScreen(else -> Stage.CANVAS}},- animationSpec = tween(320),+ // Spelled out rather than left to Crossfade.+ //+ // Crossfade dropped the cover the instant a panel+ // opened — the log had it leaving the composition in+ // the same millisecond the lyrics arrived, while the+ // panels dissolved into each other perfectly. Said+ // this way, both halves of the change are named and+ // both are given the same time.+ // Between one panel and another, where no cover+ // is involved, this is the whole animation. Going to+ // or from the cover it is held at nothing until its+ // turn; see panelAlpha.+ transitionSpec = {+ fadeIn(tween(STAGE_FADE_MS)) togetherWith+ fadeOut(tween(STAGE_FADE_MS)) using null+ },label = "stage",- modifier = Modifier.weight(1f),+ modifier = Modifier+ .fillMaxSize()+ .graphicsLayer { alpha = panelAlpha },) { stage ->when (stage) {- Stage.COVER -> Box(- Modifier.fillMaxSize(),- contentAlignment = Alignment.Center,- ) {- Cover(- state,- panel,- onNext,- onPrevious,- sharedScope,- animatedScope,- )- }+ // Empty: the cover above this AnimatedContent+ // is what fills the slot when no panel is open.+ Stage.COVER -> Box(Modifier.fillMaxSize())- // The picture in the cover's place rather than- // behind the glass like a Canvas: this one is- // the thing being watched, so it gets the slot- // and keeps its own shape inside it.Stage.VIDEO -> Box(Modifier.fillMaxSize(),contentAlignment = Alignment.Center,@@ -779,13 +792,32 @@ fun PlayerScreen(// the title because that is where the official client// puts it: it is a choice about this song, not about// the app.- if (videoFileId != null) {+ // Faded and grown in, not dropped in.+ //+ // Whether a track has a video is answered a moment+ // after it starts, so this button arrives while the+ // listener is already looking at the screen. Appearing+ // in one frame reads as a glitch; arriving reads as an+ // answer.+ androidx.compose.animation.AnimatedVisibility(+ visible = videoFileId != null,+ enter = fadeIn(tween(260)) + scaleIn(tween(260), initialScale = 0.9f) ++ expandVertically(tween(260)),+ exit = fadeOut(tween(180)) + scaleOut(tween(180), targetScale = 0.92f) ++ shrinkVertically(tween(180)),+ modifier = Modifier.align(Alignment.CenterHorizontally),+ ) {GlassSurface(backdrop = glassBackdrop,surfaceColor = GlassFilm,shape = RoundedCornerShape(50),+ // The gap to the title lives here rather than+ // in a spacer beside it: what a visibility+ // block holds is stacked in a box, so a spacer+ // next to the button sat *on* it and the button+ // ended up against the title.modifier = Modifier- .align(Alignment.CenterHorizontally)+ .padding(bottom = 14.dp).pressable(onClick = onToggleVideo),) {Row(