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.

Give the glass something to hold

Leloniod0d861095b3c
diff --git a/app/src/main/java/dev/lelonio/square/ui/components/Wordmark.kt b/app/src/main/java/dev/lelonio/square/ui/components/Wordmark.kt
index c39c0c6..5788b3a 100644
--- a/app/src/main/java/dev/lelonio/square/ui/components/Wordmark.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/components/Wordmark.kt
@@ -1,6 +1,9 @@
package dev.lelonio.square.ui.components
import androidx.compose.foundation.Canvas
+import androidx.compose.foundation.border
+import androidx.compose.foundation.layout.Box
+import androidx.compose.ui.draw.drawBehind
import androidx.compose.foundation.Image
import androidx.compose.material3.Icon
import androidx.compose.foundation.layout.Row
@@ -85,29 +88,124 @@ fun AppLockup(
modifier: Modifier = Modifier,
iconSize: Dp = 28.dp,
nameHeight: Dp = 14.dp,
+ /**
+ * What to put the mark on, when it should sit on glass.
+ *
+ * Null leaves it bare, which is what everywhere but the home header wants:
+ * a plate is a control, and a mark in the middle of a login page is not one.
+ */
+ plate: dev.lelonio.square.ui.glass.backdrop.Backdrop? = null,
) {
Row(modifier, verticalAlignment = Alignment.CenterVertically) {
- AppGlyph(iconSize)
+ if (plate == null) {
+ AppGlyph(iconSize)
+ } else {
+ AppPlate(iconSize, plate)
+ }
Spacer(Modifier.width(iconSize * 0.32f))
SquareWordmark(nameHeight)
}
}
+/**
+ * The mark on a round pane of the app's own glass.
+ *
+ * The same material and the same rim as the round buttons — see CircleAction —
+ * so it belongs to the same row of controls even though there is nothing to
+ * press. What it gives the mark is a place to stand.
+ *
+ * With something behind it to bend. Glass over the page's own flat colour has
+ * nothing to refract and comes out as a grey disc, so the pane is given a wash
+ * of the accent the app takes from the artwork that is playing: off-centre, so
+ * the film and the rim have a gradient to sit on, and alive, because that
+ * colour slides to a new one every time the music changes.
+ *
+ * Flat, deliberately. This sits in a header that moves with the scroll, and a
+ * pane that samples the screen re-photographs it every frame — for a
+ * reflection of a colour this already knows.
+ */
+@Composable
+fun AppPlate(
+ size: Dp,
+ backdrop: dev.lelonio.square.ui.glass.backdrop.Backdrop,
+ modifier: Modifier = Modifier,
+) {
+ val accent = androidx.compose.material3.MaterialTheme.colorScheme.primary
+ dev.lelonio.square.ui.glass.LiquidButton(
+ onClick = {},
+ backdrop = backdrop,
+ isInteractive = false,
+ flat = true,
+ modifier = modifier
+ .size(size)
+ // Brightest at the top left and gone by the bottom right, which is
+ // the one thing an even ring cannot do: a flat rim reads as a
+ // sticker, a graded one as an edge catching light.
+ .border(
+ 0.8.dp,
+ androidx.compose.ui.graphics.Brush.linearGradient(
+ 0f to Color.White.copy(alpha = 0.62f),
+ 0.5f to Color.White.copy(alpha = 0.20f),
+ 1f to Color.White.copy(alpha = 0.06f),
+ ),
+ androidx.compose.foundation.shape.CircleShape,
+ ),
+ contentHeight = size,
+ contentPadding = 0.dp,
+ ) {
+ Box(Modifier.size(size), contentAlignment = Alignment.Center) {
+ // Over the glass rather than under it.
+ //
+ // The material draws a film across whatever it is given, and a wash
+ // painted underneath came out through it as flat grey — the thing
+ // this exists to avoid. Above the film it is what the pane is
+ // holding: the accent the app takes from the artwork playing, which
+ // slides to a new colour every time the music changes.
+ androidx.compose.foundation.Canvas(Modifier.matchParentSize()) {
+ drawRect(
+ androidx.compose.ui.graphics.Brush.linearGradient(
+ 0f to accent.copy(alpha = 0.62f),
+ 0.5f to accent.copy(alpha = 0.30f),
+ 1f to accent.copy(alpha = 0.08f),
+ start = androidx.compose.ui.geometry.Offset.Zero,
+ end = androidx.compose.ui.geometry.Offset(size.toPx(), size.toPx()),
+ ),
+ )
+ // The light on it, which is what makes it read as curved rather
+ // than as a coloured circle.
+ drawCircle(
+ androidx.compose.ui.graphics.Brush.radialGradient(
+ listOf(Color.White.copy(alpha = 0.34f), Color.Transparent),
+ center = androidx.compose.ui.geometry.Offset(
+ this.size.width * 0.30f,
+ this.size.height * 0.20f,
+ ),
+ radius = this.size.width * 0.62f,
+ ),
+ )
+ }
+ AppGlyph(size * 0.58f)
+ }
+ }
+}
+
/**
* The app's mark with no plate under it.
*
* The launcher icon is a tile: artwork on a coloured square, because that is
* what a launcher draws. On a page of the app itself there is nothing for a
* tile to sit on — it reads as a sticker of the icon rather than as the app's
- * own mark — so the header takes the wave alone, in the page's ink.
+ * own mark — so what is used is the wave alone, in the page's ink.
*
- * The themed form is exactly that drawing without its plate, which is what it
- * exists for, so this is the same artwork rather than a second copy of it.
+ * Drawn from the same file the launcher art came from — see
+ * `app/icon-src/wave-square.svg` — rather than from the stroked approximation
+ * the themed launcher icon carries, which was a redrawing of it by hand and
+ * showed at this size.
*/
@Composable
fun AppGlyph(size: Dp, modifier: Modifier = Modifier, tint: Color = Ink) {
Icon(
- painter = painterResource(R.drawable.ic_launcher_monochrome),
+ painter = painterResource(R.drawable.ic_app_mark),
contentDescription = null,
tint = tint,
modifier = modifier.size(size),
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 75b8a21..304743a 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
@@ -15,6 +15,7 @@ import androidx.compose.runtime.Stable
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.ui.draw.clip
+import androidx.compose.ui.draw.drawBehind
import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
@@ -452,6 +453,22 @@ fun Modifier.liquidGlass(
return this
.clip(shape)
.background(surfaceTintColor.copy(alpha = config.surfaceOpacity.coerceIn(0f, 1f)))
+ // What this control adds to the shared film, which this path used
+ // to drop on the floor.
+ //
+ // Everything that reaches here is a flat pane — every chip in the
+ // app, since those are drawn without sampling the screen — and for
+ // all of them the tint was simply not run: the chosen chip was not
+ // being filled any harder than the rest, and only its label being
+ // brighter said which one it was. Between the film and the rim, so
+ // it sits inside the material rather than over its edge.
+ .then(
+ if (onDrawTint != null) {
+ Modifier.drawBehind { onDrawTint.invoke(this) }
+ } else {
+ Modifier
+ },
+ )
.border(EdgeHighlightWidth, flatRimColor.copy(alpha = flatRim), shape)
}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/GlassWash.kt b/app/src/main/java/dev/lelonio/square/ui/glass/GlassWash.kt
new file mode 100644
index 0000000..5f20932
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/GlassWash.kt
@@ -0,0 +1,32 @@
+package dev.lelonio.square.ui.glass
+
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.lerp
+import dev.lelonio.square.ui.theme.Ink
+
+/**
+ * What the glass in this app holds: the colour of what is playing.
+ *
+ * The accent comes from the artwork, which means it can be anything — a
+ * saturated pink one song and a muddy brown the next. On the app's own mark,
+ * one round pane on the page, that is the point. On a row of chips it is not:
+ * five saturated capsules read as five buttons demanding a tap, and the labels
+ * on them stop being the loudest thing in the row.
+ *
+ * So a chip wears the same colour pulled most of the way towards the page's
+ * ink and at a fraction of the alpha. What survives is the *direction* of the
+ * light and a hint of the hue, which is what makes the glass look like glass.
+ *
+ * @param selected the chosen chip, which carries a little more of it: it is
+ * already filled harder, and the wash should not undo that difference.
+ */
+@Composable
+fun chipWash(selected: Boolean): Color {
+ val accent = MaterialTheme.colorScheme.primary
+ // Most of the way to the ink: the hue is still there, the saturation
+ // mostly is not.
+ val quiet = lerp(accent, Ink, 0.55f)
+ return quiet.copy(alpha = if (selected) 0.32f else 0.20f)
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/glass/LiquidButton.kt b/app/src/main/java/dev/lelonio/square/ui/glass/LiquidButton.kt
index 1d80baa..752a2cc 100644
--- a/app/src/main/java/dev/lelonio/square/ui/glass/LiquidButton.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/glass/LiquidButton.kt
@@ -54,6 +54,19 @@ fun LiquidButton(
* read as five identical buttons.
*/
surfaceColor: Color = Color.Unspecified,
+ /**
+ * A colour for the glass to hold, over the film rather than under it.
+ *
+ * Glass over a flat page has nothing to refract and comes out grey. What
+ * this gives it is something to bend: a diagonal wash, strongest where the
+ * rim catches the light, with a sheen along the top edge. The alpha is the
+ * caller's — see GlassWash for what a chip should ask for and why it is
+ * less than what the app's own mark asks for.
+ *
+ * Drawn with the tint below, which is to say inside the material, so the
+ * label on top of it stays the colour it was set to.
+ */
+ wash: Color = Color.Unspecified,
// LOCAL CHANGE: upstream pins the height at 48dp and the horizontal padding
// at 16dp, which silently overrode any size the caller asked for — a 62dp
// round button came out 48 tall with its icon squeezed by the padding. Both
@@ -141,7 +154,7 @@ fun LiquidButton(
},
// The shared film is drawn first; these are only what this
// particular control adds to it.
- onDrawTint = if (tint.isSpecified || surfaceColor.isSpecified) {
+ onDrawTint = if (tint.isSpecified || surfaceColor.isSpecified || wash.isSpecified) {
{
if (tint.isSpecified) {
drawRect(tint, blendMode = BlendMode.Hue)
@@ -150,6 +163,28 @@ fun LiquidButton(
if (surfaceColor.isSpecified) {
drawRect(surfaceColor)
}
+ if (wash.isSpecified) {
+ drawRect(
+ androidx.compose.ui.graphics.Brush.linearGradient(
+ 0f to wash,
+ 0.55f to wash.copy(alpha = wash.alpha * 0.34f),
+ 1f to Color.Transparent,
+ start = androidx.compose.ui.geometry.Offset.Zero,
+ end = androidx.compose.ui.geometry.Offset(size.width, size.height),
+ ),
+ )
+ // The light along the top, which is what says the
+ // surface is curved rather than printed.
+ drawRect(
+ androidx.compose.ui.graphics.Brush.verticalGradient(
+ listOf(
+ Color.White.copy(alpha = 0.14f),
+ Color.Transparent,
+ ),
+ endY = size.height * 0.6f,
+ ),
+ )
+ }
}
} else {
null
diff --git a/app/src/main/java/dev/lelonio/square/ui/home/HomeScreen.kt b/app/src/main/java/dev/lelonio/square/ui/home/HomeScreen.kt
index 47c4bbc..60d6a3d 100644
--- a/app/src/main/java/dev/lelonio/square/ui/home/HomeScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/home/HomeScreen.kt
@@ -623,8 +623,12 @@ private fun Header(
// collapses rather than leaving, because a bar with nothing in
// it says nothing about where you are.
AppLockup(
- iconSize = 34.dp,
+ // Larger than the bare mark was: the glass around it is
+ // part of the shape now, and the drawing inside has to stay
+ // the size it was to read at a glance.
+ iconSize = 44.dp,
nameHeight = 22.dp,
+ plate = backdrop,
modifier = Modifier
.padding(top = 4.dp)
.graphicsLayer {
@@ -699,6 +703,7 @@ private fun FilterRow(selected: Feed, backdrop: Backdrop, onSelect: (Feed) -> Un
// A tinted fill would put the artwork's colour on a control
// whose whole job is to be legible over any artwork.
surfaceColor = if (isSelected) SelectedFilm else Color.Unspecified,
+ wash = dev.lelonio.square.ui.glass.chipWash(isSelected),
) {
Text(
stringResource(entry.label),
diff --git a/app/src/main/java/dev/lelonio/square/ui/library/LibraryScreen.kt b/app/src/main/java/dev/lelonio/square/ui/library/LibraryScreen.kt
index 427dfe9..2cdef54 100644
--- a/app/src/main/java/dev/lelonio/square/ui/library/LibraryScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/library/LibraryScreen.kt
@@ -483,6 +483,7 @@ private fun Header(
contentHeight = 36.dp,
contentPadding = 14.dp,
surfaceColor = if (selected) SelectedFilm else Color.Unspecified,
+ wash = dev.lelonio.square.ui.glass.chipWash(selected),
) {
Text(
stringResource(entry.label),
diff --git a/app/src/main/res/drawable/ic_app_mark.xml b/app/src/main/res/drawable/ic_app_mark.xml
new file mode 100644
index 0000000..280dbd9
--- /dev/null
+++ b/app/src/main/res/drawable/ic_app_mark.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ The mark itself, from app/icon-src/wave-square.svg.
+
+ The same path the launcher art was drawn from, rather than the stroked
+ approximation of it that used to stand in for it here: a square wave with the
+ weights and the corners the artwork has, at any size.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="256"
+ android:viewportHeight="256">
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M240,128v56a8,8,0,0,1,-8,8H128a8,8,0,0,1,-8,-8V80H32v48a8,8,0,0,1,-16,0V72a8,8,0,0,1,8,-8H128a8,8,0,0,1,8,8V176h88V128a8,8,0,0,1,16,0Z" />
+</vector>