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.

Relink playlist tracks to this market; icon-only track menu

Lelonio3efe2bb6d0b2
diff --git a/.claude/settings.local.json b/.claude/settings.local.json
index 6dd5195..4bc75c8 100644
--- a/.claude/settings.local.json
+++ b/.claude/settings.local.json
@@ -117,7 +117,8 @@
"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 'Menus that refract the page, and a hero that collapses into a bar *)",
- "Bash(git commit -q -m 'A hero that actually collapses, and a menu nothing covers *)"
+ "Bash(git commit -q -m 'A hero that actually collapses, and a menu nothing covers *)",
+ "Bash(git commit -q -m 'Relink playlist tracks to this market; icon-only track menu *)"
]
}
}
diff --git a/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin b/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin
index 41fb0e5..1a2ae44 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/data/SpotifyApi.kt b/app/src/main/java/dev/emanuele/spot/data/SpotifyApi.kt
index 687b078..8ecc6e7 100644
--- a/app/src/main/java/dev/emanuele/spot/data/SpotifyApi.kt
+++ b/app/src/main/java/dev/emanuele/spot/data/SpotifyApi.kt
@@ -35,11 +35,22 @@ interface SpotifyApi {
@Query("offset") offset: Int = 0,
): PageDto<PlaylistDto>
+ /**
+ * A page of a playlist's tracks.
+ *
+ * `market` is not optional in practice. Without it the response carries each
+ * track's *original* URI, and a large share of the catalogue is region-split:
+ * the original is not playable here and the engine skips straight past it —
+ * which looks exactly like a player that will not play anything. With a
+ * market Spotify relinks each track to the copy licensed for this account,
+ * and `is_playable` becomes meaningful.
+ */
@GET("v1/playlists/{id}/tracks")
suspend fun playlistTracks(
@Path("id") playlistId: String,
@Query("limit") limit: Int = 100,
@Query("offset") offset: Int = 0,
+ @Query("market") market: String = "from_token",
): PageDto<PlaylistTrackDto>
/**
diff --git a/app/src/main/java/dev/emanuele/spot/ui/MainViewModel.kt b/app/src/main/java/dev/emanuele/spot/ui/MainViewModel.kt
index 9a3af37..590256d 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/MainViewModel.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/MainViewModel.kt
@@ -730,8 +730,15 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {
var offset = 0
while (true) {
val page = container.api.playlistTracks(id, limit = WEB_API_PAGE, offset = offset)
- // Episodes and delisted tracks come back as a null track.
- loaded += page.items.mapNotNull { it.track?.toCatalogTrack(it.addedAt) }
+ // Episodes and delisted tracks come back as a null track, and
+ // `is_playable` is false for anything the relinking could not find a
+ // licensed copy of here. Keeping those would put items in the queue
+ // that the engine can only skip.
+ loaded += page.items.mapNotNull { item ->
+ item.track
+ ?.takeIf { it.isPlayable != false && it.uri.startsWith("spotify:track:") }
+ ?.toCatalogTrack(item.addedAt)
+ }
offset += page.items.size
if (showProgress) {
_playlist.value = base.copy(
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 d604bf0..a5ef831 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt
@@ -80,6 +80,15 @@ import dev.emanuele.spot.ui.library.LibraryScreen
import dev.emanuele.spot.ui.library.PlaylistScreen
import dev.emanuele.spot.ui.player.GlassFilm
import dev.emanuele.spot.ui.player.AddToPlaylistSheet
+import androidx.compose.ui.text.AnnotatedString
+import androidx.compose.ui.unit.IntOffset
+import dev.emanuele.spot.ui.components.GlassIconMenu
+import dev.emanuele.spot.ui.components.GlassIconMenuItem
+import dev.emanuele.spot.ui.library.openLink
+import com.adamglin.phosphoricons.regular.LinkSimple
+import com.adamglin.phosphoricons.regular.Plus
+import com.adamglin.phosphoricons.regular.Queue
+import com.adamglin.phosphoricons.regular.Trash
import dev.emanuele.spot.ui.player.MiniPlayer
import dev.emanuele.spot.ui.player.MiniPlayerHeight
import dev.emanuele.spot.ui.player.NowPlayingSheet
@@ -95,6 +104,7 @@ import dev.emanuele.spot.ui.theme.SpotTheme
import dev.emanuele.spot.ui.theme.rememberArtworkColor
import kotlinx.coroutines.launch
import com.adamglin.PhosphorIcons
+import com.adamglin.phosphoricons.fill.Play
import com.adamglin.phosphoricons.Fill
import com.adamglin.phosphoricons.Regular
import com.adamglin.phosphoricons.fill.House
@@ -104,6 +114,13 @@ import com.adamglin.phosphoricons.regular.House
import com.adamglin.phosphoricons.regular.MagnifyingGlass
import com.adamglin.phosphoricons.regular.MusicNotes
+/** A track menu waiting to be drawn: what it is about, and where it points. */
+private data class TrackMenuRequest(
+ val track: dev.emanuele.spot.data.CatalogTrack,
+ val anchor: IntOffset,
+ val removable: Boolean,
+)
+
object Routes {
const val HOME = "home"
const val SEARCH = "search"
@@ -159,6 +176,10 @@ fun SpotApp(
val addToPlaylist by viewModel.addToPlaylist.collectAsStateWithLifecycle()
val trackSort by viewModel.trackSort.collectAsStateWithLifecycle()
+ // The open track menu, if any. Held here because the menu is drawn above
+ // everything the app puts over its screens.
+ var trackMenu by remember { mutableStateOf<TrackMenuRequest?>(null) }
+
// Once, on the first composition that has a usable Web API session. The
// ViewModel keeps what it fetched, so navigating away and back does not
// spend the quota again.
@@ -367,7 +388,16 @@ fun SpotApp(
onAddToPlaylist = { track ->
viewModel.openAddToPlaylist(track.uri, track.name)
},
- onRemoveFromPlaylist = viewModel::removeFromPlaylist,
+ onTrackMenu = { track, anchor ->
+ trackMenu = TrackMenuRequest(
+ track = track,
+ anchor = anchor,
+ // Only a playlist can have
+ // something taken out of it.
+ removable = playlist.kind ==
+ MainViewModel.DetailKind.PLAYLIST,
+ )
+ },
storedSort = trackSort,
onSortChange = viewModel::setTrackSort,
onOpenItem = { item ->
@@ -486,6 +516,47 @@ fun SpotApp(
)
}
+ // Above the tab bar and the now-playing bar, which is the whole
+ // reason it lives here instead of in the screen that asked for
+ // it.
+ val menu = trackMenu
+ val clipboard = androidx.compose.ui.platform.LocalClipboardManager.current
+ GlassIconMenu(
+ visible = menu != null,
+ anchor = menu?.anchor ?: IntOffset.Zero,
+ backdrop = pageBackdrop,
+ onDismiss = { trackMenu = null },
+ ) {
+ if (menu != null) {
+ GlassIconMenuItem(PhosphorIcons.Fill.Play, "Riproduci") {
+ trackMenu = null
+ onPlay(listOf(menu.track), 0)
+ }
+ GlassIconMenuItem(PhosphorIcons.Regular.Queue, "Aggiungi alla coda") {
+ trackMenu = null
+ onEnqueue(menu.track)
+ }
+ GlassIconMenuItem(PhosphorIcons.Regular.Plus, "Aggiungi a una playlist") {
+ trackMenu = null
+ viewModel.openAddToPlaylist(menu.track.uri, menu.track.name)
+ }
+ GlassIconMenuItem(PhosphorIcons.Regular.LinkSimple, "Copia link") {
+ trackMenu = null
+ clipboard.setText(AnnotatedString(menu.track.openLink()))
+ }
+ if (menu.removable) {
+ GlassIconMenuItem(
+ PhosphorIcons.Regular.Trash,
+ "Rimuovi dalla playlist",
+ destructive = true,
+ ) {
+ trackMenu = null
+ viewModel.removeFromPlaylist(menu.track)
+ }
+ }
+ }
+ }
+
// Over everything, including the player: the same sheet is
// opened from a track row in the library and from the plus in
// the player, and it is one sheet with one state.
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 fab9971..3d4c1c3 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
@@ -11,6 +11,17 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
+import dev.emanuele.spot.ui.player.GlassSurface
+import dev.emanuele.spot.ui.theme.softShadow
+import com.kyant.backdrop.Backdrop
+import com.kyant.shapes.Capsule
+import androidx.compose.foundation.shape.CircleShape
+import androidx.compose.foundation.layout.offset
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.RowScope
+import androidx.compose.foundation.layout.BoxScope
+import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
@@ -130,3 +141,91 @@ private val MenuSurface = Color(0xFF16161A)
/** The hairline every other surface in the app catches light with. */
private val MenuEdge = Color.White.copy(alpha = 0.14f)
+
+/**
+ * The compact form: one row of icons in a glass capsule.
+ *
+ * For a menu whose entries are all verbs on the same object — play it, queue it,
+ * add it, copy it, remove it. Five words stacked in a list is a dialogue box;
+ * five icons in a capsule is a control, and it is small enough to sit beside the
+ * row it belongs to rather than over half the screen.
+ *
+ * Unlike [GlassMenu] this is not a popup, so it can refract [backdrop] properly.
+ * That means it has to be drawn late enough not to be covered — at the app
+ * level, above the tab bar and the now-playing bar, not inside a screen.
+ */
+@Composable
+fun BoxScope.GlassIconMenu(
+ visible: Boolean,
+ anchor: IntOffset,
+ backdrop: Backdrop,
+ onDismiss: () -> Unit,
+ content: @Composable RowScope.() -> Unit,
+) {
+ AnimatedVisibility(
+ visible = visible,
+ enter = fadeIn(tween(120)),
+ exit = fadeOut(tween(120)),
+ modifier = Modifier.fillMaxSize(),
+ ) {
+ Box(
+ Modifier
+ .fillMaxSize()
+ .clickable(interactionSource = null, indication = null, onClick = onDismiss),
+ )
+ }
+
+ AnimatedVisibility(
+ visible = visible,
+ enter = scaleIn(tween(180), initialScale = 0.7f, transformOrigin = TopEnd) +
+ fadeIn(tween(120)),
+ exit = scaleOut(tween(130), targetScale = 0.8f, transformOrigin = TopEnd) +
+ fadeOut(tween(110)),
+ modifier = Modifier
+ .align(Alignment.TopStart)
+ .offset { anchor },
+ ) {
+ val shape = Capsule()
+ GlassSurface(
+ backdrop = backdrop,
+ shape = shape,
+ surfaceColor = CapsuleFilm,
+ modifier = Modifier
+ .height(54.dp)
+ .clip(shape)
+ .softShadow(shape, elevation = 18.dp, spot = 0.3f),
+ ) {
+ Row(
+ Modifier.padding(horizontal = 6.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ content = content,
+ )
+ }
+ }
+}
+
+@Composable
+fun GlassIconMenuItem(
+ icon: ImageVector,
+ description: String,
+ destructive: Boolean = false,
+ onClick: () -> Unit,
+) {
+ Box(
+ Modifier
+ .size(48.dp)
+ .clip(CircleShape)
+ .clickable(onClick = onClick),
+ contentAlignment = Alignment.Center,
+ ) {
+ Icon(
+ icon,
+ contentDescription = description,
+ tint = if (destructive) MaterialTheme.colorScheme.error else Color.White,
+ modifier = Modifier.size(21.dp),
+ )
+ }
+}
+
+/** Light enough to stay glass; the capsule is small and never covers text. */
+private val CapsuleFilm = Color.White.copy(alpha = 0.14f)
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 b71c924..f39d0b3 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
@@ -115,7 +115,14 @@ fun PlaylistScreen(
onShuffle: (List<CatalogTrack>) -> Unit,
/** Opens the app-wide "add to playlist" sheet for one track. */
onAddToPlaylist: (CatalogTrack) -> Unit,
- onRemoveFromPlaylist: (CatalogTrack) -> Unit,
+ /**
+ * Opens the track menu, which the app draws rather than this screen.
+ *
+ * It has to be above the tab bar and the now-playing bar, and those are
+ * drawn over the whole navigation host — nothing inside a screen can reach
+ * that far up.
+ */
+ onTrackMenu: (CatalogTrack, IntOffset) -> Unit,
onOpenItem: (dev.emanuele.spot.data.SearchItem) -> Unit = {},
/** The remembered track order, and where a change to it is stored. */
storedSort: String? = null,
@@ -155,10 +162,6 @@ fun PlaylistScreen(
// cover.
val pageBackdrop = 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
@@ -338,10 +341,7 @@ fun PlaylistScreen(
position = index + 1,
isCurrent = track.uri == nowPlayingUri,
onClick = { onPlay(visible, index) },
- onMenu = { anchor ->
- menuAnchor = anchor
- menuTrack = track
- },
+ onMenu = { anchor -> onTrackMenu(track, anchor) },
)
}
}
@@ -411,26 +411,6 @@ fun PlaylistScreen(
)
}
- // 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),
- 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),
@@ -920,50 +900,8 @@ private fun TrackRow(
* app to do. No "go to album" — the track model carries the album's name for
* display and not its URI, so the entry would be there and not work.
*/
-@Composable
-private fun TrackMenu(
- track: CatalogTrack?,
- anchor: IntOffset,
- onDismiss: () -> Unit,
- onPlay: (CatalogTrack) -> Unit,
- onEnqueue: (CatalogTrack) -> Unit,
- onAddToPlaylist: (CatalogTrack) -> Unit,
- /** Null unless this list is a playlist the account can edit. */
- 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(visible = track != null, anchor = anchor, onDismiss = onDismiss) {
- GlassMenuItem("Riproduci", PhosphorIcons.Fill.Play) { onDismiss(); onPlay(shown) }
- GlassMenuItem("Aggiungi alla coda", PhosphorIcons.Regular.Queue) {
- onDismiss()
- onEnqueue(shown)
- }
- GlassMenuItem("Aggiungi a una playlist", PhosphorIcons.Regular.Plus) {
- onDismiss()
- onAddToPlaylist(shown)
- }
- GlassMenuItem("Copia link", PhosphorIcons.Regular.LinkSimple) {
- onDismiss()
- clipboard.setText(AnnotatedString(shown.openLink()))
- }
- if (onRemove != null) {
- GlassMenuItem(
- "Rimuovi dalla playlist",
- PhosphorIcons.Regular.Trash,
- destructive = true,
- ) {
- onDismiss()
- onRemove(shown)
- }
- }
- }
-}
-
/** The web address for a track URI, which is what a share expects. */
-private fun CatalogTrack.openLink(): String =
+fun CatalogTrack.openLink(): String =
"https://open.spotify.com/track/" + uri.substringAfterLast(':')
@Composable