Skip to content

Native Android client for Spotify, built with Jetpack Compose

Artist's liked songs open their own page, played inside Liked Songs in that list's order

kota-zo789dfbe8ffdd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index daea87f6..f3b9e25f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,7 +20,7 @@ Each release on GitHub shows its section below. The app shows it too when it off
- **Cover back to its full size** in the player.
- **Myspoti's buttons play on this phone again** when another device (the Spotify app on the same account, for instance) took playback without being picked in Myspoti: the music comes back here first, instead of driving that device (where skips, previous and volume were refused).
- **Faster artist pages and playlists**: an artist seen in the last minutes opens at once (and its releases page too), the discography and a playlist's first songs are asked for together with the page, and your liked songs load once per session instead of on every artist page.
-- **Your liked songs by an artist** come first on its page, above the popular tracks.
+- **Your liked songs by an artist** come first on its page, above the popular tracks, and open their own page (as in Spotify), where play and shuffle play only them.
- **New languages**: German, Spanish, Portuguese and Greek, on every screen.
- **Music no longer stops for a minute**: a Web Player page that stops answering is reloaded at once, and playback goes on.
- **No more silent songs**: the sound comes back by itself if a skip or a muted ad left it at zero; after a skip it comes back as soon as the next song is there.
diff --git a/base/app/src/main/java/com/music/spotui/data/api/Api.kt b/base/app/src/main/java/com/music/spotui/data/api/Api.kt
index d01106c6..94d3a272 100644
--- a/base/app/src/main/java/com/music/spotui/data/api/Api.kt
+++ b/base/app/src/main/java/com/music/spotui/data/api/Api.kt
@@ -533,6 +533,31 @@ class Api constructor(
return pickAlbum(hits, albumName, artist)?.uri?.substringAfterLast(':')
}
+ /**
+ * The user's liked songs by one artist, as their own page (Spotify's "Liked Songs" row on an
+ * artist page). They play inside Liked Songs, in this list's order, so only they play.
+ */
+ suspend fun getLikedByArtistPage(artistId: String, artistName: String): Flow<Response<ContextPageModel>> = flow {
+ emit(Response.Loading())
+ val all = LikedCache.tracks ?: LikedCache.loadOnce().await()
+ ?: run { emit(Response.Error(context.getString(R.string.page_load_failed))); return@flow }
+ val songs = all.filter { s ->
+ if (s.artistIds.isNotEmpty()) artistId in s.artistIds
+ else artistName.isNotBlank() && s.singer.split(", ").any { it.equals(artistName, ignoreCase = true) }
+ }
+ emit(Response.Success(ContextPageModel(
+ uri = "spotify:collection:tracks",
+ type = "liked-artist",
+ name = context.getString(R.string.artist_liked_songs),
+ coverUri = "",
+ ownerName = ProfileCache.name.orEmpty(),
+ ownerAvatar = ProfileCache.imageUrl.orEmpty(),
+ metaLine = context.resources.getQuantityString(R.plurals.artist_liked_songs_count, songs.size, songs.size, artistName),
+ tracks = songs,
+ complete = true,
+ )))
+ }
+
/** Liked Songs as a page: cached list shown instantly, then refreshed page by page. */
suspend fun getLikedPage(): Flow<Response<ContextPageModel>> = flow {
fun page(tracks: List<SongsModel>, complete: Boolean) = ContextPageModel(
diff --git a/base/app/src/main/java/com/music/spotui/ui/navigation/MyNavHost.kt b/base/app/src/main/java/com/music/spotui/ui/navigation/MyNavHost.kt
index 5a41ac53..6e6178d6 100644
--- a/base/app/src/main/java/com/music/spotui/ui/navigation/MyNavHost.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/navigation/MyNavHost.kt
@@ -237,6 +237,14 @@ fun MyNavHost(
uId?.let { com.music.spotui.ui.screens.ProfileScreen(navHostController, userId = it, userName = name) }
}
+ page("$LIKED_BY_ARTIST_ROUTE/{key}") { navBackStackEntry ->
+ LaunchedEffect(playerState) {
+ bottomBarState.value = true
+ bottomBarPlayerState.value = playerState != ""
+ }
+ navBackStackEntry.arguments?.getString("key")?.let { ContextScreen(navHostController, type = "liked-artist", id = it) }
+ }
+
page(
"${com.music.spotui.ui.screens.FOLLOW_LIST_ROUTE}/{uId}/{mode}",
) { navBackStackEntry ->
diff --git a/base/app/src/main/java/com/music/spotui/ui/navigation/Routes.kt b/base/app/src/main/java/com/music/spotui/ui/navigation/Routes.kt
index 72ad1457..fb3e5383 100644
--- a/base/app/src/main/java/com/music/spotui/ui/navigation/Routes.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/navigation/Routes.kt
@@ -42,6 +42,11 @@ fun profileRoute(userId: String, name: String = ""): String =
fun categoryRoute(genre: String, title: String): String =
"${Routes.Category.route}/${android.net.Uri.encode(genre)}?title=${android.net.Uri.encode(title)}"
+/** An artist's liked songs, their own page (see Api.getLikedByArtistPage). */
+const val LIKED_BY_ARTIST_ROUTE = "liked_by_artist"
+fun likedByArtistRoute(artistId: String, artistName: String): String =
+ "$LIKED_BY_ARTIST_ROUTE/${android.net.Uri.encode("$artistId|$artistName")}"
+
/** Builds a playlist route carrying the Spotify playlist id (and a display name). */
fun playlistRoute(id: String, name: String = ""): String =
"${Routes.Playlist.route}/${android.net.Uri.encode(id)}?name=${android.net.Uri.encode(name)}"
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/ArtistScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/ArtistScreen.kt
index 88e26911..18c4ff4e 100644
--- a/base/app/src/main/java/com/music/spotui/ui/screens/ArtistScreen.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/screens/ArtistScreen.kt
@@ -154,7 +154,6 @@ private fun ArtistOverviewContent(
var showAllPopular by remember { mutableStateOf(false) }
// The user's liked songs by this artist: from the session cache, else loaded once in the background.
var likedByArtist by remember(overview.id) { mutableStateOf<List<com.music.spotui.data.entity.SongsModel>>(emptyList()) }
- var showLiked by remember(overview.id) { mutableStateOf(false) }
LaunchedEffect(overview.id) {
// Loaded once per session, shared by every artist page, after this page is shown.
val all = com.music.spotui.data.api.Api.LikedCache.tracks
@@ -358,7 +357,9 @@ private fun ArtistOverviewContent(
item(key = "liked-by-artist") {
Row(
verticalAlignment = Alignment.CenterVertically,
- modifier = Modifier.fillMaxWidth().clickable { showLiked = !showLiked }.padding(16.dp, 8.dp),
+ modifier = Modifier.fillMaxWidth()
+ .clickable { navController.navigate(com.music.spotui.ui.navigation.likedByArtistRoute(overview.id, displayName)) }
+ .padding(16.dp, 8.dp),
) {
Box(
contentAlignment = Alignment.Center,
@@ -377,26 +378,6 @@ private fun ArtistOverviewContent(
}
}
}
- if (showLiked) itemsIndexed(likedByArtist, key = { i, s -> "liked:$i:${s.id}" }) { _, song ->
- Row(
- verticalAlignment = Alignment.CenterVertically,
- modifier = Modifier.fillMaxWidth()
- .clickable {
- SongPlayer.registerLikedSongs(com.music.spotui.data.api.Api.LikedCache.tracks.orEmpty().map { it.url })
- artistViewModel.updateQueue(likedByArtist)
- SongPlayer.playSong(song.url, context, contextUri = "spotify:collection:tracks")
- artistViewModel.updateSongState(song.coverUri, song.title, song.singer, true, song.id, 0, song.album)
- }
- .padding(16.dp, 8.dp),
- ) {
- GlideImage(model = song.coverUri, contentDescription = "", contentScale = ContentScale.Crop, modifier = Modifier.size(44.dp))
- Spacer(Modifier.width(12.dp))
- Column(Modifier.weight(1f)) {
- Text(song.title, color = Color.White, fontSize = 15.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
- Text(song.album, color = Color.White.copy(alpha = 0.7f), fontSize = 13.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
- }
- }
- }
}
// ── Popular tracks ──
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/ContextScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/ContextScreen.kt
index cf955b87..34968b58 100644
--- a/base/app/src/main/java/com/music/spotui/ui/screens/ContextScreen.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/screens/ContextScreen.kt
@@ -186,6 +186,8 @@ class ContextViewModel(
val flow = when (type) {
"album" -> api.getAlbumPage(id)
"liked" -> api.getLikedPage()
+ // id: "<artist id>|<artist name>"
+ "liked-artist" -> api.getLikedByArtistPage(id.substringBefore('|'), id.substringAfter('|', ""))
else -> api.getPlaylistPage(id)
}
// Liked Songs: a like or unlike anywhere puts the list right at once.
@@ -259,9 +261,10 @@ class ContextViewModel(
return
}
state.updateQueue(p.tracks)
- if (p.type == "liked") SongPlayer.registerLikedSongs(p.tracks.map { it.url })
- // Sorted by the user: Spotify plays the list in that order, not the playlist's.
- val order = if (sort.isCustom) null else sort.apply(p.tracks).map { "spotify:track:${it.spotifyTrackId}" }
+ if (p.type == "liked" || p.type == "liked-artist") SongPlayer.registerLikedSongs(p.tracks.map { it.url })
+ // Sorted by the user: Spotify plays the list in that order, not the playlist's. An
+ // artist's liked songs are a part of Liked Songs: always given, so only they play.
+ val order = if (sort.isCustom && p.type != "liked-artist") null else sort.apply(p.tracks).map { "spotify:track:${it.spotifyTrackId}" }
if (order != null) state.updateQueue(sort.apply(p.tracks))
SongPlayer.playSong(song.url, contextUri = p.uri, order = order)
state.updateSongState(song.coverUri, song.title, song.singer, true, song.id, 0, song.album)
@@ -297,7 +300,7 @@ private fun ContextContent(navController: NavController, vm: ContextViewModel, p
val playing = playerVm.currentSongPlayingState.value
val shuffle = playerVm.shuffleState.value
val np by SongPlayer.nowPlaying
- val isThisContext = np.contextUri == p.uri || (p.type == "liked" && np.contextUri.contains(":collection"))
+ val isThisContext = np.contextUri == p.uri || ((p.type == "liked" || p.type == "liked-artist") && np.contextUri.contains(":collection"))
val saved by vm.savedUris
val contextSaved by vm.contextSaved
@@ -397,7 +400,7 @@ private fun ContextContent(navController: NavController, vm: ContextViewModel, p
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = stringResource(R.string.accessibility_navigate_back), tint = Color.White)
}
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxWidth()) {
- if (p.type == "liked") LikedCover(Modifier.fillMaxWidth(0.66f).aspectRatio(1f).shadow(16.dp, RoundedCornerShape(4.dp))) else
+ if (p.type == "liked" || p.type == "liked-artist") LikedCover(Modifier.fillMaxWidth(0.66f).aspectRatio(1f).shadow(16.dp, RoundedCornerShape(4.dp))) else
GlideImage(
model = p.coverUri,
contentDescription = "",