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.

Make the player one surface with the now-playing bar

Lelonio09a75a7cb4e2
diff --git a/.claude/settings.local.json b/.claude/settings.local.json
index 1c5e960..d112ae0 100644
--- a/.claude/settings.local.json
+++ b/.claude/settings.local.json
@@ -74,7 +74,11 @@
"Bash(ffmpeg -hide_banner -loglevel error -i f_%03d.jpg -vf \"select='between\\(n,44,67\\)',tile=6x4\" -frames:v 1 grid2.jpg)",
"Bash(unzip -o -q classes.jar 'androidx/compose/animation/SharedTransitionScope$ResizeMode$Companion.class')",
"Bash(javap -classpath . 'androidx.compose.animation.SharedTransitionScope$ResizeMode$Companion')",
- "Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Morph the now-playing bar into the player'\\\\''s title capsule *)"
+ "Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Morph the now-playing bar into the player'\\\\''s title capsule *)",
+ "Bash(git revert *)",
+ "Bash(git stash *)",
+ "Bash(git reset *)",
+ "Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Make the player one surface with the now-playing bar *)"
]
}
}
diff --git a/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin b/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin
index 3a5a920..5d80051 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/SpotApp.kt b/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt
index 0880ae9..fbd2dbb 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt
@@ -1,13 +1,8 @@
package dev.emanuele.spot.ui
-import androidx.compose.animation.AnimatedVisibility
-import androidx.compose.animation.ExperimentalSharedTransitionApi
-import androidx.compose.animation.SharedTransitionLayout
-import androidx.compose.animation.core.tween
-import androidx.compose.animation.fadeIn
-import androidx.compose.animation.fadeOut
-import androidx.compose.animation.scaleIn
-import androidx.compose.animation.scaleOut
+import androidx.compose.animation.core.Animatable
+import androidx.compose.animation.core.Spring
+import androidx.compose.animation.core.spring
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
@@ -44,6 +39,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
@@ -52,7 +48,7 @@ import androidx.compose.ui.draw.blur
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.graphics.TransformOrigin
+import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight
@@ -85,11 +81,10 @@ import dev.emanuele.spot.ui.glass.LiquidButton
import dev.emanuele.spot.ui.home.HomeScreen
import dev.emanuele.spot.ui.library.LibraryScreen
import dev.emanuele.spot.ui.library.PlaylistScreen
-import dev.emanuele.spot.ui.player.EXPAND_MS
-import dev.emanuele.spot.ui.player.MiniPlayer
import dev.emanuele.spot.ui.player.GlassFilm
-import dev.emanuele.spot.ui.player.EXPAND_MS
+import dev.emanuele.spot.ui.player.MiniPlayer
import dev.emanuele.spot.ui.player.MiniPlayerHeight
+import dev.emanuele.spot.ui.player.NowPlayingSheet
import dev.emanuele.spot.ui.player.PlayerScreen
import dev.emanuele.spot.ui.player.progressOf
import dev.emanuele.spot.ui.player.rememberPlaybackState
@@ -99,18 +94,23 @@ import dev.emanuele.spot.ui.search.SearchScreen
import dev.emanuele.spot.ui.theme.Ink
import dev.emanuele.spot.ui.theme.SpotTheme
import dev.emanuele.spot.ui.theme.rememberArtworkColor
+import kotlinx.coroutines.launch
object Routes {
const val HOME = "home"
const val SEARCH = "search"
const val LIBRARY = "library"
const val PLAYLIST = "playlist"
- const val PLAYER = "player"
}
+/** How the player settles when it is not being dragged. */
+private val expandSpec = spring<Float>(
+ dampingRatio = 0.86f,
+ stiffness = Spring.StiffnessMediumLow,
+)
+
private val BottomBarHeight = 62.dp
-@OptIn(ExperimentalSharedTransitionApi::class)
@UnstableApi
@Composable
fun SpotApp(
@@ -154,6 +154,11 @@ fun SpotApp(
val artBackdrop = rememberLayerBackdrop()
val pageBackdrop = rememberLayerBackdrop()
+ // 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(0f) }
+ val scope = rememberCoroutineScope()
+
// Recorded here rather than at the tap: this fires for auto-advance and for
// controls outside the app too, so the history matches what was actually
// heard instead of only what was tapped.
@@ -201,15 +206,10 @@ fun SpotApp(
// here, or every Text that does not set one explicitly stays black on
// the darkened artwork.
CompositionLocalProvider(LocalContentColor provides Ink) {
- // Wraps everything that takes part in the expand animation: the
- // mini player lives outside the NavHost, and a shared element only
- // works between two composables under the same layout.
- SharedTransitionLayout {
Box(Modifier.fillMaxSize()) {
val navController = rememberNavController()
val currentEntry by navController.currentBackStackEntryAsState()
val route = currentEntry?.destination?.route
- val onPlayer = route == Routes.PLAYER
val statusBar = WindowInsets.statusBars.asPaddingValues().calculateTopPadding()
val navBar = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()
@@ -332,50 +332,52 @@ fun SpotApp(
}
}
- composable(
- Routes.PLAYER,
- // A plain fade, deliberately. The motion belongs to
- // the artwork: it is a shared element, so it travels
- // from the mini player's 42dp thumbnail to the full
- // cover and back. Sliding the screen as well would
- // be two animations describing the same thing.
- enterTransition = {
- fadeIn(tween(220, delayMillis = 60)) +
- scaleIn(
- tween(EXPAND_MS),
- initialScale = 0.94f,
- transformOrigin = TransformOrigin(0.5f, 1f),
- )
- },
- exitTransition = {
- fadeOut(tween(160)) +
- scaleOut(
- tween(EXPAND_MS),
- targetScale = 0.94f,
- transformOrigin = TransformOrigin(0.5f, 1f),
- )
- },
- popEnterTransition = {
- fadeIn(tween(220, delayMillis = 60)) +
- scaleIn(
- tween(EXPAND_MS),
- initialScale = 0.94f,
- transformOrigin = TransformOrigin(0.5f, 1f),
- )
- },
- popExitTransition = {
- fadeOut(tween(160)) +
- scaleOut(
- tween(EXPAND_MS),
- targetScale = 0.94f,
- transformOrigin = TransformOrigin(0.5f, 1f),
- )
- },
- ) {
+ }
+ }
+
+ // Outside the recorded layer, and that is structural rather than
+ // stylistic: these refract `pageBackdrop`, and a pane drawn
+ // inside the layer it samples recurses on the render thread
+ // until the process dies.
+ Box(
+ Modifier
+ .align(Alignment.BottomCenter)
+ .fillMaxWidth()
+ // Hidden as the player takes over, and out of the way
+ // before it covers it: a tab bar under a full-screen
+ // player still swallows the taps meant for the
+ // transport.
+ .graphicsLayer { alpha = (1f - expand.value * 3f).coerceIn(0f, 1f) },
+ ) {
+ BottomBar(
+ route = route,
+ bottomInset = navBar,
+ backdrop = pageBackdrop,
+ onSelect = navController::switchTab,
+ )
+ }
+
+ if (playback.hasItem) {
+ NowPlayingSheet(
+ progress = expand,
+ bottomInset = navBar + BottomBarHeight,
+ collapsedContent = {
+ MiniPlayer(
+ state = playback,
+ progress = {
+ progressOf(positionMs.value, playback.durationMs)
+ },
+ backdrop = pageBackdrop,
+ onExpand = { scope.launch { expand.animateTo(1f, expandSpec) } },
+ onTogglePlay = { player?.togglePlay() },
+ onNext = { player?.seekToNextMediaItem() },
+ )
+ },
+ expandedContent = {
PlayerScreen(
state = playback,
positionMs = positionMs,
- onCollapse = { navController.popBackStack() },
+ onCollapse = { scope.launch { expand.animateTo(0f, expandSpec) } },
onTogglePlay = { player?.togglePlay() },
onNext = { player?.seekToNextMediaItem() },
onPrevious = { player?.seekToPreviousMediaItem() },
@@ -418,60 +420,11 @@ fun SpotApp(
onDeletePreset = viewModel::deleteEffectPreset,
backdrop = artBackdrop,
canvas = canvas,
- sharedScope = this@SharedTransitionLayout,
- animatedScope = this@composable,
)
- }
- }
- }
-
- // Outside the recorded layer, and that is structural rather than
- // stylistic: these refract `pageBackdrop`, and a pane drawn
- // inside the layer it samples recurses on the render thread
- // until the process dies.
- //
- // Both survive navigation, and both step aside on the full
- // player, which already carries the same controls.
- Column(
- Modifier
- .align(Alignment.BottomCenter)
- .fillMaxWidth(),
- ) {
- // An AnimatedVisibility rather than an `if`, because the
- // shared element needs a scope to animate within: this is
- // the half of the transition that shrinks back into the bar.
- AnimatedVisibility(
- visible = !onPlayer && playback.hasItem,
- // Short, because the bar does not really disappear: its
- // bounds morph into the player's title capsule. A long
- // fade here left a ghost of the bar sitting over the
- // screen it had just become.
- enter = fadeIn(tween(200, delayMillis = 120)),
- exit = fadeOut(tween(120)),
- ) {
- MiniPlayer(
- state = playback,
- progress = { progressOf(positionMs.value, playback.durationMs) },
- backdrop = pageBackdrop,
- modifier = Modifier.padding(horizontal = 16.dp),
- sharedScope = this@SharedTransitionLayout,
- animatedScope = this@AnimatedVisibility,
- onExpand = { navController.navigate(Routes.PLAYER) },
- onTogglePlay = { player?.togglePlay() },
- onNext = { player?.seekToNextMediaItem() },
- )
- }
- if (!onPlayer) {
- BottomBar(
- route = route,
- bottomInset = navBar,
- backdrop = pageBackdrop,
- onSelect = navController::switchTab,
- )
- }
+ },
+ )
}
}
- }
}
}
}
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
new file mode 100644
index 0000000..a282e03
--- /dev/null
+++ b/app/src/main/java/dev/emanuele/spot/ui/player/NowPlayingSheet.kt
@@ -0,0 +1,165 @@
+package dev.emanuele.spot.ui.player
+
+import androidx.activity.compose.BackHandler
+import androidx.compose.animation.core.Animatable
+import androidx.compose.animation.core.Spring
+import androidx.compose.animation.core.spring
+import androidx.compose.foundation.gestures.Orientation
+import androidx.compose.foundation.gestures.draggable
+import androidx.compose.foundation.gestures.rememberDraggableState
+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.foundation.layout.padding
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.platform.LocalDensity
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.lerp
+import kotlinx.coroutines.launch
+import kotlin.math.abs
+
+/**
+ * The now-playing bar and the player, as one surface.
+ *
+ * The previous version made the player a navigation destination and tried to
+ * animate between the two. That can only ever cross-fade: they are separate
+ * 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.
+ *
+ * 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.
+ *
+ * @param progress 0 while collapsed, 1 while expanded. Hoisted because the tab
+ * bar has to fade out against it.
+ */
+@Composable
+fun NowPlayingSheet(
+ progress: Animatable<Float, *>,
+ /** Space the collapsed bar leaves for the tab bar beneath it. */
+ bottomInset: Dp,
+ collapsedContent: @Composable () -> Unit,
+ expandedContent: @Composable () -> Unit,
+) {
+ val scope = rememberCoroutineScope()
+ val density = LocalDensity.current
+ // Clamped, because the settle spring is under-damped on purpose: it passes
+ // 1 on the way in, and an interpolated padding past that end is negative,
+ // which Compose rejects outright.
+ val fraction = progress.value.coerceIn(0f, 1f)
+
+ BoxWithConstraints(Modifier.fillMaxSize()) {
+ val fullHeight = maxHeight
+ val collapsedHeight = MiniPlayerHeight
+ val travelPx = with(density) { (fullHeight - collapsedHeight).toPx() }
+
+ fun settle(target: Float) {
+ scope.launch {
+ progress.animateTo(
+ target,
+ // Slightly under-damped: it arrives with the smallest
+ // settle rather than stopping dead, which is what makes a
+ // panel this size feel like it has weight.
+ spring(dampingRatio = 0.86f, stiffness = Spring.StiffnessMediumLow),
+ )
+ }
+ }
+
+ BackHandler(enabled = fraction > 0.5f) { settle(0f) }
+
+ val draggable = rememberDraggableState { delta ->
+ scope.launch {
+ // Dragging up is negative, and up means expanding.
+ progress.snapTo((progress.value - delta / travelPx).coerceIn(0f, 1f))
+ }
+ }
+
+ Box(
+ Modifier
+ .align(Alignment.BottomCenter)
+ .fillMaxWidth()
+ .padding(horizontal = lerp(16.dp, 0.dp, fraction))
+ // The bar floats above the tab bar; the player owns the whole
+ // window.
+ .padding(bottom = lerp(bottomInset, 0.dp, fraction))
+ .height(lerp(collapsedHeight, fullHeight, fraction))
+ .clip(RoundedCornerShape(lerp(22.dp, 0.dp, fraction)))
+ .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
+ fraction > 0.5f -> 1f
+ else -> 0f
+ }
+ settle(target)
+ },
+ ),
+ ) {
+ // 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 (fraction > 0.001f) {
+ Box(
+ Modifier
+ .align(Alignment.BottomCenter)
+ .height(fullHeight)
+ .fillMaxWidth()
+ .graphicsLayer { alpha = expandedAlpha(fraction) },
+ ) {
+ expandedContent()
+ }
+ }
+
+ if (fraction < 0.999f) {
+ Box(
+ Modifier
+ .align(Alignment.TopCenter)
+ .height(collapsedHeight)
+ .fillMaxWidth()
+ .graphicsLayer { alpha = collapsedAlpha(fraction) },
+ ) {
+ collapsedContent()
+ }
+ }
+ }
+ }
+}
+
+/**
+ * The bar is gone by a fifth of the way up, the player is there by two thirds.
+ *
+ * They deliberately do not cross at 0.5: with both half-visible in the middle
+ * of the travel you see two sets of controls at once, which is precisely what
+ * the cross-fade version looked like.
+ */
+private fun collapsedAlpha(fraction: Float): Float =
+ (1f - fraction / 0.2f).coerceIn(0f, 1f)
+
+private fun expandedAlpha(fraction: Float): Float =
+ ((fraction - 0.15f) / 0.5f).coerceIn(0f, 1f)
+
+/** Past this, a drag is a flick and its direction decides where it lands. */
+private const val FLING_VELOCITY = 900f