Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
Immersive Genius notes: a soft pill behind annotated words and a small quote mark that opens the note, a cover-tinted sheet with the quoted line, paragraphs, links, upvotes, Translate and Read on Genius
kota-zo62a0437b4bf9
diff --git a/base/app/src/main/java/com/music/spotui/data/api/GeniusMeaning.kt b/base/app/src/main/java/com/music/spotui/data/api/GeniusMeaning.ktindex f28be0f5..ef477f85 100644--- a/base/app/src/main/java/com/music/spotui/data/api/GeniusMeaning.kt+++ b/base/app/src/main/java/com/music/spotui/data/api/GeniusMeaning.kt@@ -24,7 +24,8 @@ import java.util.concurrent.TimeUnit* and its annotations. The last few songs asked for are kept in memory (small texts).*/object GeniusMeaning {- data class Note(val fragment: String, val explanation: String, val votes: Int = 0)+ /** One line's explanation; [url] is its own page on Genius (empty when Genius gave none). */+ data class Note(val fragment: String, val explanation: String, val votes: Int = 0, val url: String = "")data class Meaning(val url: String, val title: String, val artist: String, val about: String?, val notes: List<Note>) {val isEmpty get() = about.isNullOrBlank() && notes.isEmpty()}@@ -67,10 +68,11 @@ object GeniusMeaning {val fragment = r.str("fragment")?.trim().orEmpty()// The best liked explanation of the line; one voted down (negative) is never shown.val best = r["annotations"]?.jsonArray.orEmpty().map { it.jsonObject }- .map { a -> a.obj("body")?.str("plain")?.trim().orEmpty() to (a.str("votes_total")?.toIntOrNull() ?: 0) }+ .map { a -> Triple(a.obj("body")?.str("plain")?.trim().orEmpty(), a.str("votes_total")?.toIntOrNull() ?: 0, a.str("url").orEmpty()) }.filter { (body, votes) -> body.isNotBlank() && body != "?" && votes >= 0 }.maxByOrNull { it.second }- if (fragment.isBlank() || best == null) null else Note(fragment, best.first, best.second)+ if (fragment.isBlank() || best == null) null+ else Note(fragment, best.first, best.second, best.third.ifBlank { r.str("url").orEmpty() })}}Meaning(diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveLyricsPanel.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveLyricsPanel.ktindex d25a6f59..e79657fc 100644--- a/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveLyricsPanel.kt+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveLyricsPanel.kt@@ -74,8 +74,6 @@ import androidx.compose.ui.draw.drawWithCacheimport androidx.compose.ui.geometry.Offsetimport androidx.compose.ui.graphics.Brushimport androidx.compose.ui.graphics.Color-import androidx.compose.ui.graphics.PathEffect-import androidx.compose.ui.graphics.StrokeCapimport androidx.compose.ui.graphics.TransformOriginimport androidx.compose.ui.graphics.graphicsLayerimport androidx.compose.ui.input.nestedscroll.nestedScroll@@ -115,6 +113,17 @@ import com.music.spotui.ui.viewmodel.LyricsViewModelimport kotlinx.coroutines.delayimport kotlinx.coroutines.flow.firstimport kotlin.math.abs+import androidx.compose.foundation.shape.CircleShape+import androidx.compose.material.icons.Icons+import androidx.compose.material.icons.rounded.FormatQuote+import androidx.compose.material3.Icon+import androidx.compose.ui.geometry.CornerRadius+import androidx.compose.ui.geometry.Rect+import androidx.compose.ui.layout.Layout+import androidx.compose.ui.text.TextMeasurer+import androidx.compose.ui.text.rememberTextMeasurer+import androidx.compose.ui.unit.Constraints+import com.music.spotui.ui.immersive.components.immersiveClickable/*** The lyrics of the playing track, inside the player: big tight type, the playing line crisp@@ -285,7 +294,8 @@ private fun LyricsList(val clock = head.clock// Genius's notes on the lines, read in the background when the song started (App.kt) and kept- // by track id; a line it explains is dotted and opens the note on a long press. Tap still seeks.+ // by track id. A line it explains sits on a soft pill with a small quote mark after its last+ // word; the mark opens the note, and so does a long press anywhere on the line. Tap still seeks.val trackId = SongPlayer.nowPlaying.value.uri.substringAfterLast(':')val genTitle = Graph.currentSongState.title.valueval genArtist = Graph.currentSongState.singer.value@@ -300,8 +310,11 @@ private fun LyricsList(var noteOpen by remember(trackKey) { mutableStateOf<Int?>(null) }val haptics = androidx.compose.ui.platform.LocalHapticFeedback.currentnoteOpen?.let { n ->- com.music.spotui.ui.immersive.sheets.ImmersiveMeaningSheet(trackId, genTitle, genArtist, n) { noteOpen = null }+ com.music.spotui.ui.immersive.sheets.ImmersiveMeaningSheet(+ trackId, genTitle, genArtist, n, coverUrl = Graph.currentSongState.coverUri.value,+ ) { noteOpen = null }}+ val noteMeasurer = rememberTextMeasurer(cacheSize = 16)val activeRow by remember(rows, isSynced) {derivedStateOf { if (!isSynced) -1 else activeRow(rows, clock.longValue) }@@ -439,7 +452,8 @@ private fun LyricsList(blurOk = blurOk,glowing = blurOk,clock = clock,- annotated = index in notes,+ noteMeasurer = noteMeasurer,+ onNote = notes[index]?.let { n -> { noteOpen = n } },onHold = notes[index]?.let { n ->{haptics.performHapticFeedback(androidx.compose.ui.hapticfeedback.HapticFeedbackType.LongPress)@@ -473,7 +487,9 @@ private fun PanelRow(blurOk: Boolean,glowing: Boolean,clock: MutableLongState,- annotated: Boolean,+ noteMeasurer: TextMeasurer,+ /** Opens the Genius note on this line; null when Genius has none. */+ onNote: (() -> Unit)?,onHold: (() -> Unit)?,onSeek: (Long) -> Unit,) {@@ -523,6 +539,7 @@ private fun PanelRow(} else {Immersive.Lyric.copy(fontSize = 26.sp, lineHeight = 33.sp)}+ val lineStyle = remember(style, row.text) { voiceStyle(style, row.text) }// The stack sits fractionally back and the playing line comes forward to meet you. Rows// behind the one being scrolled to are the ones that fan out; the ones it is moving away// from arrive together.@@ -572,15 +589,24 @@ private fun PanelRow(}.blur(blur, BlurredEdgeTreatment.Unbounded).clip(RoundedCornerShape(10.dp))- .then(if (annotated) Modifier.drawBehind {- // Genius explains this line: a faint dotted line under it, quiet beside the singing.- val y = size.height - GLOW_ROOM.toPx() + 2.dp.toPx()- drawLine(- color = Color.White.copy(alpha = 0.22f),- start = Offset(GLOW_ROOM.toPx(), y), end = Offset(size.width - GLOW_ROOM.toPx(), y),- strokeWidth = 1.5.dp.toPx(), cap = StrokeCap.Round,- pathEffect = PathEffect.dashPathEffect(floatArrayOf(0.1f, 5.dp.toPx())),- )+ .then(if (onNote != null) Modifier.drawWithCache {+ // Genius explains this line: each row of its words sits on a faint pill, as Genius+ // marks the lines it explains. Drawn behind the words, inside the row, so the sweep+ // and the glow are untouched and the pill dims and blurs with its line.+ val text = measureNoteLine(noteMeasurer, row.text, lineStyle, size.width.toInt(), GLOW_ROOM.roundToPx())+ val room = GLOW_ROOM.toPx()+ val padH = NOTE_PILL_PAD_H.toPx()+ val inset = NOTE_PILL_INSET.toPx()+ val radius = CornerRadius(NOTE_PILL_RADIUS.toPx())+ val pills = (0 until text.lineCount).mapNotNull { i ->+ val left = text.getLineLeft(i)+ val right = text.getLineRight(i)+ if (right - left < 1f) null+ else Rect(room + left - padH, room + text.getLineTop(i) + inset, room + right + padH, room + text.getLineBottom(i) - inset)+ }+ onDrawBehind {+ pills.forEach { r -> drawRoundRect(NOTE_PILL_COLOR, r.topLeft, r.size, radius) }+ }} else Modifier).secondaryClick(onHold).combinedClickable(@@ -590,11 +616,17 @@ private fun PanelRow()CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {- Column(modifier = shape) {+ NoteLayout(+ text = row.text,+ style = lineStyle,+ measurer = noteMeasurer,+ onNote = onNote,+ modifier = shape,+ ) {PanelVoice(row = row,clock = clock,- style = voiceStyle(style, row.text),+ style = lineStyle,isActive = isActive,sung = sung,synced = synced,@@ -607,6 +639,114 @@ private fun PanelRow(}}+// ─── Genius notes on the lines ───────────────────────────────────────────────────────────++private val NOTE_PILL_COLOR = Color.White.copy(alpha = 0.09f)+private val NOTE_PILL_PAD_H = 7.dp+private val NOTE_PILL_INSET = 3.dp+private val NOTE_PILL_RADIUS = 12.dp+/** The quote mark after an explained line, and the gap before it. */+private val NOTE_MARK_SIZE = 22.dp+private val NOTE_MARK_GAP = 6.dp+/** What the finger has to hit to open the note: larger than the mark it shows. */+private val NOTE_MARK_TOUCH = 40.dp++/**+ * The line's words laid out as the row lays them out: the row's width less the glow room on+ * each side, left to right. The measurer keeps the result, so the pills and the mark share it.+ */+private fun measureNoteLine(measurer: TextMeasurer, text: String, style: TextStyle, rowWidth: Int, room: Int): TextLayoutResult =+ measurer.measure(+ text = text,+ style = style,+ constraints = Constraints(maxWidth = (rowWidth - room * 2).coerceAtLeast(0)),+ layoutDirection = LayoutDirection.Ltr,+ )++/**+ * A lyric row, and when Genius explains it ([onNote] set) the small quote mark that opens the+ * note: just after the last word, centred on that row of text (before it for right-to-left+ * lines). When the last row of words runs too close to the edge for it, the mark goes on a row of+ * its own under the words rather than over them, so nothing the singing lights is ever covered.+ */+@Composable+private fun NoteLayout(+ text: String,+ style: TextStyle,+ measurer: TextMeasurer,+ onNote: (() -> Unit)?,+ modifier: Modifier = Modifier,+ voice: @Composable () -> Unit,+) {+ Layout(+ modifier = modifier,+ content = {+ voice()+ if (onNote != null) NoteMark(onNote)+ },+ ) { measurables, constraints ->+ val line = measurables[0].measure(constraints)+ val markMeasurable = measurables.getOrNull(1)+ if (markMeasurable == null) {+ return@Layout layout(line.width, line.height) { line.place(0, 0) }+ }+ val mark = markMeasurable.measure(Constraints())+ val room = GLOW_ROOM.roundToPx()+ val laid = measureNoteLine(measurer, text, style, line.width, room)+ val last = (laid.lineCount - 1).coerceAtLeast(0)+ val radius = NOTE_MARK_SIZE.toPx() / 2f+ val lead = NOTE_PILL_PAD_H.toPx() + NOTE_MARK_GAP.toPx() + radius+ val rtl = isRtl(text)+ val inlineX = if (rtl) room + laid.getLineLeft(last) - lead else room + laid.getLineRight(last) + lead+ val fits = if (rtl) inlineX - radius >= 0f else inlineX + radius <= line.width+ val centerX: Float+ val centerY: Float+ val height: Int+ if (fits) {+ centerX = inlineX+ centerY = room + (laid.getLineTop(last) + laid.getLineBottom(last)) / 2f+ height = line.height+ } else {+ centerX = if (rtl) line.width - room - radius else room + radius+ centerY = room + laid.size.height + NOTE_MARK_GAP.toPx() + radius+ height = maxOf(line.height, (centerY + radius + room / 2f).toInt())+ }+ layout(line.width, height) {+ line.place(0, 0)+ mark.place((centerX - mark.width / 2f).toInt(), (centerY - mark.height / 2f).toInt())+ }+ }+}++/** The quote mark itself: a small frosted disc, with a finger-sized target around it. */+@Composable+private fun NoteMark(onOpen: () -> Unit) {+ val label = stringResource(R.string.immersive_genius_note_open)+ Box(+ contentAlignment = Alignment.Center,+ modifier = Modifier+ .size(NOTE_MARK_TOUCH)+ .clip(CircleShape)+ .immersiveClickable(onClick = onOpen, pressedScale = 0.85f)+ .semantics { contentDescription = label },+ ) {+ Box(+ contentAlignment = Alignment.Center,+ modifier = Modifier+ .size(NOTE_MARK_SIZE)+ .clip(CircleShape)+ .background(Color.White.copy(alpha = 0.16f)),+ ) {+ Icon(+ Icons.Rounded.FormatQuote,+ contentDescription = null,+ tint = Color.White.copy(alpha = 0.9f),+ modifier = Modifier.size(15.dp),+ )+ }+ }+}+private fun isRtl(text: String): Boolean {var rtl = 0var ltr = 0diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/sheets/ImmersiveMeaningSheet.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/sheets/ImmersiveMeaningSheet.ktindex 8880c290..21d077e6 100644--- a/base/app/src/main/java/com/music/spotui/ui/immersive/sheets/ImmersiveMeaningSheet.kt+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/sheets/ImmersiveMeaningSheet.kt@@ -1,41 +1,49 @@package com.music.spotui.ui.immersive.sheetsimport android.content.Intent+import android.content.res.Configuration+import androidx.compose.foundation.backgroundimport androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.IntrinsicSizeimport androidx.compose.foundation.layout.Rowimport androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxHeightimport androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.heightInimport androidx.compose.foundation.layout.height-import androidx.compose.foundation.layout.navigationBarsPadding+import androidx.compose.foundation.layout.heightInimport androidx.compose.foundation.layout.padding-import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.widthimport androidx.compose.foundation.shape.RoundedCornerShape-import androidx.compose.foundation.verticalScroll+import androidx.compose.material.icons.Icons+import androidx.compose.material.icons.automirrored.rounded.OpenInNew+import androidx.compose.material.icons.rounded.Translateimport androidx.compose.material3.CircularProgressIndicatorimport androidx.compose.material3.ExperimentalMaterial3Api+import androidx.compose.material3.Iconimport androidx.compose.material3.Textimport androidx.compose.runtime.Composableimport androidx.compose.runtime.getValueimport androidx.compose.runtime.produceState+import androidx.compose.runtime.rememberimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.clip+import androidx.compose.ui.layout.ContentScaleimport androidx.compose.ui.platform.LocalConfigurationimport androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.res.pluralStringResourceimport androidx.compose.ui.res.stringResource-import androidx.compose.ui.text.AnnotatedString-import androidx.compose.ui.text.LinkAnnotation-import androidx.compose.ui.text.SpanStyle-import androidx.compose.ui.text.TextLinkStyles-import androidx.compose.ui.text.buildAnnotatedString-import androidx.compose.ui.text.style.TextDecoration-import androidx.compose.ui.text.withLink+import androidx.compose.ui.text.style.TextOverflowimport androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.spimport app.myspoti.engine.R+import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi+import com.bumptech.glide.integration.compose.GlideImageimport com.music.spotui.data.api.GeniusMeaning-import com.music.spotui.ui.components.readerLanguage+import com.music.spotui.ui.components.rememberLinkedTextimport com.music.spotui.ui.components.rememberShownimport com.music.spotui.ui.components.showOriginalimport com.music.spotui.ui.immersive.Immersive@@ -50,10 +58,14 @@ private sealed interface MeaningLoad {}/**- * Genius's words on the Immersive glass sheet, from the same [GeniusMeaning] the Classic look- * reads (nothing new on the network: the look-up begun when the song started, or the cached one).- * [noteIndex] set: the explanation of one lyric line; null: the song as a whole ("About").- * The text is read off the main thread and keyed on [trackId].+ * Genius's words on an Immersive sheet in the song's colours (the song sheet's ground), from the+ * same [GeniusMeaning] the Classic look reads (nothing new on the network: the look-up begun when+ * the song started, or the cached one). [noteIndex] set: the explanation of one lyric line, under+ * that line quoted; null: the song as a whole ("About"). The text is read off the main thread and+ * keyed on [trackId].+ *+ * A note stops short of the top of a portrait screen, so the line being sung (which sits high on+ * the lyrics page) stays in sight above it; landscape has too little height to spare and takes more.*/@OptIn(ExperimentalMaterial3Api::class)@Composable@@ -62,6 +74,7 @@ fun ImmersiveMeaningSheet(title: String,artist: String,noteIndex: Int?,+ coverUrl: String? = null,onDismiss: () -> Unit,) {val load by produceState<MeaningLoad>(MeaningLoad.Loading, trackId, title, artist) {@@ -76,28 +89,34 @@ fun ImmersiveMeaningSheet(MeaningLoad.Failed}}- ImmersiveGlassSheet(onDismiss = onDismiss) {- val maxH = LocalConfiguration.current.screenHeightDp.dp * 0.7f- Column(Modifier.fillMaxWidth().heightIn(max = maxH).verticalScroll(rememberScrollState()).navigationBarsPadding()) {- when (val l = load) {- MeaningLoad.Loading -> {- ImmersiveSheetTitle(stringResource(R.string.lyrics_meaning_title), subtitle = "$title · $artist")- Row(Modifier.fillMaxWidth().padding(vertical = 28.dp), horizontalArrangement = Arrangement.Center) {- CircularProgressIndicator(color = Immersive.TextSecondary, strokeWidth = 2.dp, modifier = Modifier.height(24.dp))- }- }- MeaningLoad.None -> {- ImmersiveSheetTitle(stringResource(R.string.lyrics_meaning_title), subtitle = "$title · $artist")- ImmersiveSheetNote(stringResource(R.string.immersive_genius_none))- }- MeaningLoad.Failed -> {- ImmersiveSheetTitle(stringResource(R.string.lyrics_meaning_title), subtitle = "$title · $artist")- ImmersiveSheetNote(stringResource(R.string.immersive_genius_error))+ val configuration = LocalConfiguration.current+ val landscape = configuration.orientation == Configuration.ORIENTATION_LANDSCAPE+ val fraction = when {+ landscape -> 0.9f+ noteIndex == null -> 0.8f+ configuration.smallestScreenWidthDp >= 600 -> 0.5f+ else -> 0.62f+ }+ ImmersiveSheet(onDismiss = onDismiss, imageUrl = coverUrl, maxHeightFraction = fraction) {+ val songLine = listOf(title, artist).filter { it.isNotBlank() }.joinToString(" · ")+ when (val l = load) {+ MeaningLoad.Loading -> {+ MeaningHeader(stringResource(R.string.lyrics_meaning_title), songLine, quoted = false)+ Row(Modifier.fillMaxWidth().padding(vertical = 32.dp), horizontalArrangement = Arrangement.Center) {+ CircularProgressIndicator(color = Immersive.TextSecondary, strokeWidth = 2.dp, modifier = Modifier.size(22.dp))}- is MeaningLoad.Ready -> MeaningBody(l.meaning, noteIndex)}- Spacer(Modifier.height(16.dp))+ MeaningLoad.None -> {+ MeaningHeader(stringResource(R.string.lyrics_meaning_title), songLine, quoted = false)+ ImmersiveSheetNote(stringResource(R.string.immersive_genius_none), Modifier.padding(bottom = 12.dp))+ }+ MeaningLoad.Failed -> {+ MeaningHeader(stringResource(R.string.lyrics_meaning_title), songLine, quoted = false)+ ImmersiveSheetNote(stringResource(R.string.immersive_genius_error), Modifier.padding(bottom = 12.dp))+ }+ is MeaningLoad.Ready -> MeaningBody(l.meaning, noteIndex)}+ Spacer(Modifier.height(20.dp))}}@@ -107,56 +126,163 @@ private fun MeaningBody(original: GeniusMeaning.Meaning, noteIndex: Int?) {val shown = rememberShown(original, listOfNotNull(if (note != null) note.explanation else original.about))val m = shown.meaningval shownNote = noteIndex?.let { m.notes.getOrNull(it) }- val context = LocalContext.current+ val songLine = listOf(m.title, m.artist).filter { it.isNotBlank() }.joinToString(" · ")if (shownNote != null) {- ImmersiveSheetTitle(shownNote.fragment, subtitle = "${m.title} · ${m.artist}")- ImmersiveSheetDivider()- LinkedText(shownNote.explanation)+ MeaningHeader(shownNote.fragment, songLine, quoted = true)+ MeaningText(shownNote.explanation)} else {- ImmersiveSheetTitle(stringResource(R.string.lyrics_meaning_about), subtitle = "${m.title} · ${m.artist}")- ImmersiveSheetDivider()- if (!m.about.isNullOrBlank()) LinkedText(m.about!!)+ MeaningHeader(stringResource(R.string.lyrics_meaning_about), songLine, quoted = false)+ if (!m.about.isNullOrBlank()) MeaningText(m.about!!)else ImmersiveSheetNote(stringResource(R.string.immersive_genius_none))}- Row(Modifier.fillMaxWidth().padding(horizontal = 22.dp, vertical = 6.dp), verticalAlignment = Alignment.CenterVertically) {- when {- shown.translating -> Text(stringResource(R.string.lyrics_meaning_translating), style = Immersive.Subhead)- shown.canTranslate -> Text(- stringResource(if (showOriginal.value) R.string.lyrics_meaning_translate else R.string.lyrics_meaning_original),- style = Immersive.Subhead.copy(color = Immersive.Text),- modifier = Modifier.clip(RoundedCornerShape(50))- .immersiveClickable(onClick = { showOriginal.value = !showOriginal.value })- .padding(horizontal = 12.dp, vertical = 6.dp),+ MeaningFooter(+ shown = shown,+ url = shownNote?.url?.takeIf { it.isNotBlank() } ?: m.url,+ votes = shownNote?.votes,+ )+}++/**+ * The head of the sheet. A note quotes its line in the title face behind a bar in the sheet's+ * accent, as a pull quote, whole rather than cut to one line; the song it is from sits above, small.+ */+@Composable+private fun MeaningHeader(title: String, songLine: String, quoted: Boolean) {+ Column(Modifier.fillMaxWidth().padding(start = 22.dp, end = 22.dp, top = 10.dp, bottom = 14.dp)) {+ if (songLine.isNotBlank()) {+ Text(+ songLine.uppercase(),+ style = Immersive.Caption.copy(letterSpacing = 0.6.sp),+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,)+ Spacer(Modifier.height(8.dp))+ }+ if (quoted) {+ Row(Modifier.height(IntrinsicSize.Min)) {+ Box(+ Modifier+ .width(3.dp)+ .fillMaxHeight()+ .clip(RoundedCornerShape(50))+ .background(LocalImmersiveSheetTint.current.accent),+ )+ Spacer(Modifier.width(12.dp))+ Text(+ title,+ style = Immersive.Title.copy(fontSize = 21.sp, lineHeight = 27.sp, color = Immersive.Text),+ maxLines = 6,+ overflow = TextOverflow.Ellipsis,+ modifier = Modifier.padding(vertical = 2.dp),+ )+ }+ } else {+ Text(title, style = Immersive.Title, maxLines = 2, overflow = TextOverflow.Ellipsis)}- Spacer(Modifier.weight(1f))- if (m.url.isNotBlank()) Text(- stringResource(R.string.immersive_genius_view),- style = Immersive.BodyStrong.copy(color = LocalImmersiveSheetTint.current.accent),- modifier = Modifier.clip(RoundedCornerShape(50))- .immersiveClickable(onClick = {- runCatching { context.startActivity(Intent(Intent.ACTION_VIEW, android.net.Uri.parse(m.url)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) }- })- .padding(horizontal = 12.dp, vertical = 8.dp),- )}}-private val urlRegex = Regex("""https?://[^\s<>"')]+""")+/** A paragraph that is only a picture's address: Genius's plain text keeps some images that way. */+private val IMAGE_URL = Regex("""https?://\S+\.(?:jpe?g|png|gif|webp)(?:\?\S*)?""", RegexOption.IGNORE_CASE)-/** The annotation as body text; the web addresses in it open when tapped. */+/**+ * The annotation, set for reading: one block per paragraph with air between them, a looser+ * leading than the sheets' rows, and the web addresses tappable (Spotify ones open in the app).+ * A paragraph that is a picture's address shows the picture, rounded, at the column's width.+ */+@OptIn(ExperimentalGlideComposeApi::class)@Composable-private fun LinkedText(text: String) {+private fun MeaningText(text: String) {+ val paragraphs = remember(text) {+ text.replace("\r\n", "\n")+ .split(Regex("""\n\s*\n"""))+ .map { p -> p.lines().joinToString("\n") { it.trim() }.trim() }+ .filter { it.isNotEmpty() }+ }val accent = LocalImmersiveSheetTint.current.accent- val styled: AnnotatedString = buildAnnotatedString {- var last = 0- for (hit in urlRegex.findAll(text)) {- append(text.substring(last, hit.range.first))- val url = hit.value.trimEnd('.', ',', ';', ':', '!', '?')- withLink(LinkAnnotation.Url(url, TextLinkStyles(SpanStyle(color = accent, textDecoration = TextDecoration.Underline)))) { append(url) }- last = hit.range.first + url.length+ val style = Immersive.Body.copy(fontSize = 16.5.sp, lineHeight = 25.sp, color = Immersive.Text.copy(alpha = 0.92f))+ Column(+ Modifier.fillMaxWidth().padding(horizontal = 22.dp),+ verticalArrangement = Arrangement.spacedBy(14.dp),+ ) {+ paragraphs.forEach { p ->+ if (IMAGE_URL.matches(p)) {+ GlideImage(+ model = p,+ contentDescription = null,+ contentScale = ContentScale.FillWidth,+ modifier = Modifier+ .fillMaxWidth()+ .heightIn(max = 260.dp)+ .clip(Immersive.CoverMedium),+ )+ } else {+ Text(rememberLinkedText(p, accent), style = style)+ }}- append(text.substring(last))}- Text(styled, style = Immersive.Body.copy(color = Immersive.Text), modifier = Modifier.padding(horizontal = 22.dp, vertical = 14.dp))+}++/**+ * Where the text came from, small, and what can be done with it: translate it (or go back to the+ * original), and read it on Genius, where the note's own page opens when Genius gave one.+ */+@Composable+private fun MeaningFooter(shown: com.music.spotui.ui.components.ShownMeaning, url: String, votes: Int?) {+ val context = LocalContext.current+ val accent = LocalImmersiveSheetTint.current.accent+ Spacer(Modifier.height(18.dp))+ ImmersiveSheetDivider(Modifier.padding(horizontal = 22.dp))+ Row(+ Modifier.fillMaxWidth().padding(start = 22.dp, end = 12.dp, top = 10.dp),+ verticalAlignment = Alignment.CenterVertically,+ ) {+ Column(Modifier.weight(1f)) {+ Text(stringResource(R.string.immersive_genius_source), style = Immersive.Caption.copy(color = Immersive.TextSecondary))+ if (votes != null && votes > 0) {+ Text(pluralStringResource(R.plurals.immersive_genius_upvotes, votes, votes), style = Immersive.Caption.copy(color = Immersive.TextTertiary))+ }+ }+ when {+ shown.translating -> Text(+ stringResource(R.string.lyrics_meaning_translating),+ style = Immersive.Subhead,+ modifier = Modifier.padding(horizontal = 10.dp, vertical = 8.dp),+ )+ shown.canTranslate -> FooterPill(+ label = stringResource(if (showOriginal.value) R.string.lyrics_meaning_translate else R.string.lyrics_meaning_original),+ icon = { Icon(Icons.Rounded.Translate, null, tint = Immersive.Text, modifier = Modifier.size(15.dp)) },+ color = Immersive.Text,+ onClick = { showOriginal.value = !showOriginal.value },+ )+ }+ if (url.isNotBlank()) FooterPill(+ label = stringResource(R.string.immersive_genius_read),+ icon = { Icon(Icons.AutoMirrored.Rounded.OpenInNew, null, tint = accent, modifier = Modifier.size(15.dp)) },+ color = accent,+ onClick = {+ runCatching {+ context.startActivity(Intent(Intent.ACTION_VIEW, android.net.Uri.parse(url)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))+ }+ },+ )+ }+}++@Composable+private fun FooterPill(label: String, icon: @Composable () -> Unit, color: androidx.compose.ui.graphics.Color, onClick: () -> Unit) {+ Row(+ Modifier+ .padding(start = 6.dp)+ .clip(RoundedCornerShape(50))+ .background(Immersive.Text.copy(alpha = 0.08f))+ .immersiveClickable(onClick = onClick)+ .heightIn(min = 36.dp)+ .padding(horizontal = 12.dp, vertical = 8.dp),+ verticalAlignment = Alignment.CenterVertically,+ ) {+ icon()+ Spacer(Modifier.width(6.dp))+ Text(label, style = Immersive.Subhead.copy(color = color, fontWeight = androidx.compose.ui.text.font.FontWeight.SemiBold), maxLines = 1)+ }}diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/sheets/ImmersiveSongOptionsSheet.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/sheets/ImmersiveSongOptionsSheet.ktindex d706fd8d..f1b90708 100644--- a/base/app/src/main/java/com/music/spotui/ui/immersive/sheets/ImmersiveSongOptionsSheet.kt+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/sheets/ImmersiveSongOptionsSheet.kt@@ -82,7 +82,7 @@ fun ImmersiveSongOptionsSheet(var showMeaning by remember { mutableStateOf(false) }if (showCredits) { CreditsSheet(song = song, onDismiss = { showCredits = false; onDismiss() }); return }if (showMeaning) {- ImmersiveMeaningSheet(song.spotifyTrackId, song.title, song.singer, null) { showMeaning = false; onDismiss() }+ ImmersiveMeaningSheet(song.spotifyTrackId, song.title, song.singer, null, coverUrl = song.coverUri) { showMeaning = false; onDismiss() }return}if (showSpeed) { SpeedSheet(onDismiss = { showSpeed = false; onDismiss() }); return }diff --git a/base/app/src/main/res/values-de/immersive_genius_strings.xml b/base/app/src/main/res/values-de/immersive_genius_strings.xmlindex b77ec3e7..8de3e96e 100644--- a/base/app/src/main/res/values-de/immersive_genius_strings.xml+++ b/base/app/src/main/res/values-de/immersive_genius_strings.xml@@ -2,5 +2,11 @@<resources><string name="immersive_genius_none">Genius hat nichts zu diesem Titel.</string><string name="immersive_genius_error">Genius ist gerade nicht erreichbar.</string>- <string name="immersive_genius_view">Auf Genius ansehen</string>+ <string name="immersive_genius_read">Auf Genius lesen</string>+ <string name="immersive_genius_note_open">Was Genius zu dieser Zeile sagt</string>+ <string name="immersive_genius_source">Genius-Anmerkung</string>+ <plurals name="immersive_genius_upvotes">+ <item quantity="one">%1$d positive Stimme</item>+ <item quantity="other">%1$d positive Stimmen</item>+ </plurals></resources>diff --git a/base/app/src/main/res/values-el/immersive_genius_strings.xml b/base/app/src/main/res/values-el/immersive_genius_strings.xmlindex 50fec949..af9a7d69 100644--- a/base/app/src/main/res/values-el/immersive_genius_strings.xml+++ b/base/app/src/main/res/values-el/immersive_genius_strings.xml@@ -2,5 +2,4 @@<resources><string name="immersive_genius_none">Το Genius δεν έχει τίποτα για αυτό το τραγούδι.</string><string name="immersive_genius_error">Το Genius δεν είναι προσβάσιμο αυτή τη στιγμή.</string>- <string name="immersive_genius_view">Προβολή στο Genius</string></resources>diff --git a/base/app/src/main/res/values-es/immersive_genius_strings.xml b/base/app/src/main/res/values-es/immersive_genius_strings.xmlindex 31d45394..09c1788b 100644--- a/base/app/src/main/res/values-es/immersive_genius_strings.xml+++ b/base/app/src/main/res/values-es/immersive_genius_strings.xml@@ -2,5 +2,11 @@<resources><string name="immersive_genius_none">Genius no tiene nada sobre esta canción.</string><string name="immersive_genius_error">No se puede conectar con Genius ahora mismo.</string>- <string name="immersive_genius_view">Ver en Genius</string>+ <string name="immersive_genius_read">Leer en Genius</string>+ <string name="immersive_genius_note_open">Lo que dice Genius de esta línea</string>+ <string name="immersive_genius_source">Anotación de Genius</string>+ <plurals name="immersive_genius_upvotes">+ <item quantity="one">%1$d voto positivo</item>+ <item quantity="other">%1$d votos positivos</item>+ </plurals></resources>diff --git a/base/app/src/main/res/values-fr/immersive_genius_strings.xml b/base/app/src/main/res/values-fr/immersive_genius_strings.xmlindex 1bcf67b4..4c7d40ed 100644--- a/base/app/src/main/res/values-fr/immersive_genius_strings.xml+++ b/base/app/src/main/res/values-fr/immersive_genius_strings.xml@@ -2,5 +2,11 @@<resources><string name="immersive_genius_none">Genius n\'a rien sur ce morceau.</string><string name="immersive_genius_error">Genius est injoignable pour le moment.</string>- <string name="immersive_genius_view">Voir sur Genius</string>+ <string name="immersive_genius_read">Lire sur Genius</string>+ <string name="immersive_genius_note_open">Ce que Genius dit de cette ligne</string>+ <string name="immersive_genius_source">Annotation Genius</string>+ <plurals name="immersive_genius_upvotes">+ <item quantity="one">%1$d vote positif</item>+ <item quantity="other">%1$d votes positifs</item>+ </plurals></resources>diff --git a/base/app/src/main/res/values-it/immersive_genius_strings.xml b/base/app/src/main/res/values-it/immersive_genius_strings.xmlindex 56062a07..84e2d900 100644--- a/base/app/src/main/res/values-it/immersive_genius_strings.xml+++ b/base/app/src/main/res/values-it/immersive_genius_strings.xml@@ -2,5 +2,11 @@<resources><string name="immersive_genius_none">Genius non ha nulla su questo brano.</string><string name="immersive_genius_error">Genius non è raggiungibile al momento.</string>- <string name="immersive_genius_view">Vedi su Genius</string>+ <string name="immersive_genius_read">Leggi su Genius</string>+ <string name="immersive_genius_note_open">Cosa dice Genius di questa riga</string>+ <string name="immersive_genius_source">Annotazione di Genius</string>+ <plurals name="immersive_genius_upvotes">+ <item quantity="one">%1$d voto positivo</item>+ <item quantity="other">%1$d voti positivi</item>+ </plurals></resources>diff --git a/base/app/src/main/res/values-pl/immersive_genius_strings.xml b/base/app/src/main/res/values-pl/immersive_genius_strings.xmlindex 7a83de36..daf5a2a6 100644--- a/base/app/src/main/res/values-pl/immersive_genius_strings.xml+++ b/base/app/src/main/res/values-pl/immersive_genius_strings.xml@@ -2,5 +2,4 @@<resources><string name="immersive_genius_none">Genius nie ma nic o tym utworze.</string><string name="immersive_genius_error">Genius jest teraz niedostępny.</string>- <string name="immersive_genius_view">Zobacz w Genius</string></resources>diff --git a/base/app/src/main/res/values-pt/immersive_genius_strings.xml b/base/app/src/main/res/values-pt/immersive_genius_strings.xmlindex 8cef1480..90c28804 100644--- a/base/app/src/main/res/values-pt/immersive_genius_strings.xml+++ b/base/app/src/main/res/values-pt/immersive_genius_strings.xml@@ -2,5 +2,11 @@<resources><string name="immersive_genius_none">O Genius não tem nada sobre esta música.</string><string name="immersive_genius_error">Não foi possível acessar o Genius agora.</string>- <string name="immersive_genius_view">Ver no Genius</string>+ <string name="immersive_genius_read">Ler no Genius</string>+ <string name="immersive_genius_note_open">O que o Genius diz desta linha</string>+ <string name="immersive_genius_source">Anotação do Genius</string>+ <plurals name="immersive_genius_upvotes">+ <item quantity="one">%1$d voto positivo</item>+ <item quantity="other">%1$d votos positivos</item>+ </plurals></resources>diff --git a/base/app/src/main/res/values-ru/immersive_genius_strings.xml b/base/app/src/main/res/values-ru/immersive_genius_strings.xmlindex 851acfb6..1b7969ad 100644--- a/base/app/src/main/res/values-ru/immersive_genius_strings.xml+++ b/base/app/src/main/res/values-ru/immersive_genius_strings.xml@@ -2,5 +2,4 @@<resources><string name="immersive_genius_none">На Genius нет информации об этом треке.</string><string name="immersive_genius_error">Genius сейчас недоступен.</string>- <string name="immersive_genius_view">Открыть на Genius</string></resources>diff --git a/base/app/src/main/res/values-zh/immersive_genius_strings.xml b/base/app/src/main/res/values-zh/immersive_genius_strings.xmlindex 1e31297d..04882677 100644--- a/base/app/src/main/res/values-zh/immersive_genius_strings.xml+++ b/base/app/src/main/res/values-zh/immersive_genius_strings.xml@@ -2,5 +2,4 @@<resources><string name="immersive_genius_none">Genius 上没有关于这首歌的内容。</string><string name="immersive_genius_error">目前无法连接到 Genius。</string>- <string name="immersive_genius_view">在 Genius 上查看</string></resources>diff --git a/base/app/src/main/res/values/immersive_genius_strings.xml b/base/app/src/main/res/values/immersive_genius_strings.xmlindex bb285d12..28be4916 100644--- a/base/app/src/main/res/values/immersive_genius_strings.xml+++ b/base/app/src/main/res/values/immersive_genius_strings.xml@@ -2,5 +2,11 @@<resources><string name="immersive_genius_none">Genius has nothing on this song.</string><string name="immersive_genius_error">Genius can\'t be reached right now.</string>- <string name="immersive_genius_view">View on Genius</string>+ <string name="immersive_genius_read">Read on Genius</string>+ <string name="immersive_genius_note_open">What Genius says about this line</string>+ <string name="immersive_genius_source">Genius annotation</string>+ <plurals name="immersive_genius_upvotes">+ <item quantity="one">%1$d upvote</item>+ <item quantity="other">%1$d upvotes</item>+ </plurals></resources>