Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.
Kotlin alternativeandroidandroid-applicationclientglassmorphisminnertubelibrespotliquid-glassspotifyspotify-connectspotifyapiyoutube-musicyoutube-playerytdlnis
Track menus, a page-coloured glass, and a remembered sort
Lelonio7c2c2d787fdd
diff --git a/.claude/settings.local.json b/.claude/settings.local.jsonindex 31bc2dd..b2ba98b 100644--- a/.claude/settings.local.json+++ b/.claude/settings.local.json@@ -112,7 +112,8 @@"Bash(PATH=/Users/emanuele/.cargo/bin:__TRACKED_VAR__ cargo check --quiet)","Bash(git commit -q -m 'Cap concurrent track lookups and retry the dropped ones *)","Bash(git commit -q -m 'Read playlists through the Web API, and keep them *)",- "Bash(git commit -q -m 'A draggable scrollbar, and sorting by when tracks were added *)"+ "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 *)"]}}diff --git a/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin b/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.binindex 83d38e8..7956ea8 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 Logljh/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/additional_project_files.txtCA-?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint ����3 ����3i+?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint ي���3 ����3ig-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� ����3nl-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 ي���3db-`/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 @ ����3ec-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�� ����3ig-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 �" ����3om-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 ( ����3ge-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 ����3DB-@/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 filediff --git a/app/src/main/java/dev/emanuele/spot/SpotApplication.kt b/app/src/main/java/dev/emanuele/spot/SpotApplication.ktindex f88eb2e..9f645ef 100644--- a/app/src/main/java/dev/emanuele/spot/SpotApplication.kt+++ b/app/src/main/java/dev/emanuele/spot/SpotApplication.kt@@ -4,6 +4,7 @@ import android.app.Applicationimport dev.emanuele.spot.auth.TokenStoreimport dev.emanuele.spot.auth.WebApiAccountimport dev.emanuele.spot.data.PlaylistOrderStore+import dev.emanuele.spot.data.PreferencesStoreimport dev.emanuele.spot.data.RecentStoreimport dev.emanuele.spot.playback.EffectPresetStoreimport dev.emanuele.spot.data.ApiFactory@@ -23,6 +24,7 @@ class SpotApplication : Application() {/** Which playlists were opened most recently, for ordering the home page. */val playlistOrder: PlaylistOrderStore by lazy { PlaylistOrderStore(this) }+ val preferences: PreferencesStore by lazy { PreferencesStore(this) }/*** The user's own Spotify application. Web API calls go through it so theydiff --git a/app/src/main/java/dev/emanuele/spot/data/PreferencesStore.kt b/app/src/main/java/dev/emanuele/spot/data/PreferencesStore.ktnew file mode 100644index 0000000..7c0cc1a--- /dev/null+++ b/app/src/main/java/dev/emanuele/spot/data/PreferencesStore.kt@@ -0,0 +1,34 @@+package dev.emanuele.spot.data++import android.content.Context+import kotlinx.coroutines.flow.MutableStateFlow+import kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.flow.asStateFlow++/**+ * Small UI choices that should survive the screen being left.+ *+ * Kept as strings rather than as an enum so this module does not have to know+ * about the screens that use it, and so a value written by an older version that+ * no longer exists reads back as "not set" instead of crashing.+ */+class PreferencesStore(context: Context) {++ private val prefs = context.applicationContext+ .getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)++ private val _trackSort = MutableStateFlow(prefs.getString(KEY_TRACK_SORT, null))++ /** How the detail screen's track list is ordered; null until first chosen. */+ val trackSort: StateFlow<String?> = _trackSort.asStateFlow()++ fun setTrackSort(value: String) {+ _trackSort.value = value+ prefs.edit().putString(KEY_TRACK_SORT, value).apply()+ }++ private companion object {+ const val FILE_NAME = "spot_preferences"+ const val KEY_TRACK_SORT = "track_sort"+ }+}diff --git a/app/src/main/java/dev/emanuele/spot/ui/MainViewModel.kt b/app/src/main/java/dev/emanuele/spot/ui/MainViewModel.ktindex 009e641..4987ddb 100644--- a/app/src/main/java/dev/emanuele/spot/ui/MainViewModel.kt+++ b/app/src/main/java/dev/emanuele/spot/ui/MainViewModel.kt@@ -584,6 +584,11 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {/** Playlists in the order this device last opened them; see [PlaylistOrderStore]. */val playlistOrder: StateFlow<List<String>> get() = container.playlistOrder.order+ /** How the detail screen sorts its tracks; remembered between visits. */+ val trackSort: StateFlow<String?> get() = container.preferences.trackSort++ fun setTrackSort(value: String) = container.preferences.setTrackSort(value)+/*** Loads a playlist's tracks.*diff --git a/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt b/app/src/main/java/dev/emanuele/spot/ui/SpotApp.ktindex 85b265e..eab05b7 100644--- a/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt+++ b/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt@@ -79,6 +79,7 @@ import dev.emanuele.spot.ui.home.HomeScreenimport dev.emanuele.spot.ui.library.LibraryScreenimport dev.emanuele.spot.ui.library.PlaylistScreenimport dev.emanuele.spot.ui.player.GlassFilm+import dev.emanuele.spot.ui.player.AddToPlaylistSheetimport dev.emanuele.spot.ui.player.MiniPlayerimport dev.emanuele.spot.ui.player.MiniPlayerHeightimport dev.emanuele.spot.ui.player.NowPlayingSheet@@ -156,6 +157,7 @@ fun SpotApp(val playlistOrder by viewModel.playlistOrder.collectAsStateWithLifecycle()val devices by viewModel.devices.collectAsStateWithLifecycle()val addToPlaylist by viewModel.addToPlaylist.collectAsStateWithLifecycle()+ val trackSort by viewModel.trackSort.collectAsStateWithLifecycle()// 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@@ -362,7 +364,11 @@ fun SpotApp(player?.shuffleModeEnabled = trueonPlay(tracks, 0)},- backdrop = artBackdrop,+ onAddToPlaylist = { track ->+ viewModel.openAddToPlaylist(track.uri, track.name)+ },+ storedSort = trackSort,+ onSortChange = viewModel::setTrackSort,onOpenItem = { item ->viewModel.openContext(item.uri,@@ -471,16 +477,25 @@ fun SpotApp(onCloseDevices = viewModel::closeDevices,onRefreshDevices = viewModel::refreshDevices,onSelectDevice = { viewModel.transferPlayback(it) },- addToPlaylist = addToPlaylist,onAddToPlaylist = {viewModel.openAddToPlaylist(playback.mediaId, playback.title)},- onPickPlaylist = viewModel::addToPlaylist,- onCloseAddToPlaylist = viewModel::closeAddToPlaylist,)},)}++ // 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.+ if (addToPlaylist.open) {+ AddToPlaylistSheet(+ state = addToPlaylist,+ backdrop = pageBackdrop,+ onSelect = viewModel::addToPlaylist,+ onDismiss = viewModel::closeAddToPlaylist,+ )+ }}}}diff --git a/app/src/main/java/dev/emanuele/spot/ui/components/ScrollBar.kt b/app/src/main/java/dev/emanuele/spot/ui/components/ScrollBar.ktindex 99be1e6..628f9cd 100644--- a/app/src/main/java/dev/emanuele/spot/ui/components/ScrollBar.kt+++ b/app/src/main/java/dev/emanuele/spot/ui/components/ScrollBar.kt@@ -52,6 +52,15 @@ fun LazyScrollBar(modifier: Modifier = Modifier,/** Below this many rows the list is short enough to scroll by hand. */minItems: Int = 40,+ /**+ * Content type of the first row the bar should span from.+ *+ * The detail screen opens on a full-bleed cover, and a bar running up the+ * side of the artwork is a scrollbar over a picture. With this set it starts+ * where the tracks start and grows into the full height as the cover scrolls+ * away.+ */+ startAfter: Any? = null,thumbHeight: Dp = 52.dp,color: Color = Color.White.copy(alpha = 0.55f),) {@@ -103,7 +112,9 @@ fun LazyScrollBar(// thumb without recomposing the list it is drawn over..graphicsLayer {this.alpha = alpha- translationY = (trackPx - thumbPx) * state.progress()+ val top = state.topOffsetFor(startAfter)+ translationY = top + (trackPx - top - thumbPx).coerceAtLeast(0f) *+ state.progress()}.clip(RoundedCornerShape(50)).background(color),@@ -111,6 +122,19 @@ fun LazyScrollBar(}}+/**+ * Where the run of rows begins on screen, in pixels from the top of the bar.+ *+ * Zero once whatever precedes them has been scrolled off, which is what makes+ * the bar grow to the full height rather than jump.+ */+private fun LazyListState.topOffsetFor(contentType: Any?): Float {+ if (contentType == null) return 0f+ val first = layoutInfo.visibleItemsInfo.firstOrNull { it.contentType == contentType }+ ?: return 0f+ return first.offset.toFloat().coerceAtLeast(0f)+}+/** How far down the list is, 0 to 1, counted in items. */private fun LazyListState.progress(): Float {val info = layoutInfodiff --git a/app/src/main/java/dev/emanuele/spot/ui/library/PlaylistScreen.kt b/app/src/main/java/dev/emanuele/spot/ui/library/PlaylistScreen.ktindex eadf049..74316a9 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@@ -42,6 +42,8 @@ import androidx.compose.ui.draw.clipimport androidx.compose.ui.graphics.Brushimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.graphics.lerp+import androidx.compose.ui.platform.LocalClipboardManager+import androidx.compose.ui.text.AnnotatedStringimport androidx.compose.ui.text.font.FontWeightimport androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.text.style.TextOverflow@@ -49,6 +51,8 @@ import androidx.compose.ui.unit.dpimport dev.emanuele.spot.data.CatalogTrackimport dev.emanuele.spot.ui.MainViewModelimport com.kyant.backdrop.Backdrop+import com.kyant.backdrop.backdrops.layerBackdrop+import com.kyant.backdrop.backdrops.rememberLayerBackdropimport dev.emanuele.spot.ui.components.Artworkimport dev.emanuele.spot.ui.components.LazyScrollBarimport dev.emanuele.spot.ui.components.SwipeToQueue@@ -67,6 +71,9 @@ import com.adamglin.phosphoricons.regular.ArrowLeftimport com.adamglin.phosphoricons.regular.ArrowsDownUpimport com.adamglin.phosphoricons.regular.Checkimport com.adamglin.phosphoricons.regular.DotsThree+import com.adamglin.phosphoricons.regular.LinkSimple+import com.adamglin.phosphoricons.regular.Plus+import com.adamglin.phosphoricons.regular.Queueimport com.adamglin.phosphoricons.regular.Shuffleimport com.adamglin.phosphoricons.regular.X@@ -88,12 +95,23 @@ fun PlaylistScreen(onPlay: (List<CatalogTrack>, Int) -> Unit,onEnqueue: (CatalogTrack) -> Unit,onShuffle: (List<CatalogTrack>) -> Unit,- backdrop: Backdrop,+ /** Opens the app-wide "add to playlist" sheet for one track. */+ onAddToPlaylist: (CatalogTrack) -> Unit,onOpenItem: (dev.emanuele.spot.data.SearchItem) -> Unit = {},+ /** The remembered track order, and where a change to it is stored. */+ storedSort: String? = null,+ onSortChange: (String) -> Unit = {},) {var query by remember { mutableStateOf("") }var searching by remember { mutableStateOf(false) }- var sort by remember { mutableStateOf(TrackSort.ORIGINAL) }+ // Seeded from the stored choice and written back on change: picking an+ // order and finding it gone on the next playlist is the kind of thing that+ // makes a setting feel like it did not take.+ var sort by remember(storedSort) {+ mutableStateOf(+ TrackSort.entries.firstOrNull { it.name == storedSort } ?: TrackSort.ORIGINAL,+ )+ }var sortOpen by remember { mutableStateOf(false) }// Derived, not stored: keeping a second list in state would leave the two@@ -110,9 +128,18 @@ fun PlaylistScreen(val accent by rememberArtworkColor(state.artworkUrl)val pageColor = remember(accent) { pageColorFor(accent) }+ // What the glass on this screen refracts.+ //+ // Not the app's backdrop: that is the blurred cover of whatever is playing,+ // so the buttons here — back, play, shuffle, search — picked up the colour+ // of an unrelated track while the page around them was tinted from this+ // cover. Recording this screen instead makes them glass over *this* page.+ val pageBackdrop = rememberLayerBackdrop()+Box(Modifier.fillMaxSize()+ .layerBackdrop(pageBackdrop)// Opaque, so the app-wide blurred artwork of the playing track does// not show through and re-tint the page..background(@@ -145,7 +172,7 @@ fun PlaylistScreen(trackCount = state.tracks.size,totalMs = state.tracks.sumOf { it.durationMs },pageColor = pageColor,- backdrop = backdrop,+ backdrop = pageBackdrop,onPlay = { visible.takeIf { it.isNotEmpty() }?.let { onPlay(it, 0) } },onShuffle = { visible.takeIf { it.isNotEmpty() }?.let(onShuffle) },onToggleSearch = {@@ -173,7 +200,10 @@ fun PlaylistScreen(sort = sort,sortOpen = sortOpen,onSortOpen = { sortOpen = it },- onSort = { sort = it },+ onSort = {+ sort = it+ onSortChange(it.name)+ },)}@@ -240,6 +270,8 @@ fun PlaylistScreen(position = index + 1,isCurrent = track.uri == nowPlayingUri,onClick = { onPlay(visible, index) },+ onEnqueue = { onEnqueue(track) },+ onAddToPlaylist = { onAddToPlaylist(track) },)}}@@ -276,6 +308,7 @@ fun PlaylistScreen(LazyScrollBar(state = listState,+ startAfter = "track",modifier = Modifier.align(Alignment.CenterEnd).padding(@@ -288,7 +321,7 @@ fun PlaylistScreen(// picture stays uninterrupted.LiquidButton(onClick = onBack,- backdrop = backdrop,+ backdrop = pageBackdrop,modifier = Modifier.padding(top = contentPadding.calculateTopPadding() + 8.dp, start = 14.dp).align(Alignment.TopStart)@@ -579,7 +612,10 @@ private fun TrackRow(position: Int,isCurrent: Boolean,onClick: () -> Unit,+ onEnqueue: () -> Unit,+ onAddToPlaylist: () -> 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@@ -654,17 +690,77 @@ private fun TrackRow()}- Icon(- PhosphorIcons.Regular.DotsThree,- contentDescription = null,- tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.6f),- modifier = Modifier- .padding(start = 10.dp)- .size(18.dp),+ 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,+ onDismiss = { menuOpen = false },+ onPlay = onClick,+ onEnqueue = onEnqueue,+ onAddToPlaylist = onAddToPlaylist,+ )+ }+ }+}++/**+ * What can be done with one track, without leaving the list.+ *+ * Only actions this app can actually carry out: the queue and the playlists,+ * plus the link, since sharing a track is the one thing people leave a music+ * 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(+ expanded: Boolean,+ track: CatalogTrack,+ onDismiss: () -> Unit,+ onPlay: () -> Unit,+ onEnqueue: () -> Unit,+ onAddToPlaylist: () -> Unit,+) {+ val clipboard = LocalClipboardManager.current++ DropdownMenu(expanded = expanded, onDismissRequest = onDismiss) {+ DropdownMenuItem(+ text = { Text("Riproduci") },+ leadingIcon = { Icon(PhosphorIcons.Fill.Play, contentDescription = null) },+ onClick = { onDismiss(); onPlay() },+ )+ DropdownMenuItem(+ text = { Text("Aggiungi alla coda") },+ leadingIcon = { Icon(PhosphorIcons.Regular.Queue, contentDescription = null) },+ onClick = { onDismiss(); onEnqueue() },+ )+ DropdownMenuItem(+ text = { Text("Aggiungi a una playlist") },+ leadingIcon = { Icon(PhosphorIcons.Regular.Plus, contentDescription = null) },+ onClick = { onDismiss(); onAddToPlaylist() },+ )+ DropdownMenuItem(+ text = { Text("Copia link") },+ leadingIcon = { Icon(PhosphorIcons.Regular.LinkSimple, contentDescription = null) },+ onClick = {+ onDismiss()+ clipboard.setText(AnnotatedString(track.openLink()))+ },)}}+/** The web address for a track URI, which is what a share expects. */+private fun CatalogTrack.openLink(): String =+ "https://open.spotify.com/track/" + uri.substringAfterLast(':')+@Composableprivate fun StatusBox(content: @Composable () -> Unit) {Box(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.ktindex b56f4c6..2e2c8b9 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@@ -148,11 +148,14 @@ fun PlayerScreen(onCloseDevices: () -> Unit,onRefreshDevices: () -> Unit,onSelectDevice: (String) -> Unit,- /** The "add to playlist" sheet, and the button that opens it. */- addToPlaylist: MainViewModel.AddToPlaylistState,+ /**+ * Opens the "add to playlist" sheet.+ *+ * The sheet itself is drawn by the app rather than by this screen: the track+ * rows in the library open the same one, and two copies would be two states+ * of one thing.+ */onAddToPlaylist: () -> Unit,- onPickPlaylist: (dev.emanuele.spot.data.CatalogPlaylist) -> Unit,- onCloseAddToPlaylist: () -> Unit,) {var panel by remember { mutableStateOf(PlayerPanel.NONE) }@@ -500,15 +503,6 @@ fun PlayerScreen(// Over everything, including the transport: it is a modal choice, and// the controls underneath would be operating a device the user is in// the middle of changing.- if (addToPlaylist.open) {- AddToPlaylistSheet(- state = addToPlaylist,- backdrop = glassBackdrop,- onSelect = onPickPlaylist,- onDismiss = onCloseAddToPlaylist,- )- }-if (devices.open) {DevicePicker(state = devices,