Skip to content

Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.

Word-level lyric highlight, list fade, chips follow the scroll

Lelonio33fb95f03b77
diff --git a/.claude/settings.local.json b/.claude/settings.local.json
index e3c0549..64c9652 100644
--- a/.claude/settings.local.json
+++ b/.claude/settings.local.json
@@ -62,7 +62,8 @@
"Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Rewrite the home page on the glass material *)",
"Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Home: profile header, recency-ordered playlists, plainer cards *)",
"Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Collapsing home header, sharper cards, library rewrite *)",
- "Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Lyrics centre stage over a blurred Canvas; fix the card blur artefact *)"
+ "Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Lyrics centre stage over a blurred Canvas; fix the card blur artefact *)",
+ "Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Word-level lyric highlight, list fade, chips follow the scroll *)"
]
}
}
diff --git a/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin b/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin
index 1e16389..74e2683 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 Logl
j
h/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/additional_project_files.txtC
A
-?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint  �����3  ����3i
+?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint  �Ӆ��3  ����3i
g
-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� ����3n
l
-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  �Ӆ��3d
b
-`/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 @ ����3e
c
-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�� ����3i
g
-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 �" ����3o
m
-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  ( ����3g
e
-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 ����3D
B
-@/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 file
diff --git a/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt b/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt
index 8c0c14a..baefc36 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt
@@ -469,9 +469,19 @@ private fun BottomBar(
// do something and come back — and giving it the same weight as Home and
// Library made all three read as places.
val routes = remember { listOf(Routes.HOME, Routes.LIBRARY) }
- // Falls back to Home rather than -1 while on a screen that is not a tab —
- // the playlist detail, say — so the indicator has somewhere to sit.
- val selected = routes.indexOf(route).coerceAtLeast(0)
+
+ // The last tab that was actually on screen, held across screens that are not
+ // tabs at all — a playlist, the search page.
+ //
+ // Falling back to Home instead, which is what this did, navigated the user
+ // away: the bar reports every change of its selected index through
+ // `onTabSelected`, so opening a playlist from Library moved the index 1 -> 0
+ // and the bar promptly "selected" Home. That was the playlist opening and
+ // then bouncing back.
+ var lastTab by remember { mutableStateOf(0) }
+ val routeIndex = routes.indexOf(route)
+ if (routeIndex >= 0 && routeIndex != lastTab) lastTab = routeIndex
+ val selected = if (routeIndex >= 0) routeIndex else lastTab
// A *stable* lambda, deliberately. LiquidBottomTabs keys its internal state
// on this reference, so a fresh closure on every recomposition threw that
diff --git a/app/src/main/java/dev/emanuele/spot/ui/home/HomeScreen.kt b/app/src/main/java/dev/emanuele/spot/ui/home/HomeScreen.kt
index c2ec679..0e72d22 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/home/HomeScreen.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/home/HomeScreen.kt
@@ -32,8 +32,11 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
+import androidx.compose.ui.draw.drawWithContent
+import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.CompositingStrategy
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.text.style.TextAlign
@@ -157,19 +160,50 @@ fun HomeScreen(
}
}
+ // Which section is being looked at, for the chips.
+ //
+ // Read from the item type rather than from an index: sections
+ // appear and disappear with the filter, so any arithmetic over
+ // positions would be wrong the moment one of them is empty.
+ val visibleSection by remember {
+ derivedStateOf {
+ listState.layoutInfo.visibleItemsInfo
+ .firstNotNullOfOrNull { info ->
+ Feed.entries.firstOrNull { it.name == info.contentType }
+ }
+ }
+ }
+
Column(Modifier.fillMaxSize()) {
Header(
name = state.displayName,
avatarUrl = state.avatarUrl,
collapse = collapse,
filter = filter,
+ highlighted = if (filter == Feed.ALL) visibleSection ?: Feed.ALL else filter,
backdrop = backdrop,
topPadding = contentPadding.calculateTopPadding(),
onFilter = { filter = it },
)
LazyColumn(
- Modifier.fillMaxSize(),
+ Modifier
+ .fillMaxSize()
+ // Fades the first rows out under the header instead of
+ // cutting them off square. DstIn needs a layer of its
+ // own, or the mask would erase the page behind the list
+ // as well.
+ .graphicsLayer(compositingStrategy = CompositingStrategy.Offscreen)
+ .drawWithContent {
+ drawContent()
+ drawRect(
+ brush = Brush.verticalGradient(
+ 0f to Color.Transparent,
+ FADE_FRACTION to Color.Black,
+ ),
+ blendMode = BlendMode.DstIn,
+ )
+ },
state = listState,
// The header already covers the status bar, so only the
// bottom inset is left for the list.
@@ -178,7 +212,7 @@ fun HomeScreen(
),
) {
if (showReleases && feed.newReleases.isNotEmpty()) {
- item(contentType = "heading") { Heading("Novità") }
+ item(contentType = Feed.RELEASES.name) { Heading("Novità") }
// Cards rather than another row of thumbnails. A carousel
// says "here is a list, pick one"; this is meant to be
// looked at, so each release gets the width of the page and
@@ -186,15 +220,15 @@ fun HomeScreen(
items(
feed.newReleases.take(FEED_SIZE),
key = { it.uri },
- contentType = { "card" },
+ contentType = { Feed.RELEASES.name },
) { item ->
FeedCard(item) { onOpenItem(item) }
}
}
if (showArtists && feed.topArtists.isNotEmpty()) {
- item(contentType = "heading") { Heading("Artisti che ascolti") }
- item(contentType = "artists") {
+ item(contentType = Feed.ARTISTS.name) { Heading("Artisti che ascolti") }
+ item(contentType = Feed.ARTISTS.name) {
Carousel(feed.topArtists, key = { it.uri }) { artist ->
ArtistTile(artist) { onOpenItem(artist) }
}
@@ -202,8 +236,8 @@ fun HomeScreen(
}
if (showLibrary || filter == Feed.ALL) {
- item(contentType = "heading") { Heading("Le tue playlist") }
- item(contentType = "playlists") {
+ item(contentType = Feed.LIBRARY.name) { Heading("Le tue playlist") }
+ item(contentType = Feed.LIBRARY.name) {
Carousel(
playlists.take(if (showLibrary) LIBRARY_SIZE else CAROUSEL_SIZE),
key = { it.uri },
@@ -214,8 +248,8 @@ fun HomeScreen(
}
if (recent.isNotEmpty() && filter != Feed.ARTISTS) {
- item(contentType = "heading") { Heading("Riascolta") }
- item(contentType = "recent") {
+ item(contentType = Feed.LIBRARY.name) { Heading("Riascolta") }
+ item(contentType = Feed.LIBRARY.name) {
LazyRow(
contentPadding = PaddingValues(horizontal = 20.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp),
@@ -249,6 +283,8 @@ private fun Header(
avatarUrl: String?,
collapse: Float,
filter: Feed,
+ /** The chip drawn as active, which follows the scroll while nothing is filtered. */
+ highlighted: Feed,
backdrop: Backdrop,
topPadding: Dp,
onFilter: (Feed) -> Unit,
@@ -321,7 +357,7 @@ private fun Header(
)
}
- FilterRow(filter, backdrop, onFilter)
+ FilterRow(highlighted, backdrop, onFilter)
}
}
@@ -594,6 +630,9 @@ private const val COLLAPSE_DISTANCE_PX = 140f
/** Comfortably under the 640px Spotify serves, so it is never upscaled. */
private val COVER_SIZE = 210.dp
+/** How much of the list's height the fade under the header covers. */
+private const val FADE_FRACTION = 0.045f
+
private const val FEED_SIZE = 6
private const val CAROUSEL_SIZE = 8
diff --git a/app/src/main/java/dev/emanuele/spot/ui/player/LyricsView.kt b/app/src/main/java/dev/emanuele/spot/ui/player/LyricsView.kt
index 61aa72b..09a39ff 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/player/LyricsView.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/player/LyricsView.kt
@@ -26,6 +26,9 @@ import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.CompositingStrategy
import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.text.AnnotatedString
+import androidx.compose.ui.text.SpanStyle
+import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
@@ -89,23 +92,76 @@ fun LyricsView(
contentPadding = androidx.compose.foundation.layout.PaddingValues(vertical = 40.dp),
) {
itemsIndexed(lyrics.lines) { index, line ->
+ val isActive = index == activeLine
LyricRow(
text = line.text,
distance = if (activeLine < 0) 0 else abs(index - activeLine),
- isActive = index == activeLine,
+ isActive = isActive,
unsynced = !lyrics.synced,
+ // Only the line being sung pays for this; the rest are drawn
+ // plain.
+ sungFraction = if (isActive) {
+ lineProgress(lyrics, index, position)
+ } else {
+ 0f
+ },
onClick = { line.startTimeMs?.let(onSeek) },
)
}
}
}
+/**
+ * How far through the current line playback is, 0 to 1.
+ *
+ * The line's end is the next line's start; the last line has no such marker, so
+ * it gets a fixed span rather than staying at zero for however long the outro
+ * runs.
+ */
+private fun lineProgress(lyrics: Lyrics, index: Int, positionMs: Long): Float {
+ val start = lyrics.lines[index].startTimeMs ?: return 0f
+ val end = lyrics.lines.getOrNull(index + 1)?.startTimeMs ?: (start + TAIL_LINE_MS)
+ val span = (end - start).coerceAtLeast(1L)
+ return ((positionMs - start).toFloat() / span).coerceIn(0f, 1f)
+}
+
+/**
+ * Splits a line into words with a share of its duration each.
+ *
+ * Spotify times lyrics by line, never by word, so Apple Music's sung-along
+ * highlight cannot be reproduced from the data — this approximates it by giving
+ * each word a share of the line proportional to its length. Longer words take
+ * longer to sing, which is true often enough to read as right; it will drift on
+ * a line that holds one syllable for a bar, and nothing here can know that.
+ *
+ * Trailing space is counted with the word so the highlight sweeps continuously
+ * instead of stepping across gaps.
+ */
+private fun wordStops(text: String): List<Pair<IntRange, Float>> {
+ val total = text.count { !it.isWhitespace() }.coerceAtLeast(1)
+ val stops = mutableListOf<Pair<IntRange, Float>>()
+ var consumed = 0
+ var index = 0
+ while (index < text.length) {
+ while (index < text.length && text[index].isWhitespace()) index++
+ if (index >= text.length) break
+ val start = index
+ while (index < text.length && !text[index].isWhitespace()) index++
+ val wordEnd = index
+ while (index < text.length && text[index].isWhitespace()) index++
+ consumed += wordEnd - start
+ stops += (start until index) to consumed.toFloat() / total
+ }
+ return stops
+}
+
@Composable
private fun LyricRow(
text: String,
distance: Int,
isActive: Boolean,
unsynced: Boolean,
+ sungFraction: Float,
onClick: () -> Unit,
) {
val springSpec = spring<Float>(
@@ -145,8 +201,32 @@ private fun LyricRow(
.padding(horizontal = 22.dp, vertical = 9.dp),
contentAlignment = Alignment.CenterStart,
) {
+ // The sung part of the line is fully lit, the rest of it is not.
+ //
+ // Word by word rather than a sweep across the whole line: a gradient
+ // spans the text block, so on a line that wraps it would light the
+ // second row from the left while the first is still being sung.
+ val rendered = remember(text, isActive, sungFraction) {
+ if (!isActive) {
+ AnnotatedString(text)
+ } else {
+ buildAnnotatedString {
+ append(text)
+ wordStops(text).forEach { (range, stop) ->
+ if (stop > sungFraction) {
+ addStyle(
+ SpanStyle(color = Color.White.copy(alpha = 0.45f)),
+ range.first,
+ range.last + 1,
+ )
+ }
+ }
+ }
+ }
+ }
+
Text(
- text = text,
+ text = rendered,
style = MaterialTheme.typography.titleLarge.copy(fontSize = 27.sp, lineHeight = 33.sp),
fontWeight = FontWeight.Bold,
// White rather than the artwork accent. These sit over a Canvas now,
@@ -170,3 +250,6 @@ private fun LyricRow(
/** Rough line height in px, used to bias the auto-scroll target. */
private const val LineHeightPx = 60
+
+/** How long the last line is assumed to last, having no next line to end it. */
+private const val TAIL_LINE_MS = 4_000L