Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
Heart and download mark on the song rows of Immersive playlists, albums and Liked Songs: a small heart before the more button for a liked song and the download badge before the artist, from the Classic list's own state (what Spotify last reported, the list's one check, the downloads on the phone) so a like or a finished download shows at once, with no request per row; songs downloaded through an extension show it too [skip ci]
kota-zo2dfee24dc7a3
diff --git a/base/app/src/main/java/com/music/spotui/di/LibraryState.kt b/base/app/src/main/java/com/music/spotui/di/LibraryState.ktindex ba3eaeee..3337ff88 100644--- a/base/app/src/main/java/com/music/spotui/di/LibraryState.kt+++ b/base/app/src/main/java/com/music/spotui/di/LibraryState.kt@@ -17,3 +17,12 @@ fun rememberSaved(uri: String, fallback: Boolean = false): Boolean {@Composablefun rememberTrackSaved(trackId: String): Boolean =if (trackId.isBlank()) false else rememberSaved("spotify:track:$trackId")++/**+ * Whether a track is liked, for a row of a list: what Spotify last reported ([SongPlayer.library], which a like+ * made anywhere moves at once), else the list's own batch check [known] (the uris it asked about in one go).+ */+fun trackSaved(trackId: String, known: Set<String>): Boolean {+ val uri = "spotify:track:$trackId"+ return SongPlayer.library[uri] ?: (uri in known)+}diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/components/ImmersiveRows.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/components/ImmersiveRows.ktindex 72d71dd4..f3d7fdc5 100644--- a/base/app/src/main/java/com/music/spotui/ui/immersive/components/ImmersiveRows.kt+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/components/ImmersiveRows.kt@@ -20,6 +20,7 @@ import androidx.compose.foundation.layout.sizeimport androidx.compose.foundation.layout.widthimport androidx.compose.foundation.shape.CircleShapeimport androidx.compose.material.icons.Icons+import androidx.compose.material.icons.rounded.Favoriteimport androidx.compose.material.icons.rounded.GraphicEqimport androidx.compose.material.icons.rounded.MoreVertimport androidx.compose.material.icons.rounded.PlayArrow@@ -43,6 +44,8 @@ import androidx.compose.ui.unit.Dpimport androidx.compose.ui.unit.dpimport app.myspoti.engine.Rimport com.music.spotui.data.entity.SongsModel+import com.music.spotui.data.offline.OfflineStatus+import com.music.spotui.ui.components.DownloadBadgeimport com.music.spotui.ui.immersive.Immersive/** The cover of a row, and the height that lines the rows up (4 dp above and below it make [Immersive.RowHeight]). */@@ -71,6 +74,8 @@ private val RowTitle = Immersive.Body.copy(fontWeight = FontWeight.Medium)* @param trackNumber shown in place of the cover, for an album's own listing.* @param showDuration the length at the end of the row.* @param showAlbum "artist · album" as the second line instead of just the artist.+ * @param liked the song is in Liked Songs: a small heart before the more button.+ * @param offline the song's download, as the Classic list shows it before the artist: nothing when it has none.*/@OptIn(ExperimentalFoundationApi::class)@Composable@@ -84,6 +89,8 @@ fun ImmersiveSongRow(trackNumber: Int? = null,showDuration: Boolean = false,showAlbum: Boolean = false,+ liked: Boolean = false,+ offline: OfflineStatus? = null,trailing: (@Composable () -> Unit)? = null,) {val titleColor by animateColorAsState(@@ -127,7 +134,20 @@ fun ImmersiveSongRow(gapAfterLeading = if (trackNumber == null) 14.dp else Immersive.Gutter,trailingText = if (showDuration && song.durationMs > 0) formatDuration(song.durationMs) else null,onMore = onMore,- trailing = trailing,+ subtitleLeading = if (offline != null) ({+ DownloadBadge(offline, size = 14.dp)+ Spacer(Modifier.width(6.dp))+ }) else null,+ trailing = if (liked) ({+ trailing?.invoke()+ Spacer(Modifier.width(8.dp))+ Icon(+ Icons.Rounded.Favorite,+ contentDescription = stringResource(R.string.liked_song),+ tint = Immersive.Accent,+ modifier = Modifier.size(18.dp),+ )+ }) else trailing,)}@@ -196,6 +216,7 @@ private fun RowScaffold(gapAfterLeading: Dp,trailingText: String?,onMore: (() -> Unit)?,+ subtitleLeading: (@Composable () -> Unit)? = null,trailing: (@Composable () -> Unit)? = null,) {val haptics = LocalHapticFeedback.current@@ -223,12 +244,15 @@ private fun RowScaffold(ImmersiveSongTitle(title = title, explicit = explicit, style = RowTitle, color = titleColor)if (subtitle.isNotBlank()) {Spacer(Modifier.height(2.dp))- Text(- text = subtitle,- style = Immersive.Subhead,- maxLines = 1,- overflow = TextOverflow.Ellipsis,- )+ Row(verticalAlignment = Alignment.CenterVertically) {+ subtitleLeading?.invoke()+ Text(+ text = subtitle,+ style = Immersive.Subhead,+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ )+ }}}trailing?.invoke()diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/screens/ImmersiveContextScreen.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/screens/ImmersiveContextScreen.ktindex 1f6c6e1c..dd678954 100644--- a/base/app/src/main/java/com/music/spotui/ui/immersive/screens/ImmersiveContextScreen.kt+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/screens/ImmersiveContextScreen.kt@@ -229,6 +229,7 @@ private fun ImmersiveContextContent(navController: NavController, vm: ContextVieval isLiked = p.type == "liked" || p.type == "liked-artist"val isThisContext = np.contextUri == p.uri || (isLiked && np.contextUri.contains(":collection"))val contextSaved by vm.contextSaved+ val savedTracks by vm.savedUrisval smart = SmartShuffle.on.value == p.urival tapper = rememberTrackTapper()@@ -516,6 +517,10 @@ private fun ImmersiveContextContent(navController: NavController, vm: ContextVietrackNumber = if (numbered) index + 1 else null,showDuration = numbered,showAlbum = !numbered,+ // As in the Classic list: the heart and the download of the song, from the same state+ // (what Spotify last reported, the list's one batch check, the downloads kept on the phone).+ liked = com.music.spotui.di.trackSaved(song.spotifyTrackId, savedTracks),+ offline = OfflineStore.statusOf(song.spotifyTrackId),// Collaborative: the small face of who added the song.trailing = vm.adders.value.let { a -> a["row:" + song.rowUid] ?: a["song:" + song.spotifyTrackId] }?.let { m ->{ com.music.spotui.ui.components.ProfileAvatar(m.imageUrl, m.name, 22.dp) }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.ktindex e0285bfc..dda79537 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@@ -984,7 +984,7 @@ private fun ContextContent(navController: NavController, vm: ContextViewModel, psong = song,showCover = p.type != "album",isCurrent = song.id == currentSongId,- saved = SongPlayer.library["spotify:track:${song.spotifyTrackId}"] ?: ("spotify:track:${song.spotifyTrackId}" in saved),+ saved = com.music.spotui.di.trackSaved(song.spotifyTrackId, saved),offline = com.music.spotui.data.offline.OfflineStore.statusOf(song.spotifyTrackId),addedBy = vm.adders.value.let { a -> a["row:" + song.rowUid] ?: a["song:" + song.spotifyTrackId] },onClick = { if (SmartShuffle.on.value == p.uri) vm.playSmart(p, song) else vm.play(p, song, sort) },