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.

Menus that refract the page, and a hero that collapses into a bar

Lelonioe19f927a2a36
diff --git a/.claude/settings.local.json b/.claude/settings.local.json
index 3612619..93be70e 100644
--- a/.claude/settings.local.json
+++ b/.claude/settings.local.json
@@ -115,7 +115,8 @@
"Bash(git commit -q -m 'A draggable scrollbar, and sorting by when tracks were added *)",
"Bash(git commit -q -m 'Track menus, a page-coloured glass, and a remembered sort *)",
"Bash(git commit -q -m 'Keep the glass out of the layer it samples *)",
- "Bash(git commit -q -m 'Glass context menus, with remove-from-playlist *)"
+ "Bash(git commit -q -m 'Glass context menus, with remove-from-playlist *)",
+ "Bash(git commit -q -m 'Menus that refract the page, and a hero that collapses into a bar *)"
]
}
}
diff --git a/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin b/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin
index cd70365..c746769 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/components/GlassMenu.kt b/app/src/main/java/dev/emanuele/spot/ui/components/GlassMenu.kt
index 6f20c49..ac2d923 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/components/GlassMenu.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/components/GlassMenu.kt
@@ -1,12 +1,21 @@
package dev.emanuele.spot.ui.components
-import androidx.compose.animation.core.animateFloatAsState
+import androidx.compose.animation.AnimatedVisibility
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.foundation.background
import androidx.compose.foundation.clickable
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
@@ -15,72 +24,79 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
-import androidx.compose.runtime.getValue
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.TransformOrigin
-import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
-import androidx.compose.ui.window.Popup
-import androidx.compose.ui.window.PopupProperties
import com.kyant.backdrop.Backdrop
import dev.emanuele.spot.ui.player.GlassSurface
/**
* A context menu made of the same glass as everything else.
*
- * Material's `DropdownMenu` draws an opaque elevated card. It works, and it is
- * the one surface in the app that announces it came from a different design
- * system — a paper rectangle over a page built entirely out of refraction.
+ * Material's `DropdownMenu` draws an opaque elevated card — the one surface in
+ * the app that announces it came from a different design system.
*
- * The anchor is whatever composable this is placed inside, so it belongs in the
- * `Box` around the button that opens it.
+ * Drawn inside the screen rather than in a `Popup`, which is what the first
+ * version did and is worth explaining because a popup is the obvious choice. A
+ * popup is its own window: it cannot refract the list it is covering, because
+ * that list is in another window and in no layer the popup can sample. What
+ * came out was a pane of glass with nothing behind it — transparent, with the
+ * rows legible straight through its own text. As a sibling of the content,
+ * [backdrop] can be the layer the page is recorded into and the material
+ * behaves like every other pane in the app.
+ *
+ * @param anchor where the menu's top-left corner goes, in pixels from the top
+ * left of the box this is placed in. See [MENU_WIDTH] for placing it by its
+ * right edge instead.
*/
@Composable
-fun GlassMenu(
- expanded: Boolean,
- onDismiss: () -> Unit,
+fun BoxScope.GlassMenu(
+ visible: Boolean,
+ anchor: IntOffset,
backdrop: Backdrop,
- modifier: Modifier = Modifier,
- /** Where the menu sits relative to its anchor. */
- alignment: Alignment = Alignment.TopEnd,
- offset: IntOffset = IntOffset(0, 0),
+ onDismiss: () -> Unit,
content: @Composable ColumnScope.() -> Unit,
) {
- if (!expanded) return
-
- Popup(
- alignment = alignment,
- offset = offset,
- onDismissRequest = onDismiss,
- properties = PopupProperties(focusable = true),
+ // Catches the tap that closes the menu, and stops what is behind it from
+ // competing with it.
+ AnimatedVisibility(
+ visible = visible,
+ enter = fadeIn(tween(140)),
+ exit = fadeOut(tween(140)),
+ modifier = Modifier.fillMaxSize(),
) {
- val shape = RoundedCornerShape(20.dp)
- val scale by animateFloatAsState(
- targetValue = 1f,
- animationSpec = tween(140),
- label = "menuScale",
+ Box(
+ Modifier
+ .fillMaxSize()
+ .background(Color.Black.copy(alpha = 0.32f))
+ .clickable(interactionSource = null, indication = null, onClick = onDismiss),
)
+ }
+ AnimatedVisibility(
+ visible = visible,
+ // Grows out of the corner it was opened from, which is the only thing
+ // tying it to the button that was tapped.
+ enter = scaleIn(tween(170), initialScale = 0.86f, transformOrigin = TopEnd) +
+ fadeIn(tween(120)),
+ exit = scaleOut(tween(130), targetScale = 0.9f, transformOrigin = TopEnd) +
+ fadeOut(tween(110)),
+ modifier = Modifier
+ .align(Alignment.TopStart)
+ .offset { anchor },
+ ) {
+ val shape = RoundedCornerShape(20.dp)
GlassSurface(
backdrop = backdrop,
shape = shape,
surfaceColor = MenuFilm,
- modifier = modifier
- .width(236.dp)
- // Grows out of the corner it is anchored to rather than
- // appearing at full size, which is the only thing that ties it
- // to the button that was tapped.
- .graphicsLayer {
- scaleX = 0.92f + 0.08f * scale
- scaleY = 0.92f + 0.08f * scale
- this.alpha = scale
- transformOrigin = TransformOrigin(1f, 0f)
- }
+ modifier = Modifier
+ .width(MENU_WIDTH)
.clip(shape),
) {
Column(Modifier.padding(vertical = 6.dp), content = content)
@@ -114,5 +130,16 @@ fun GlassMenuItem(
}
}
-/** Enough film to read text over anything the page puts behind it. */
-private val MenuFilm = Color.White.copy(alpha = 0.14f)
+/** How wide a menu is, so a caller can place it by its right edge. */
+val MENU_WIDTH = 244.dp
+
+private val TopEnd = TransformOrigin(1f, 0f)
+
+/**
+ * The film over the refracted page.
+ *
+ * Heavier than the app's other panes deliberately: those sit over a backdrop
+ * nobody is reading, and this one sits over a list of track titles. At the usual
+ * twelve per cent the rows underneath were legible through the menu's own text.
+ */
+private val MenuFilm = Color.Black.copy(alpha = 0.62f)
diff --git a/app/src/main/java/dev/emanuele/spot/ui/library/PlaylistScreen.kt b/app/src/main/java/dev/emanuele/spot/ui/library/PlaylistScreen.kt
index 7e4d2dd..64e013c 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/library/PlaylistScreen.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/library/PlaylistScreen.kt
@@ -46,6 +46,16 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
+import dev.emanuele.spot.ui.player.GlassSurface
+import dev.emanuele.spot.ui.components.MENU_WIDTH
+import androidx.compose.ui.unit.IntOffset
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.platform.LocalDensity
+import androidx.compose.ui.layout.boundsInRoot
+import androidx.compose.ui.layout.onGloballyPositioned
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.runtime.derivedStateOf
+import androidx.compose.foundation.layout.BoxScope
import dev.emanuele.spot.data.CatalogTrack
import dev.emanuele.spot.ui.MainViewModel
import com.kyant.backdrop.Backdrop
@@ -138,7 +148,35 @@ fun PlaylistScreen(
// cover.
val pageBackdrop = rememberLayerBackdrop()
+ // The page *including* its list, for the panes that cover it: the context
+ // menu and the collapsed bar. Nothing inside this layer samples it — the
+ // header's buttons take the plain page colour above — so there is no cycle.
+ val contentBackdrop = rememberLayerBackdrop()
+
+ // Which track's menu is open, and where its button is, so the menu can be
+ // drawn at the top level rather than inside a row the list may recycle.
+ var menuTrack by remember { mutableStateOf<CatalogTrack?>(null) }
+ var menuAnchor by remember { mutableStateOf(IntOffset.Zero) }
+ var sortAnchor by remember { mutableStateOf(IntOffset.Zero) }
+
+ val density = LocalDensity.current
+ val listState = rememberLazyListState()
+
+ // How far the hero has been scrolled away, 0 to 1. Read in a derived state
+ // so the bar it drives recomposes when the answer changes rather than on
+ // every pixel of the scroll.
+ val collapse by remember {
+ derivedStateOf {
+ if (listState.firstVisibleItemIndex > 0) {
+ 1f
+ } else {
+ (listState.firstVisibleItemScrollOffset / COLLAPSE_DISTANCE_PX).coerceIn(0f, 1f)
+ }
+ }
+ }
+
Box(Modifier.fillMaxSize()) {
+ Box(Modifier.fillMaxSize().layerBackdrop(contentBackdrop)) {
// The page colour, and only the page colour.
//
// The layer has to hold nothing that samples it. Recording the whole
@@ -168,8 +206,6 @@ fun PlaylistScreen(
// No top content padding: the hero runs under the status bar, which is
// the whole point of the layout — the picture is the top of the screen,
// not something sitting below a gap.
- val listState = rememberLazyListState()
-
LazyColumn(
state = listState,
contentPadding = PaddingValues(bottom = contentPadding.calculateBottomPadding()),
@@ -207,14 +243,9 @@ fun PlaylistScreen(
} else {
"Brani"
},
- backdrop = pageBackdrop,
sort = sort,
- sortOpen = sortOpen,
onSortOpen = { sortOpen = it },
- onSort = {
- sort = it
- onSortChange(it.name)
- },
+ onAnchor = { sortAnchor = it },
)
}
@@ -281,17 +312,10 @@ fun PlaylistScreen(
position = index + 1,
isCurrent = track.uri == nowPlayingUri,
onClick = { onPlay(visible, index) },
- onEnqueue = { onEnqueue(track) },
- onAddToPlaylist = { onAddToPlaylist(track) },
- // Only a playlist can have something taken out of
- // it; an album or an artist's top tracks is not a
- // list the account owns.
- onRemove = if (state.kind == MainViewModel.DetailKind.PLAYLIST) {
- { onRemoveFromPlaylist(track) }
- } else {
- null
+ onMenu = { anchor ->
+ menuAnchor = anchor
+ menuTrack = track
},
- backdrop = pageBackdrop,
)
}
}
@@ -326,6 +350,8 @@ fun PlaylistScreen(
}
}
+ }
+
LazyScrollBar(
state = listState,
startAfter = "track",
@@ -338,14 +364,16 @@ fun PlaylistScreen(
)
// Floating rather than a top bar: the list scrolls under it, so the
- // picture stays uninterrupted.
+ // picture stays uninterrupted. It gives way to the collapsed bar, which
+ // carries a back button of its own.
LiquidButton(
onClick = onBack,
backdrop = pageBackdrop,
modifier = Modifier
.padding(top = contentPadding.calculateTopPadding() + 8.dp, start = 14.dp)
.align(Alignment.TopStart)
- .size(42.dp),
+ .size(42.dp)
+ .graphicsLayer { alpha = 1f - collapse },
contentHeight = 42.dp,
contentPadding = 0.dp,
blurRadius = 8.dp,
@@ -357,6 +385,173 @@ fun PlaylistScreen(
modifier = Modifier.size(20.dp),
)
}
+
+ // What the hero turns into. The cover, the title and the three controls
+ // do not simply scroll away — the title is what tells you which playlist
+ // you are in, and the play button is the thing most likely to be wanted
+ // after reading a screenful of tracks.
+ CollapsedBar(
+ title = state.name,
+ artworkUrl = state.artworkUrl,
+ collapse = collapse,
+ backdrop = contentBackdrop,
+ topPadding = contentPadding.calculateTopPadding(),
+ searching = searching,
+ onBack = onBack,
+ onPlay = { visible.takeIf { it.isNotEmpty() }?.let { onPlay(it, 0) } },
+ onShuffle = { visible.takeIf { it.isNotEmpty() }?.let(onShuffle) },
+ onToggleSearch = {
+ searching = !searching
+ if (!searching) query = ""
+ },
+ modifier = Modifier.align(Alignment.TopCenter),
+ )
+
+ // Both menus are drawn here rather than beside the buttons that open
+ // them: a row inside a lazy list can be recycled out from under its own
+ // popup, and only at this level is there a layer holding the page for
+ // the glass to refract.
+ TrackMenu(
+ track = menuTrack,
+ anchor = menuAnchor.leftOf(density),
+ backdrop = contentBackdrop,
+ onDismiss = { menuTrack = null },
+ onPlay = { track -> visible.indexOf(track).takeIf { it >= 0 }?.let { onPlay(visible, it) } },
+ onEnqueue = onEnqueue,
+ onAddToPlaylist = onAddToPlaylist,
+ // Only a playlist can have something taken out of it; an album or an
+ // artist's top tracks is not a list the account owns.
+ onRemove = if (state.kind == MainViewModel.DetailKind.PLAYLIST) {
+ onRemoveFromPlaylist
+ } else {
+ null
+ },
+ )
+
+ GlassMenu(
+ visible = sortOpen,
+ anchor = sortAnchor.leftOf(density),
+ backdrop = contentBackdrop,
+ onDismiss = { sortOpen = false },
+ ) {
+ TrackSort.entries.forEach { option ->
+ GlassMenuItem(
+ option.label,
+ if (option == sort) {
+ PhosphorIcons.Regular.Check
+ } else {
+ PhosphorIcons.Regular.ArrowsDownUp
+ },
+ ) {
+ sort = option
+ onSortChange(option.name)
+ sortOpen = false
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Turns a button's position into where a menu hanging off its right edge goes.
+ *
+ * Menus open leftwards from the control that owns them, because every one of
+ * those controls is at the right-hand edge of the screen.
+ */
+private fun IntOffset.leftOf(density: androidx.compose.ui.unit.Density): IntOffset {
+ val width = with(density) { MENU_WIDTH.roundToPx() }
+ val gap = with(density) { 8.dp.roundToPx() }
+ return IntOffset((x - width + gap).coerceAtLeast(gap), y + gap)
+}
+
+/**
+ * The hero, once it has been scrolled away.
+ *
+ * Fades in over the last of the cover rather than sliding down from nowhere, so
+ * the two read as one thing changing size. The controls are the same three, at
+ * the size a bar can carry them.
+ */
+@Composable
+private fun CollapsedBar(
+ title: String,
+ artworkUrl: String?,
+ collapse: Float,
+ backdrop: Backdrop,
+ topPadding: Dp,
+ searching: Boolean,
+ onBack: () -> Unit,
+ onPlay: () -> Unit,
+ onShuffle: () -> Unit,
+ onToggleSearch: () -> Unit,
+ modifier: Modifier = Modifier,
+) {
+ if (collapse <= 0.01f) return
+
+ GlassSurface(
+ backdrop = backdrop,
+ shape = RoundedCornerShape(0.dp),
+ surfaceColor = Color.Black.copy(alpha = 0.34f),
+ modifier = modifier
+ .fillMaxWidth()
+ .graphicsLayer { alpha = collapse },
+ ) {
+ Row(
+ Modifier
+ .fillMaxWidth()
+ .padding(top = topPadding + 6.dp, bottom = 10.dp)
+ .padding(horizontal = 12.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ IconButton(onClick = onBack) {
+ Icon(
+ PhosphorIcons.Regular.ArrowLeft,
+ contentDescription = "Indietro",
+ tint = Color.White,
+ modifier = Modifier.size(20.dp),
+ )
+ }
+ Artwork(
+ url = artworkUrl,
+ title = title,
+ modifier = Modifier.size(34.dp),
+ corner = 8.dp,
+ decodeSize = 34.dp,
+ )
+ Text(
+ title,
+ style = MaterialTheme.typography.titleMedium,
+ color = Color.White,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier
+ .weight(1f)
+ .padding(horizontal = 12.dp),
+ )
+ IconButton(onClick = onToggleSearch) {
+ Icon(
+ if (searching) PhosphorIcons.Regular.X else PhosphorIcons.Fill.MagnifyingGlass,
+ contentDescription = "Cerca fra i brani",
+ tint = Color.White,
+ modifier = Modifier.size(18.dp),
+ )
+ }
+ IconButton(onClick = onShuffle) {
+ Icon(
+ PhosphorIcons.Regular.Shuffle,
+ contentDescription = "Casuale",
+ tint = Color.White,
+ modifier = Modifier.size(18.dp),
+ )
+ }
+ IconButton(onClick = onPlay) {
+ Icon(
+ PhosphorIcons.Fill.Play,
+ contentDescription = "Riproduci",
+ tint = Color.White,
+ modifier = Modifier.size(20.dp),
+ )
+ }
+ }
}
}
@@ -565,11 +760,10 @@ private fun AlbumStrip(
@Composable
private fun SectionHeader(
title: String,
- backdrop: Backdrop,
sort: TrackSort,
- sortOpen: Boolean,
onSortOpen: (Boolean) -> Unit,
- onSort: (TrackSort) -> Unit,
+ /** Where the sort button is, for the menu drawn above the list. */
+ onAnchor: (IntOffset) -> Unit,
) {
Row(
Modifier
@@ -579,8 +773,14 @@ private fun SectionHeader(
) {
Text(title, style = MaterialTheme.typography.titleMedium, modifier = Modifier.weight(1f))
- Box {
- IconButton(onClick = { onSortOpen(true) }) {
+ IconButton(
+ onClick = { onSortOpen(true) },
+ modifier = Modifier.onGloballyPositioned {
+ val root = it.boundsInRoot()
+ onAnchor(IntOffset(root.left.toInt(), root.bottom.toInt()))
+ },
+ ) {
+ run {
Icon(
PhosphorIcons.Regular.ArrowsDownUp,
contentDescription = "Ordina",
@@ -592,31 +792,18 @@ private fun SectionHeader(
modifier = Modifier.size(20.dp),
)
}
- // The same glass as the track menu: two context menus on one screen
- // made of two different materials is worse than either choice.
- GlassMenu(
- expanded = sortOpen,
- onDismiss = { onSortOpen(false) },
- backdrop = backdrop,
- ) {
- TrackSort.entries.forEach { option ->
- GlassMenuItem(
- option.label,
- if (option == sort) {
- PhosphorIcons.Regular.Check
- } else {
- PhosphorIcons.Regular.ArrowsDownUp
- },
- ) {
- onSort(option)
- onSortOpen(false)
- }
- }
- }
}
}
}
+/**
+ * How much of the hero has to go before the bar has fully taken over.
+ *
+ * Not the whole cover: the bar should be there by the time the first tracks
+ * reach the top of the screen, not once the entire picture has gone.
+ */
+private const val COLLAPSE_DISTANCE_PX = 620f
+
/** Tall enough to be the top of the screen rather than a banner above a list. */
private val HERO_HEIGHT = 420.dp
@@ -640,12 +827,9 @@ private fun TrackRow(
position: Int,
isCurrent: Boolean,
onClick: () -> Unit,
- onEnqueue: () -> Unit,
- onAddToPlaylist: () -> Unit,
- onRemove: (() -> Unit)?,
- backdrop: Backdrop,
+ /** Where the menu button is on screen, for the menu drawn above the list. */
+ onMenu: (IntOffset) -> Unit,
) {
- var menuOpen by remember { mutableStateOf(false) }
val shape = RoundedCornerShape(14.dp)
// Eased rather than snapped: rows change state on every track advance, and
// a hard cut in the middle of a list draws the eye more than the change
@@ -720,24 +904,21 @@ private fun TrackRow(
)
}
- Box {
- IconButton(onClick = { menuOpen = true }, modifier = Modifier.size(32.dp)) {
- Icon(
- PhosphorIcons.Regular.DotsThree,
- contentDescription = "Altro",
- tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.6f),
- modifier = Modifier.size(18.dp),
- )
- }
- TrackMenu(
- expanded = menuOpen,
- track = track,
- backdrop = backdrop,
- onDismiss = { menuOpen = false },
- onPlay = onClick,
- onEnqueue = onEnqueue,
- onAddToPlaylist = onAddToPlaylist,
- onRemove = onRemove,
+ var buttonPosition by remember { mutableStateOf(IntOffset.Zero) }
+ IconButton(
+ onClick = { onMenu(buttonPosition) },
+ modifier = Modifier
+ .size(32.dp)
+ .onGloballyPositioned {
+ val root = it.boundsInRoot()
+ buttonPosition = IntOffset(root.left.toInt(), root.bottom.toInt())
+ },
+ ) {
+ Icon(
+ PhosphorIcons.Regular.DotsThree,
+ contentDescription = "Altro",
+ tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.6f),
+ modifier = Modifier.size(18.dp),
)
}
}
@@ -752,32 +933,39 @@ private fun TrackRow(
* display and not its URI, so the entry would be there and not work.
*/
@Composable
-private fun TrackMenu(
- expanded: Boolean,
- track: CatalogTrack,
+private fun BoxScope.TrackMenu(
+ track: CatalogTrack?,
+ anchor: IntOffset,
backdrop: Backdrop,
onDismiss: () -> Unit,
- onPlay: () -> Unit,
- onEnqueue: () -> Unit,
- onAddToPlaylist: () -> Unit,
+ onPlay: (CatalogTrack) -> Unit,
+ onEnqueue: (CatalogTrack) -> Unit,
+ onAddToPlaylist: (CatalogTrack) -> Unit,
/** Null unless this list is a playlist the account can edit. */
- onRemove: (() -> Unit)?,
+ onRemove: ((CatalogTrack) -> Unit)?,
) {
val clipboard = LocalClipboardManager.current
+ // Held so the menu still has something to draw while it animates out.
+ val shown = remember(track) { track } ?: return
- GlassMenu(expanded = expanded, onDismiss = onDismiss, backdrop = backdrop) {
- GlassMenuItem("Riproduci", PhosphorIcons.Fill.Play) { onDismiss(); onPlay() }
+ GlassMenu(
+ visible = track != null,
+ anchor = anchor,
+ backdrop = backdrop,
+ onDismiss = onDismiss,
+ ) {
+ GlassMenuItem("Riproduci", PhosphorIcons.Fill.Play) { onDismiss(); onPlay(shown) }
GlassMenuItem("Aggiungi alla coda", PhosphorIcons.Regular.Queue) {
onDismiss()
- onEnqueue()
+ onEnqueue(shown)
}
GlassMenuItem("Aggiungi a una playlist", PhosphorIcons.Regular.Plus) {
onDismiss()
- onAddToPlaylist()
+ onAddToPlaylist(shown)
}
GlassMenuItem("Copia link", PhosphorIcons.Regular.LinkSimple) {
onDismiss()
- clipboard.setText(AnnotatedString(track.openLink()))
+ clipboard.setText(AnnotatedString(shown.openLink()))
}
if (onRemove != null) {
GlassMenuItem(
@@ -786,7 +974,7 @@ private fun TrackMenu(
destructive = true,
) {
onDismiss()
- onRemove()
+ onRemove(shown)
}
}
}