Skip to content

Native Android client for Spotify, built with Jetpack Compose

Player: the tappable artist names keep the line's own colour instead of the accent, a press underlines one

kota-zoa8b04cbea6b8
diff --git a/base/app/src/main/java/com/music/spotui/ui/components/ArtistChooser.kt b/base/app/src/main/java/com/music/spotui/ui/components/ArtistChooser.kt
index c3f7db6e..1acc9834 100644
--- a/base/app/src/main/java/com/music/spotui/ui/components/ArtistChooser.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/components/ArtistChooser.kt
@@ -141,13 +141,18 @@ fun ArtistChooserHost(navController: NavHostController) {
* credit): the line is then a plain text, opened as before.
*/
@Composable
-fun rememberArtistCredit(trackId: String, line: String, open: (ArtistRef) -> Unit): AnnotatedString? {
+fun rememberArtistCredit(trackId: String, line: String, color: androidx.compose.ui.graphics.Color, open: (ArtistRef) -> Unit): AnnotatedString? {
val artists by produceState<List<ArtistRef>?>(null, trackId) {
value = if (trackId.isBlank()) null else ArtistChooser.artistsOf(trackId, "").takeIf { list -> list.isNotEmpty() && list.all { it.uri.isNotBlank() } }
}
val onOpen by rememberUpdatedState(open)
- return remember(artists, line) {
+ return remember(artists, line, color) {
val list = artists ?: return@remember null
+ // The names keep the line's own colour (the theme would paint links in the accent); a press underlines one.
+ val styles = androidx.compose.ui.text.TextLinkStyles(
+ style = androidx.compose.ui.text.SpanStyle(color = color),
+ pressedStyle = androidx.compose.ui.text.SpanStyle(color = color, textDecoration = androidx.compose.ui.text.style.TextDecoration.Underline),
+ )
// Each name, in order, with only separators between them.
var at = 0
val starts = IntArray(list.size)
@@ -162,7 +167,7 @@ fun rememberArtistCredit(trackId: String, line: String, open: (ArtistRef) -> Uni
var last = 0
for ((i, a) in list.withIndex()) {
append(line.substring(last, starts[i]))
- withLink(LinkAnnotation.Clickable("artist", null) { onOpen(a) }) { append(a.name) }
+ withLink(LinkAnnotation.Clickable("artist", styles) { onOpen(a) }) { append(a.name) }
last = starts[i] + a.name.length
}
append(line.substring(last))
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersivePlayer.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersivePlayer.kt
index f292a0fd..922cae2b 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersivePlayer.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersivePlayer.kt
@@ -486,7 +486,7 @@ private fun RowScope.PlayerCredits(
}
if (!state.adPlaying) {
// One tap per artist when the song's artists are known; the whole line otherwise.
- val credit = com.music.spotui.ui.components.rememberArtistCredit(state.trackId, state.artist) { a -> actions.openArtistRef(a) }
+ val credit = com.music.spotui.ui.components.rememberArtistCredit(state.trackId, state.artist, tint.copy(alpha = 0.55f)) { a -> actions.openArtistRef(a) }
Text(
text = credit ?: androidx.compose.ui.text.AnnotatedString(state.artist),
style = Immersive.Title.copy(fontSize = 20.sp, lineHeight = lineH, fontWeight = FontWeight.W500),
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt
index 6b45d3cb..f80b6fda 100644
--- a/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/screens/PlayerScreen.kt
@@ -645,7 +645,7 @@ fun PlayerScreen(navController: NavController) {
}
},
// One tap per artist: each name opens that artist, not the choice.
- artistCredit = com.music.spotui.ui.components.rememberArtistCredit(displayedTrackId, outgoing?.artist ?: songSinger) { a ->
+ artistCredit = com.music.spotui.ui.components.rememberArtistCredit(displayedTrackId, outgoing?.artist ?: songSinger, Color.White.copy(alpha = 0.7f)) { a ->
navController.navigate(com.music.spotui.ui.components.ArtistChooser.routeOf(a))
},
)