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.

The explicit mark beside the song

Lelonio8a2cb31ba830
diff --git a/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt b/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt
index c91a5ce..7e07747 100644
--- a/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt
+++ b/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt
@@ -1634,6 +1634,9 @@ class LibrespotPlayer(
track.albumUri?.let {
putString(dev.lelonio.square.ui.EXTRA_ALBUM_URI, it)
}
+ if (track.explicit) {
+ putBoolean(dev.lelonio.square.ui.EXTRA_EXPLICIT, true)
+ }
val credited = track.artists.filter { it.uri != null }
if (credited.isNotEmpty()) {
putStringArrayList(
diff --git a/app/src/main/java/dev/lelonio/square/playback/PlayQueue.kt b/app/src/main/java/dev/lelonio/square/playback/PlayQueue.kt
index d9a334d..bf0ce20 100644
--- a/app/src/main/java/dev/lelonio/square/playback/PlayQueue.kt
+++ b/app/src/main/java/dev/lelonio/square/playback/PlayQueue.kt
@@ -54,6 +54,13 @@ class PlayQueue {
* between "queued" and "in the playlist" does not.
*/
val queued: Boolean = false,
+ /**
+ * Whether the source rates the track as explicit.
+ *
+ * Carried for the same reason the album is: the queue rebuilds every
+ * item it holds, and what it does not carry never reaches the player.
+ */
+ val explicit: Boolean = false,
)
private val _items = mutableListOf<Track>()
@@ -397,6 +404,7 @@ class PlayQueue {
durationMs = metadata.durationMs ?: 0L,
artworkUri = metadata.artworkUri,
queued = metadata.extras?.getBoolean(EXTRA_PLAY_NEXT) == true,
+ explicit = metadata.extras?.getBoolean(dev.lelonio.square.ui.EXTRA_EXPLICIT) == true,
)
}
}
diff --git a/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt b/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt
index 2a0981e..565f9df 100644
--- a/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt
+++ b/app/src/main/java/dev/lelonio/square/playback/PlaybackService.kt
@@ -1521,6 +1521,9 @@ class PlaybackService : MediaLibraryService() {
track.albumUri?.let {
putString(dev.lelonio.square.ui.EXTRA_ALBUM_URI, it)
}
+ if (track.explicit) {
+ putBoolean(dev.lelonio.square.ui.EXTRA_EXPLICIT, true)
+ }
val credited = track.artists.filter { it.uri != null }
if (credited.isNotEmpty()) {
putStringArrayList(
@@ -1577,6 +1580,7 @@ class PlaybackService : MediaLibraryService() {
albumUri = track.albumUri,
durationMs = track.durationMs,
artworkUri = track.artworkUrl?.let(android.net.Uri::parse),
+ explicit = track.explicit,
)
/** The two parallel lists put back together; see EXTRA_ARTIST_NAMES. */
diff --git a/app/src/main/java/dev/lelonio/square/ui/MainActivity.kt b/app/src/main/java/dev/lelonio/square/ui/MainActivity.kt
index 9111149..bdada47 100644
--- a/app/src/main/java/dev/lelonio/square/ui/MainActivity.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/MainActivity.kt
@@ -421,6 +421,9 @@ class MainActivity : ComponentActivity() {
// And the record, so its name under the title is a
// way in as well.
track.albumUri?.let { putString(EXTRA_ALBUM_URI, it) }
+ // Marked in the player the way every other client
+ // marks it, and only when it is true.
+ if (track.explicit) putBoolean(EXTRA_EXPLICIT, true)
// 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 }
@@ -466,6 +469,9 @@ const val EXTRA_ARTIST_URI = "dev.lelonio.square.ARTIST_URI"
/** The record the playing track is from; see [EXTRA_ARTIST_URI]. */
const val EXTRA_ALBUM_URI = "dev.lelonio.square.ALBUM_URI"
+/** Whether the track carries Spotify's explicit-content rating. */
+const val EXTRA_EXPLICIT = "dev.lelonio.square.EXPLICIT"
+
/** 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/SquareApp.kt b/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt
index f3b20c5..82a7c74 100644
--- a/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt
@@ -3939,6 +3939,7 @@ private fun savedPlaybackSeed(context: android.content.Context): PlaybackState?
album = track.album,
albumUri = track.albumUri,
artworkUrl = track.artworkUrl,
+ explicit = track.explicit,
durationMs = track.durationMs,
// Not "paused": what it is doing is unknown until the controller
// answers, and a play button that flips to pause a moment later reads
diff --git a/app/src/main/java/dev/lelonio/square/ui/components/ExplicitMark.kt b/app/src/main/java/dev/lelonio/square/ui/components/ExplicitMark.kt
new file mode 100644
index 0000000..58ad928
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/components/ExplicitMark.kt
@@ -0,0 +1,53 @@
+package dev.lelonio.square.ui.components
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.LocalContentColor
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.luminance
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+
+/**
+ * The explicit-content rating, as the small square "E" every music app draws
+ * for it.
+ *
+ * In the colour of the line it sits on rather than a colour of its own: it is
+ * a fact about the song, not a warning this app is giving, and the source says
+ * only that the rating is there.
+ */
+@Composable
+fun ExplicitMark(
+ modifier: Modifier = Modifier,
+ color: Color = LocalContentColor.current,
+) {
+ // Black on a light mark and white on a dark one, worked out from the mark
+ // itself: the colour it is drawn in is the colour of whatever line it sits
+ // on, which on a page taken from a record can be anything.
+ val ink = if (color.luminance() > 0.5f) Color.Black else Color.White
+ Box(
+ modifier = modifier.size(SIZE).background(color, RoundedCornerShape(CORNER)),
+ contentAlignment = Alignment.Center,
+ ) {
+ Text(
+ text = "E",
+ style = MaterialTheme.typography.labelSmall,
+ fontSize = TEXT,
+ lineHeight = TEXT,
+ fontWeight = FontWeight.Bold,
+ color = ink,
+ )
+ }
+}
+
+private val SIZE = 15.dp
+private val CORNER = 3.dp
+private val TEXT = 10.sp
diff --git a/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt b/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt
index 25ae77d..87c3503 100644
--- a/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/library/PlaylistScreen.kt
@@ -2601,6 +2601,14 @@ private fun TrackRow(
// read past. Starting a download is the row menu's job, so this
// never needs to be a target.
DownloadMark(download)
+ // The rating before the names, where every other client puts
+ // it, and only on the rows that carry one.
+ if (track.explicit) {
+ dev.lelonio.square.ui.components.ExplicitMark(
+ modifier = Modifier.padding(end = 6.dp),
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ }
Text(
text = subtitle
?: "${track.artist} · ${formatDuration(track.durationMs)}",
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.kt
index ad182c9..367e547 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
@@ -20,6 +20,7 @@ import androidx.compose.animation.core.spring
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.width
import androidx.compose.foundation.border
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.ui.text.font.FontWeight
@@ -1872,7 +1873,17 @@ private fun TitleBlock(
Modifier
},
)
- ArtistLine(state, artist, onOpenArtist)
+ // The rating beside the names rather than on its own line: it is
+ // about the song, and a line of its own would read as a warning.
+ if (state.explicit) {
+ Row(verticalAlignment = Alignment.CenterVertically) {
+ dev.lelonio.square.ui.components.ExplicitMark(color = GlassInk)
+ Spacer(Modifier.width(6.dp))
+ ArtistLine(state, artist, onOpenArtist)
+ }
+ } else {
+ ArtistLine(state, artist, onOpenArtist)
+ }
}
}
}
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.kt
index 8c0b08a..8d40742 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
@@ -36,6 +36,8 @@ data class PlaybackState(
/** And its address, where the queue knows it; see EXTRA_ALBUM_URI. */
val albumUri: String? = null,
val artworkUrl: String? = null,
+ /** Whether the source rates this track as explicit; see EXTRA_EXPLICIT. */
+ val explicit: Boolean = false,
val isPlaying: Boolean = false,
/**
* What the listener asked for, which is not always what is happening.
@@ -201,6 +203,8 @@ fun rememberPlaybackState(
artist = metadata.artist?.toString().orEmpty(),
album = metadata.albumTitle?.toString().orEmpty(),
artworkUrl = metadata.artworkUri?.toString(),
+ explicit = metadata.extras
+ ?.getBoolean(dev.lelonio.square.ui.EXTRA_EXPLICIT) == true,
isPlaying = player.isPlaying,
wantsPlay = player.playWhenReady,
isBuffering = player.playbackState == Player.STATE_BUFFERING,