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.

Open the player with a transform instead of a resize

Lelonio00f22e2023d4
diff --git a/.claude/settings.local.json b/.claude/settings.local.json
index 2f46be5..267451c 100644
--- a/.claude/settings.local.json
+++ b/.claude/settings.local.json
@@ -102,7 +102,8 @@
"Bash(xargs -0 sed -i '' -e s/Magnifyingglass/MagnifyingGlass/g -e s/Musicnotes/MusicNotes/g -e s/Skipback/SkipBack/g -e s/Skipforward/SkipForward/g -e s/Arrowclockwise/ArrowClockwise/g -e s/Arrowleft/ArrowLeft/g -e s/Arrowsdownup/ArrowsDownUp/g -e s/Caretdown/CaretDown/g -e s/Devicemobile/DeviceMobile/g -e s/Dotsthree/DotsThree/g -e s/Listbullets/ListBullets/g -e s/Slidershorizontal/SlidersHorizontal/g -e s/Speakerhifi/SpeakerHifi/g -e s/Squaresfour/SquaresFour/g -e s/Textalignleft/TextAlignLeft/g -e s/Vinylrecord/VinylRecord/g -e s/RepeatOne/RepeatOnce/g)",
"Bash(./gradlew :app:assembleDev -q)",
"Bash(git commit -q -m 'Swap every icon to Phosphor *)",
- "Bash(git commit -q -m 'Close the player by gesture, not by dragging it around *)"
+ "Bash(git commit -q -m 'Close the player by gesture, not by dragging it around *)",
+ "Bash(git commit -q -m 'Open the player with a transform instead of a resize *)"
]
}
}
diff --git a/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin b/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin
index a11ba5f..d3a0143 100644
--- a/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin
+++ b/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin
@@ -2,27 +2,27 @@ C/C++ Structured Logl
j
h/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/additional_project_files.txtC
A
-?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint  �����3  ����3i
+?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint  �����3  ����3i
g
-e/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/android_gradle_build.json  �����3� ����3n
+e/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/android_gradle_build.json  �����3� ����3n
l
-j/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/android_gradle_build_mini.json  �����3� �����3[
+j/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/android_gradle_build_mini.json  �����3� �����3[
Y
-W/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build.ninja  �����3�� ����3_
+W/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build.ninja  �����3�� ����3_
]
-[/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build.ninja.txt  �����3d
+[/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build.ninja.txt  �����3d
b
-`/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build_file_index.txt  �����3 @ ����3e
+`/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build_file_index.txt  �����3 @ ����3e
c
-a/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/compile_commands.json  �����3�� ����3i
+a/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/compile_commands.json  �����3�� ����3i
g
-e/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/compile_commands.json.bin  �����3 �" ����3o
+e/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/compile_commands.json.bin  �����3 �" ����3o
m
-k/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/metadata_generation_command.txt  �����3
+k/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/metadata_generation_command.txt  �����3
� ����3b
`
-^/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/prefab_config.json  �����3  ( ����3g
+^/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/prefab_config.json  �����3  ( ����3g
e
-c/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/symbol_folder_index.txt  �����3  b ����3D
+c/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/symbol_folder_index.txt  �����3  b ����3D
B
-@/Users/emanuele/Progetto Spotify/app/src/main/cpp/CMakeLists.txt  �����3 � �Ȅ��3
\ No newline at end of file
+@/Users/emanuele/Progetto Spotify/app/src/main/cpp/CMakeLists.txt  �����3 � �Ȅ��3
\ No newline at end of file
diff --git a/app/src/main/java/dev/emanuele/spot/ui/player/CoverGestures.kt b/app/src/main/java/dev/emanuele/spot/ui/player/CoverGestures.kt
index 5dd66b6..d120ce8 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/player/CoverGestures.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/player/CoverGestures.kt
@@ -6,7 +6,11 @@ import androidx.compose.animation.core.tween
import androidx.compose.foundation.gestures.detectHorizontalDragGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberUpdatedState
+import androidx.compose.runtime.snapshotFlow
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.graphicsLayer
@@ -43,6 +47,13 @@ fun CoverGestures(
* the swipe refers to is the clip behind this box rather than the box.
*/
followFinger: Boolean = true,
+ /**
+ * How far the gesture has travelled, in pixels, for whoever is drawing the
+ * feedback. Reported when the swiped thing is not inside this box — over a
+ * Canvas the clip is drawn behind the whole screen, so it is the only thing
+ * that can move, and it is not ours to place.
+ */
+ onDrag: (Float) -> Unit = {},
content: @Composable () -> Unit,
) {
val offsetX = remember { Animatable(0f) }
@@ -53,6 +64,11 @@ fun CoverGestures(
val screenWidth = with(density) { LocalConfiguration.current.screenWidthDp.dp.toPx() }
val threshold = screenWidth * 0.22f
+ val report by rememberUpdatedState(onDrag)
+ LaunchedEffect(Unit) {
+ snapshotFlow { offsetX.value }.collect { report(it) }
+ }
+
Box(
modifier
.graphicsLayer {
diff --git a/app/src/main/java/dev/emanuele/spot/ui/player/NowPlayingSheet.kt b/app/src/main/java/dev/emanuele/spot/ui/player/NowPlayingSheet.kt
index cc25e90..1f7bfe8 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/player/NowPlayingSheet.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/player/NowPlayingSheet.kt
@@ -39,12 +39,21 @@ import kotlin.math.abs
* screens, both on stage at once, and no amount of shared-element work hides
* that the bar and the player are two different things pretending to be one.
*
- * Here they *are* one. A single container sits at the bottom of the window and
- * its height runs from the bar's to the whole window's; the player is inside it
- * the entire time, laid out at full height and revealed as the container grows,
- * and the bar's row fades out over the first quarter of the travel. Nothing is
- * re-measured while it moves — the player keeps its final layout throughout —
- * so the motion is a single edge sliding up, not two screens dissolving.
+ * They still are, in the sense that matters: one `progress` value owns both, so
+ * the bar and the player are two views of a single state rather than two screens
+ * taking turns.
+ *
+ * How that value is spent went through a growing container — the bar's height
+ * stretched up to the window's, with the player already laid out full size
+ * inside it. It looked right and it was never quite smooth: resizing that
+ * container re-ran a layout pass over a screen holding a video surface and
+ * several pieces of live glass, sixty times a second, and deferring every state
+ * read only moved the cost around.
+ *
+ * So the travel is now a transform and nothing else. The player is full size
+ * from the first frame, rises a little way into place and fades in as the bar
+ * fades out under it. One layer, scaled and faded on the render thread, with no
+ * measure or layout anywhere in the frame.
*
* The same value is what a drag writes to, which is why dragging down works at
* any point and can be released anywhere: expansion is a position, not an event.
@@ -121,132 +130,79 @@ fun NowPlayingSheet(
}
}
- val marginPx = with(density) { SIDE_MARGIN.roundToPx() }
- val insetPx = with(density) { bottomInset.roundToPx() }
- val collapsedPx = with(density) { collapsedHeight.roundToPx() }
- val fullPx = with(density) { fullHeight.roundToPx() }
-
- Box(
- Modifier
- .align(Alignment.BottomCenter)
- .fillMaxWidth()
- // Size, margins and inset in one measure pass, all read here
- // rather than in composition.
- .layout { measurable, constraints ->
- val f = progress.value.coerceIn(0f, 1f)
- val margin = ((1f - f) * marginPx).toInt()
- val inset = ((1f - f) * insetPx).toInt()
- val height = collapsedPx + ((fullPx - collapsedPx) * f).toInt()
-
- val width = (constraints.maxWidth - margin * 2).coerceAtLeast(0)
- val placeable = measurable.measure(
- constraints.copy(
- minWidth = width,
- maxWidth = width,
- minHeight = height,
- maxHeight = height,
- ),
- )
- layout(constraints.maxWidth, height + inset) {
- placeable.place(margin, 0)
- }
- }
- .graphicsLayer {
- val f = progress.value.coerceIn(0f, 1f)
- shape = RoundedCornerShape(SHEET_CORNER * (1f - f))
- clip = true
- }
- .draggable(
- state = draggable,
- orientation = Orientation.Vertical,
- onDragStopped = { velocity ->
- // Velocity decides when the gesture was a flick;
- // otherwise the halfway point does. Without the
- // velocity test a fast short flick would snap back,
- // which reads as the gesture having been ignored.
- val target = when {
- abs(velocity) > FLING_VELOCITY -> if (velocity < 0) 1f else 0f
- progress.value > 0.5f -> 1f
- else -> 0f
- }
- // Handed to the spring rather than dropped. Releasing
- // mid-drag otherwise restarted the motion from a dead
- // stop, which is the one thing a tap-to-open never does
- // and is why closing felt unlike opening reversed.
- settle(target, initialVelocity = -velocity / travelPx)
+ // The player, full size from the first frame to the last. Nothing about
+ // the travel touches measure or layout any more: the growing container
+ // that used to drive it re-ran a layout pass on the whole player every
+ // frame, and no amount of deferring state reads makes that free on a
+ // screen with a video surface and a stack of glass in it. What is left
+ // is one layer being scaled and faded, which the render thread does
+ // without waking the UI thread at all.
+ if (expandedVisible) {
+ Box(
+ Modifier
+ .fillMaxSize()
+ .graphicsLayer {
+ val f = progress.value.coerceIn(0f, 1f)
+ alpha = f
+ // Rises into place from just below, slightly smaller.
+ // Small numbers on purpose — this is the player arriving
+ // where it already is, not flying in from off-screen.
+ val scale = ENTER_SCALE + (1f - ENTER_SCALE) * f
+ scaleX = scale
+ scaleY = scale
+ translationY = (1f - f) * size.height * ENTER_TRAVEL
+ transformOrigin = TransformOrigin(0.5f, 1f)
+ // Rounded while it is on its way in and square once it
+ // has arrived, so it reads as a sheet rather than as a
+ // screen appearing.
+ shape = RoundedCornerShape(SHEET_CORNER * (1f - f))
+ clip = true
+ // Modulated rather than composited: the default draws
+ // the whole subtree into an offscreen buffer the size of
+ // the window before applying alpha, every frame.
+ compositingStrategy = CompositingStrategy.ModulateAlpha
},
- ),
- ) {
- if (expandedVisible) {
- Box(
- Modifier
- .align(Alignment.BottomCenter)
- .height(fullHeight)
- .fillMaxWidth()
- // Tracks the travel one to one, so what is behind the
- // player — the page it was opened from — is visible
- // through it while it is being dragged away. It used to
- // reach full opacity in the first quarter, which made
- // the content slide down over a background that never
- // moved and never let anything through.
- .graphicsLayer { alpha = progress.value.coerceIn(0f, 1f) },
+ ) {
+ background()
+ androidx.compose.runtime.CompositionLocalProvider(
+ LocalGlassEnabled provides settled,
) {
- background()
+ expandedContent()
}
}
+ }
- // Laid out at its final size from the start and simply uncovered.
- // Re-measuring a screen this complex on every frame of the travel is
- // what would make it stutter.
- if (expandedVisible) {
- Box(
- Modifier
- .align(Alignment.BottomCenter)
- .height(fullHeight)
- .fillMaxWidth()
- .graphicsLayer {
- val f = progress.value.coerceIn(0f, 1f)
- alpha = expandedAlpha(f)
- // Contracts towards the bottom edge as it closes.
- //
- // Without this the player was a full-size screen
- // being slid down behind a shrinking window: every
- // element kept its size right up to the moment it
- // was gone, which reads as a screen leaving rather
- // than as a panel collapsing into the bar. The
- // origin is the bottom because that is where the bar
- // it is becoming actually is.
- val scale = COLLAPSE_SCALE + (1f - COLLAPSE_SCALE) * f
- scaleX = scale
- scaleY = scale
- transformOrigin = TransformOrigin(0.5f, 1f)
- // Modulated rather than composited: the default
- // draws the whole subtree into an offscreen buffer
- // the size of the window before applying alpha,
- // every frame. Modulating is per-draw-call and looks
- // identical here because nothing in the player
- // overlaps itself.
- compositingStrategy = CompositingStrategy.ModulateAlpha
+ // The bar stays where it is and fades under the arriving player. It used
+ // to be the same surface, stretched — which is the effect this is
+ // giving up, and with it the stutter that came from stretching it.
+ if (collapsedVisible) {
+ Box(
+ Modifier
+ .align(Alignment.BottomCenter)
+ .padding(horizontal = SIDE_MARGIN)
+ .padding(bottom = bottomInset)
+ .height(collapsedHeight)
+ .fillMaxWidth()
+ .graphicsLayer { alpha = collapsedAlpha(progress.value) }
+ .draggable(
+ state = draggable,
+ orientation = Orientation.Vertical,
+ onDragStopped = { velocity ->
+ // Velocity decides when the gesture was a flick;
+ // otherwise the halfway point does. Without the
+ // velocity test a fast short flick would snap back,
+ // which reads as the gesture having been ignored.
+ val target = when {
+ abs(velocity) > FLING_VELOCITY -> if (velocity < 0) 1f else 0f
+ progress.value > 0.5f -> 1f
+ else -> 0f
+ }
+ // Handed to the spring rather than dropped.
+ settle(target, initialVelocity = -velocity / travelPx)
},
- ) {
- androidx.compose.runtime.CompositionLocalProvider(
- LocalGlassEnabled provides settled,
- ) {
- expandedContent()
- }
- }
- }
-
- if (collapsedVisible) {
- Box(
- Modifier
- .align(Alignment.TopCenter)
- .height(collapsedHeight)
- .fillMaxWidth()
- .graphicsLayer { alpha = collapsedAlpha(progress.value) },
- ) {
- collapsedContent()
- }
+ ),
+ ) {
+ collapsedContent()
}
}
}
@@ -265,19 +221,14 @@ fun NowPlayingSheet(
private fun collapsedAlpha(fraction: Float): Float =
(1f - fraction / HANDOVER).coerceIn(0f, 1f)
-private fun expandedAlpha(fraction: Float): Float =
- ((fraction - HANDOVER) / (1f - HANDOVER) * 2f).coerceIn(0f, 1f)
-
/** Where the bar has finished leaving and the player begins to arrive. */
private const val HANDOVER = 0.3f
-/**
- * How far the player is shrunk when fully collapsed.
- *
- * Enough to read as a contraction; much below this and the text inside starts
- * to look like it is being squashed rather than moving away.
- */
-private const val COLLAPSE_SCALE = 0.86f
+/** How small the player starts, growing to its own size as it arrives. */
+private const val ENTER_SCALE = 0.92f
+
+/** How far below its place it starts, as a fraction of its height. */
+private const val ENTER_TRAVEL = 0.06f
/** Margin the collapsed bar keeps from the edges of the window. */
private val SIDE_MARGIN = 16.dp
diff --git a/app/src/main/java/dev/emanuele/spot/ui/player/PlayerScreen.kt b/app/src/main/java/dev/emanuele/spot/ui/player/PlayerScreen.kt
index 4b66168..110848b 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/player/PlayerScreen.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/player/PlayerScreen.kt
@@ -41,6 +41,7 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.State
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
@@ -81,6 +82,15 @@ import com.adamglin.phosphoricons.regular.Queue
import com.adamglin.phosphoricons.regular.Repeat
import com.adamglin.phosphoricons.regular.RepeatOnce
import com.adamglin.phosphoricons.regular.Shuffle
+import kotlin.math.abs
+
+/**
+ * How much of the swipe the clip takes, when it stands in for the cover.
+ *
+ * Damped: the Canvas is the backdrop every piece of glass above it samples, and
+ * moving it one to one drags the whole screen's refraction along with it.
+ */
+private const val CANVAS_SWIPE_FOLLOW = 0.35f
/**
* The player, as a liquid-glass prototype.
@@ -144,6 +154,12 @@ fun PlayerScreen(
) {
var panel by remember { mutableStateOf(PlayerPanel.NONE) }
+ // How far the track-change swipe has been dragged, when the clip stands in
+ // for the cover. Written from the gesture and read only inside a
+ // graphicsLayer, so following the finger costs a redraw of one layer rather
+ // than a recomposition of the player.
+ val canvasShift = remember { mutableFloatStateOf(0f) }
+
// The Canvas gets a layer of its own so the glass over it refracts the clip
// rather than the app's blurred artwork. It is combined with the app
// backdrop rather than replacing it, because with no Canvas this layer is
@@ -170,6 +186,21 @@ fun PlayerScreen(
Modifier
.fillMaxSize()
.then(if (canvasBlur > 0.dp) Modifier.blur(canvasBlur) else Modifier)
+ // The clip follows a track-change swipe, since with a Canvas
+ // playing it is the only thing on screen the gesture could be
+ // about. Damped, because the clip is the backdrop of everything
+ // above it and moving it one to one drags the whole screen's
+ // refraction with it.
+ .graphicsLayer {
+ val shift = canvasShift.floatValue
+ if (shift == 0f) return@graphicsLayer
+ translationX = shift * CANVAS_SWIPE_FOLLOW
+ val travel = (abs(shift) / size.width).coerceIn(0f, 1f)
+ val shrink = 1f - travel * 0.12f
+ scaleX = shrink
+ scaleY = shrink
+ alpha = 1f - travel * 0.5f
+ }
.layerBackdrop(canvasBackdrop),
) {
Crossfade(
@@ -229,6 +260,7 @@ fun PlayerScreen(
) {
TopBar(
backdrop = glassBackdrop,
+ panel = panel,
onCollapse = onCollapse,
onOpenDevices = onOpenDevices,
)
@@ -343,6 +375,7 @@ fun PlayerScreen(
canGoNext = state.hasNext,
canGoPrevious = state.hasPrevious,
followFinger = false,
+ onDrag = { canvasShift.floatValue = it },
modifier = Modifier.fillMaxSize(),
) {
Box(Modifier.fillMaxSize())
@@ -496,6 +529,7 @@ fun PlayerScreen(
@Composable
private fun TopBar(
backdrop: Backdrop,
+ panel: PlayerPanel,
onCollapse: () -> Unit,
onOpenDevices: () -> Unit,
) {
@@ -508,12 +542,26 @@ private fun TopBar(
GlassButton(backdrop, onClick = onCollapse) {
Icon(PhosphorIcons.Regular.CaretDown, contentDescription = "Chiudi")
}
- Text(
- "In riproduzione",
- style = MaterialTheme.typography.titleMedium,
- textAlign = TextAlign.Center,
+ // Names whatever the middle of the screen is currently showing, so the
+ // switch below has a label without carrying one.
+ Crossfade(
+ targetState = when (panel) {
+ PlayerPanel.LYRICS -> "Testo"
+ PlayerPanel.EFFECTS -> "Effetti"
+ PlayerPanel.QUEUE -> "In coda"
+ PlayerPanel.NONE -> "In riproduzione"
+ },
+ animationSpec = tween(220),
+ label = "topBarTitle",
modifier = Modifier.weight(1f),
- )
+ ) { title ->
+ Text(
+ title,
+ style = MaterialTheme.typography.titleMedium,
+ textAlign = TextAlign.Center,
+ modifier = Modifier.fillMaxWidth(),
+ )
+ }
// Connect gets the permanent slot rather than hiding behind "more":
// moving playback to another speaker is the thing you reach for while
// the player is open, and the queue already has its own tab below.
@@ -849,3 +897,4 @@ private fun LyricsStage(
}
}
}
+