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
Send each credited artist to their own page
Lelonio70f95b663b2d
diff --git a/app/src/main/java/dev/lelonio/square/data/Catalog.kt b/app/src/main/java/dev/lelonio/square/data/Catalog.ktindex 325201e..c3f18aa 100644--- a/app/src/main/java/dev/lelonio/square/data/Catalog.kt+++ b/app/src/main/java/dev/lelonio/square/data/Catalog.kt@@ -25,6 +25,13 @@ data class CatalogTrack(val artist: String,/** The first artist's own uri, when the source gives one; see catalog.rs. */val artistUri: String? = null,+ /**+ * Every artist credited, named and addressed.+ *+ * [artist] is these names run together for the places that show one line;+ * this is what makes each of them its own way into the app.+ */+ val artists: List<CatalogArtist> = emptyList(),val album: String = "",val durationMs: Long = 0,val explicit: Boolean = false,@@ -66,12 +73,17 @@ data class CatalogPlaylist(val artworkUrl: String? = null,)+/** One credited artist: what to write, and where it leads. */+@Serializable+data class CatalogArtist(val name: String, val uri: String? = null)+/** Bridges a Web API track into the model the UI and the queue already use. */fun TrackDto.toCatalogTrack(addedAt: String? = null): CatalogTrack = CatalogTrack(uri = uri,name = name,artist = artists.joinToString(", ") { it.name },artistUri = artists.firstOrNull()?.uri,+ artists = artists.map { CatalogArtist(it.name, it.uri) },album = album?.name.orEmpty(),durationMs = durationMs,explicit = explicit,diff --git a/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt b/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.ktindex 85b94b1..0103604 100644--- a/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt+++ b/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt@@ -1087,6 +1087,17 @@ class LibrespotPlayer(track.artistUri?.let {putString(dev.lelonio.square.ui.EXTRA_ARTIST_URI, it)}+ val credited = track.artists.filter { it.uri != null }+ if (credited.isNotEmpty()) {+ putStringArrayList(+ dev.lelonio.square.ui.EXTRA_ARTIST_NAMES,+ ArrayList(credited.map { it.name }),+ )+ putStringArrayList(+ dev.lelonio.square.ui.EXTRA_ARTIST_URIS,+ ArrayList(credited.map { it.uri!! }),+ )+ }},).build(),diff --git a/app/src/main/java/dev/lelonio/square/playback/PlayQueue.kt b/app/src/main/java/dev/lelonio/square/playback/PlayQueue.ktindex c9755d4..56d4d07 100644--- a/app/src/main/java/dev/lelonio/square/playback/PlayQueue.kt+++ b/app/src/main/java/dev/lelonio/square/playback/PlayQueue.kt@@ -30,6 +30,8 @@ class PlayQueue {val artist: String,/** The first artist's uri, when it is known; see EXTRA_ARTIST_URI. */val artistUri: String? = null,+ /** Every credited artist with a page of their own, in credit order. */+ val artists: List<dev.lelonio.square.data.CatalogArtist> = emptyList(),val durationMs: Long,val artworkUri: Uri?,/**@@ -286,6 +288,16 @@ class PlayQueue {else add(index, tracks)}+ /** The two parallel lists put back together; see EXTRA_ARTIST_NAMES. */+ private fun creditedArtists(+ extras: android.os.Bundle?,+ ): List<dev.lelonio.square.data.CatalogArtist> {+ val names = extras?.getStringArrayList(dev.lelonio.square.ui.EXTRA_ARTIST_NAMES)+ val uris = extras?.getStringArrayList(dev.lelonio.square.ui.EXTRA_ARTIST_URIS)+ if (names == null || uris == null) return emptyList()+ return names.zip(uris) { name, uri -> dev.lelonio.square.data.CatalogArtist(name, uri) }+ }+private fun toTrack(item: MediaItem): Track? {val uri = item.mediaId.takeIf { it.startsWith("spotify:") } ?: return nullval metadata = item.mediaMetadata@@ -294,6 +306,7 @@ class PlayQueue {title = metadata.title?.toString().orEmpty(),artist = metadata.artist?.toString().orEmpty(),artistUri = metadata.extras?.getString(dev.lelonio.square.ui.EXTRA_ARTIST_URI),+ artists = creditedArtists(metadata.extras),durationMs = metadata.durationMs ?: 0L,artworkUri = metadata.artworkUri,queued = metadata.extras?.getBoolean(EXTRA_PLAY_NEXT) == true,diff --git a/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt b/app/src/main/java/dev/lelonio/square/playback/PlaybackService.ktindex e9d5905..6d1950f 100644--- a/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt+++ b/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt@@ -697,6 +697,7 @@ class PlaybackService : MediaLibraryService() {// artist page a row opens is its own.artistUri = metadata.extras?.getString(dev.lelonio.square.ui.EXTRA_ARTIST_URI),+ artists = creditedArtists(metadata.extras),durationMs = metadata.durationMs ?: 0L,artworkUrl = metadata.artworkUri?.toString(),)@@ -749,6 +750,17 @@ class PlaybackService : MediaLibraryService() {track.artistUri?.let {putString(dev.lelonio.square.ui.EXTRA_ARTIST_URI, it)}+ val credited = track.artists.filter { it.uri != null }+ if (credited.isNotEmpty()) {+ putStringArrayList(+ dev.lelonio.square.ui.EXTRA_ARTIST_NAMES,+ ArrayList(credited.map { it.name }),+ )+ putStringArrayList(+ dev.lelonio.square.ui.EXTRA_ARTIST_URIS,+ ArrayList(credited.map { it.uri!! }),+ )+ }saved.contextUri?.let {putString(dev.lelonio.square.ui.EXTRA_CONTEXT_URI, it)}@@ -779,6 +791,7 @@ class PlaybackService : MediaLibraryService() {name = track.title,artist = track.artist,artistUri = track.artistUri,+ artists = track.artists,durationMs = track.durationMs,artworkUrl = track.artworkUri?.toString(),)@@ -788,10 +801,21 @@ class PlaybackService : MediaLibraryService() {title = track.name,artist = track.artist,artistUri = track.artistUri,+ artists = track.artists,durationMs = track.durationMs,artworkUri = track.artworkUrl?.let(android.net.Uri::parse),)+ /** The two parallel lists put back together; see EXTRA_ARTIST_NAMES. */+ private fun creditedArtists(+ extras: android.os.Bundle?,+ ): List<dev.lelonio.square.data.CatalogArtist> {+ val names = extras?.getStringArrayList(dev.lelonio.square.ui.EXTRA_ARTIST_NAMES)+ val uris = extras?.getStringArrayList(dev.lelonio.square.ui.EXTRA_ARTIST_URIS)+ if (names == null || uris == null) return emptyList()+ return names.zip(uris) { name, uri -> dev.lelonio.square.data.CatalogArtist(name, uri) }+ }+override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaLibrarySession? =sessiondiff --git a/app/src/main/java/dev/lelonio/square/ui/MainActivity.kt b/app/src/main/java/dev/lelonio/square/ui/MainActivity.ktindex e30d75c..165df56 100644--- a/app/src/main/java/dev/lelonio/square/ui/MainActivity.kt+++ b/app/src/main/java/dev/lelonio/square/ui/MainActivity.kt@@ -224,6 +224,19 @@ class MainActivity : ComponentActivity() {// So the artist's name in the player is a way to// reach them, rather than a caption.track.artistUri?.let { putString(EXTRA_ARTIST_URI, it) }+ // And each credited artist separately, so a track+ // by two people opens the one that was pressed.+ val credited = track.artists.filter { it.uri != null }+ if (credited.isNotEmpty()) {+ putStringArrayList(+ EXTRA_ARTIST_NAMES,+ ArrayList(credited.map { it.name }),+ )+ putStringArrayList(+ EXTRA_ARTIST_URIS,+ ArrayList(credited.map { it.uri!! }),+ )+ }if (playNext) putBoolean(EXTRA_PLAY_NEXT, true)},)@@ -249,3 +262,7 @@ const val EXTRA_CONTEXT_LABEL = "dev.lelonio.square.CONTEXT_LABEL"/** The first artist's own uri, so the player's second line can be opened. */const val EXTRA_ARTIST_URI = "dev.lelonio.square.ARTIST_URI"++/** Every credited artist, in order, as two lists that line up. */+const val EXTRA_ARTIST_NAMES = "dev.lelonio.square.ARTIST_NAMES"+const val EXTRA_ARTIST_URIS = "dev.lelonio.square.ARTIST_URIS"diff --git a/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt b/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.ktindex 626ce72..fa28543 100644--- a/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt+++ b/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt@@ -16,6 +16,7 @@ import androidx.compose.animation.core.springimport androidx.compose.animation.core.animateDpAsStateimport androidx.compose.animation.core.tweenimport androidx.compose.foundation.background+import androidx.compose.foundation.gestures.detectTapGesturesimport androidx.compose.foundation.verticalScrollimport androidx.compose.foundation.rememberScrollStateimport androidx.compose.foundation.clickable@@ -62,7 +63,9 @@ import androidx.compose.ui.draw.drawWithContentimport androidx.compose.ui.graphics.Brushimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.graphics.graphicsLayer+import androidx.compose.ui.input.pointer.pointerInputimport androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.text.TextLayoutResultimport androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.text.style.TextOverflowimport androidx.compose.ui.unit.Dp@@ -614,11 +617,9 @@ fun PlayerScreen(TitleBlock(state,Modifier.weight(1f),- onOpenArtist = {- state.artistUri?.let { uri ->- onCollapse()- onOpenUri(uri, state.artist)- }+ onOpenArtist = { uri, name ->+ onCollapse()+ onOpenUri(uri, name)},)// The queue's one control. It is a sheet that@@ -1070,7 +1071,7 @@ private fun Cover(private fun TitleBlock(state: PlaybackState,modifier: Modifier = Modifier,- onOpenArtist: () -> Unit = {},+ onOpenArtist: (uri: String, name: String) -> Unit = { _, _ -> },) {// Slid rather than swapped on a track change: this capsule is the only place// the track is named now that the big cover is gone, so the change has to be@@ -1091,26 +1092,68 @@ private fun TitleBlock(maxLines = 1,overflow = TextOverflow.Ellipsis,)- // Tappable only when there is somewhere to go: a queue built from- // search results, or a track another device is playing, names an- // artist this app has no page for, and a line that looks like a- // link and does nothing is worse than plain text.- Text(- text = artist,- style = MaterialTheme.typography.bodyMedium,- color = GlassInkDim,- maxLines = 1,- overflow = TextOverflow.Ellipsis,- modifier = if (state.artistUri != null) {- Modifier.plainClickable(onOpenArtist)- } else {- Modifier- },- )+ ArtistLine(state, artist, onOpenArtist)}}}+/**+ * The line under the title: who made this, and a way to each of them.+ *+ * "Pyrex, Sfera Ebbasta" is two artists and two pages, so the whole line+ * cannot lead to one of them. Where the finger landed is turned into a+ * character offset and matched against the span each name occupies, which is+ * what makes the second name reach the second artist.+ *+ * Plain text when there is nowhere to go: a queue built from search results, or+ * a track another device is playing, names an artist this app has no page for,+ * and a line that looks like a link and does nothing is worse than a caption.+ */+@Composable+private fun ArtistLine(+ state: PlaybackState,+ artist: String,+ onOpenArtist: (uri: String, name: String) -> Unit,+) {+ val credits = state.artists+ // The names as written, so the spans below line up with what is drawn.+ val label = if (credits.isEmpty()) artist else credits.joinToString(", ") { it.name }++ var layout by remember(label) { mutableStateOf<TextLayoutResult?>(null) }+ val openable = credits.any { it.uri != null } || state.artistUri != null++ Text(+ text = label,+ style = MaterialTheme.typography.bodyMedium,+ color = GlassInkDim,+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ onTextLayout = { layout = it },+ modifier = if (!openable) {+ Modifier+ } else {+ Modifier.pointerInput(credits, label) {+ detectTapGestures { position ->+ val offset = layout?.getOffsetForPosition(position)+ val hit = offset?.let { at ->+ var start = 0+ credits.firstOrNull { credit ->+ val end = start + credit.name.length+ val contains = at in start..end+ start = end + 2+ contains+ }+ }+ // Anywhere else on the line, and any track that named only+ // one artist, goes to the first.+ val uri = hit?.uri ?: state.artistUri ?: return@detectTapGestures+ onOpenArtist(uri, hit?.name ?: artist)+ }+ }+ },+ )+}+/*** A tap with no ripple behind it.*diff --git a/app/src/main/java/dev/lelonio/square/ui/player/PlayerState.kt b/app/src/main/java/dev/lelonio/square/ui/player/PlayerState.ktindex 04c514e..78454d7 100644--- a/app/src/main/java/dev/lelonio/square/ui/player/PlayerState.kt+++ b/app/src/main/java/dev/lelonio/square/ui/player/PlayerState.kt@@ -54,6 +54,11 @@ data class PlaybackState(* The labels are then plain text, which is what they have always been.*/val artistUri: String? = null,+ /**+ * Each credited artist separately, so a line naming two of them opens the+ * one that was pressed. Empty when the source gave only the joined names.+ */+ val artists: List<dev.lelonio.square.data.CatalogArtist> = emptyList(),val contextUri: String? = null,)@@ -176,6 +181,19 @@ fun rememberPlaybackState(pitch = player.playbackParameters.pitch,source = metadata.extras?.getString(EXTRA_CONTEXT_LABEL).orEmpty(),artistUri = metadata.extras?.getString(dev.lelonio.square.ui.EXTRA_ARTIST_URI),+ artists = run {+ val names = metadata.extras+ ?.getStringArrayList(dev.lelonio.square.ui.EXTRA_ARTIST_NAMES)+ val uris = metadata.extras+ ?.getStringArrayList(dev.lelonio.square.ui.EXTRA_ARTIST_URIS)+ if (names == null || uris == null) {+ emptyList()+ } else {+ names.zip(uris) { name, uri ->+ dev.lelonio.square.data.CatalogArtist(name, uri)+ }+ }+ },contextUri = metadata.extras?.getString(dev.lelonio.square.ui.EXTRA_CONTEXT_URI),)if (next.hasItem) {diff --git a/native/src/catalog.rs b/native/src/catalog.rsindex df30ffd..5b4fbda 100644--- a/native/src/catalog.rs+++ b/native/src/catalog.rs@@ -263,13 +263,18 @@ fn track_json(track: &Track) -> Value {.map(|a| a.name.as_str()).collect::<Vec<_>>().join(", "),- // The first artist's own uri, so a name on screen can be tapped. The- // first rather than all of them: a track credited to three people has- // one page a listener means when they press the line.+ // The first artist's own uri, kept for everything that shows one name."artistUri": track.artists.first().and_then(|a| a.id.to_uri().ok()),+ // And all of them, named and addressed, because a track credited to two+ // people has two pages and the listener presses the one they mean.+ "artists": track+ .artists+ .iter()+ .map(|a| json!({ "name": a.name, "uri": a.id.to_uri().ok() }))+ .collect::<Vec<_>>(),"album": track.album.name,"durationMs": track.duration,"explicit": track.is_explicit,