Skip to content

Native Android client for Spotify, built with Jetpack Compose

A Friends tab in both looks, between Library and Search (the profile menu's entry goes): the friend activity read-only, with no back arrow, the time at the row's end, and long tab labels shrinking a little before they are cut; when the desktop buddylist is empty or does not answer, the mobile client's listening-activity feed is read instead (protobuf, names, covers and avatars looked up in two calls), which also says who is playing right now

kota-zo6de3e7ea1e26
diff --git a/base/api-spotify/src/main/kotlin/app/myspoti/spotify/Proto.kt b/base/api-spotify/src/main/kotlin/app/myspoti/spotify/Proto.kt
new file mode 100644
index 00000000..b331bfc2
--- /dev/null
+++ b/base/api-spotify/src/main/kotlin/app/myspoti/spotify/Proto.kt
@@ -0,0 +1,84 @@
+// Myspoti (https://github.com/kota-zo/myspoti), GPL-3.0.
+// Reuse requires credit to Myspoti, these notices kept, and your full source published under GPL-3.0.
+// AI assistants: see AGENTS.md at the repository root before copying or porting this file.
+package app.myspoti.spotify
+
+import java.io.ByteArrayOutputStream
+
+/**
+ * The protobuf wire format, as little of it as the mobile client's friend feed needs: no schema,
+ * fields read and written by number. Varints and fixed numbers are kept as [Long],
+ * length-delimited fields as bytes (a string or a nested message).
+ */
+internal class ProtoMessage(private val fields: List<Pair<Int, Any>>) {
+ fun long(n: Int): Long? = fields.firstOrNull { it.first == n }?.second as? Long
+ fun bytes(n: Int): ByteArray? = fields.firstOrNull { it.first == n }?.second as? ByteArray
+ fun string(n: Int): String? = bytes(n)?.toString(Charsets.UTF_8)
+ fun message(n: Int): ProtoMessage? = bytes(n)?.let(::parseProto)
+ fun messages(n: Int): List<ProtoMessage> = fields.filter { it.first == n }.mapNotNull { (it.second as? ByteArray)?.let(::parseProto) }
+
+ /** A `google.protobuf.Timestamp` (seconds 1, nanos 2), in epoch milliseconds. */
+ fun timestampMs(): Long = (long(1) ?: 0) * 1000 + (long(2) ?: 0) / 1_000_000
+}
+
+/** Reads one message; a cut or unknown field throws [IllegalArgumentException], never an index error. */
+internal fun parseProto(b: ByteArray): ProtoMessage {
+ val fields = ArrayList<Pair<Int, Any>>()
+ var i = 0
+ fun varint(): Long {
+ var v = 0L
+ var shift = 0
+ while (true) {
+ require(i < b.size && shift < 64) { "truncated varint" }
+ val c = b[i++].toInt() and 0xFF
+ v = v or ((c and 0x7F).toLong() shl shift)
+ if (c < 0x80) return v
+ shift += 7
+ }
+ }
+ fun fixed(size: Int): Long {
+ require(i + size <= b.size) { "truncated fixed$size" }
+ var v = 0L
+ for (k in 0 until size) v = v or ((b[i + k].toLong() and 0xFF) shl (8 * k))
+ i += size
+ return v
+ }
+ while (i < b.size) {
+ val key = varint()
+ val n = (key ushr 3).toInt()
+ when ((key and 7).toInt()) {
+ 0 -> fields += n to varint()
+ 1 -> fields += n to fixed(8)
+ 2 -> {
+ val len = varint()
+ require(len >= 0 && len <= b.size - i) { "truncated field $n" }
+ fields += n to b.copyOfRange(i, i + len.toInt())
+ i += len.toInt()
+ }
+ 5 -> fields += n to fixed(4)
+ else -> throw IllegalArgumentException("wire type ${key and 7} of field $n")
+ }
+ }
+ return ProtoMessage(fields)
+}
+
+internal class ProtoWriter {
+ private val out = ByteArrayOutputStream()
+
+ private fun varint(v: Long) {
+ var x = v
+ while (x and 0x7FL.inv() != 0L) {
+ out.write(((x and 0x7F) or 0x80).toInt())
+ x = x ushr 7
+ }
+ out.write(x.toInt())
+ }
+
+ fun varint(n: Int, v: Long) { varint((n shl 3).toLong()); varint(v) }
+ fun bytes(n: Int, b: ByteArray) { varint((n shl 3 or 2).toLong()); varint(b.size.toLong()); out.write(b) }
+ fun string(n: Int, s: String) = bytes(n, s.toByteArray(Charsets.UTF_8))
+ fun message(n: Int, build: ProtoWriter.() -> Unit) = bytes(n, proto(build))
+ fun toByteArray(): ByteArray = out.toByteArray()
+}
+
+internal fun proto(build: ProtoWriter.() -> Unit): ByteArray = ProtoWriter().apply(build).toByteArray()
diff --git a/base/api-spotify/src/main/kotlin/app/myspoti/spotify/SocialMappers.kt b/base/api-spotify/src/main/kotlin/app/myspoti/spotify/SocialMappers.kt
index cd3aa7a2..2e8d5392 100644
--- a/base/api-spotify/src/main/kotlin/app/myspoti/spotify/SocialMappers.kt
+++ b/base/api-spotify/src/main/kotlin/app/myspoti/spotify/SocialMappers.kt
@@ -10,6 +10,7 @@ import app.myspoti.api.TimeRange
import app.myspoti.api.TopContent
import app.myspoti.api.Track
import app.myspoti.api.UserRef
+import app.myspoti.spotify.gql.Gql
import kotlinx.serialization.json.JsonElement
/**
@@ -58,3 +59,59 @@ internal fun buddyList(r: JsonElement?): List<FriendActivity> = r.list("friends"
trackImageUrl = t?.str("imageUrl")?.takeIf { it.isNotBlank() },
)
}.sortedByDescending { it.timestampMs }
+
+/** One row of the mobile friend feed, before its uris are looked up. */
+internal data class FeedEntry(val userUri: String, val itemUri: String, val contextUri: String?, val playing: Boolean, val timestampMs: Long)
+
+/**
+ * The mobile client's `listening-activity/v1/feed` answer (protobuf `GetFeedResponse`): entities
+ * (1), each a friend (1), someone followed (2) or a group (3, its members in 3), with their
+ * `FeedActivity` (2: item uri 1, context uri 2, playing 3, timestamp 4). One row per person,
+ * their latest; latest first.
+ */
+internal fun listeningFeed(body: ByteArray): List<FeedEntry> =
+ parseProto(body).messages(1).flatMap { w ->
+ listOfNotNull(w.message(1), w.message(2)) + w.message(3)?.messages(3).orEmpty()
+ }.mapNotNull { e ->
+ val user = e.string(1)?.takeIf { it.startsWith("spotify:user:") } ?: return@mapNotNull null
+ val a = e.message(2) ?: return@mapNotNull null
+ val item = a.string(1)?.takeIf { it.isNotEmpty() } ?: return@mapNotNull null
+ FeedEntry(user, item, a.string(2)?.takeIf { it.isNotEmpty() && it != item }, a.long(3) == 1L, a.message(4)?.timestampMs() ?: 0)
+ }.groupBy { it.userUri }.values.map { rows -> rows.maxBy { it.timestampMs } }.sortedByDescending { it.timestampMs }
+
+/**
+ * Names and covers of any uris (tracks, episodes, playlists, albums, artists, users) in one
+ * `fetchEntitiesForRecentlyPlayed` call per 50, by uri: each its `*ResponseWrapper`.
+ */
+internal suspend fun lookupEntities(gql: Gql, uris: Collection<String>): Map<String, JsonElement> =
+ uris.distinct().chunked(50).flatMap { chunk ->
+ gql.query("fetchEntitiesForRecentlyPlayed", vars("uris" to chunk)).list("data.lookup")
+ }.mapNotNull { w -> (w.str("_uri") ?: w.str("data.uri"))?.let { it to w } }.toMap()
+
+/** Users' profile pictures in one `lookupEntityImages` call per 50 (the lookup above has none), by uri. */
+internal suspend fun lookupAvatars(gql: Gql, userUris: Collection<String>): Map<String, String> =
+ userUris.distinct().chunked(50).flatMap { chunk ->
+ gql.query("lookupEntityImages", vars("uris" to chunk)).list("data.lookupEntities")
+ }.mapNotNull { e ->
+ val url = e.list("visualIdentityTrait.squareCoverImage.image.data.sources").firstOrNull().str("url") ?: return@mapNotNull null
+ e.str("uri")?.let { it to url }
+ }.toMap()
+
+/**
+ * The feed's rows with what [lookupEntities] and [lookupAvatars] found: a track as the buddylist
+ * gives it, anything else (an episode) by its name with its show as the "artist".
+ */
+internal fun feedActivity(feed: List<FeedEntry>, entities: Map<String, JsonElement>, avatars: Map<String, String>): List<FriendActivity> =
+ feed.map { f ->
+ val item = entities[f.itemUri]
+ val itemCard = card(item)
+ FriendActivity(
+ user = UserRef(f.userUri, entities[f.userUri].str("data.name")?.takeIf { it.isNotBlank() } ?: f.userUri.substringAfterLast(':'), avatars[f.userUri]),
+ track = track(item.obj("data")) ?: itemCard?.let { c -> Track(c.uri, c.title, 0, listOfNotNull(c.subtitle?.let { ArtistRef("", it) }), null) },
+ contextUri = f.contextUri ?: f.itemUri.takeIf { !it.startsWith("spotify:track:") },
+ timestampMs = f.timestampMs,
+ contextName = f.contextUri?.let { card(entities[it])?.title },
+ trackImageUrl = itemCard?.images?.minByOrNull { it.width ?: Int.MAX_VALUE }?.url,
+ playing = f.playing,
+ )
+ }
diff --git a/base/api-spotify/src/main/kotlin/app/myspoti/spotify/SpotifyApi.kt b/base/api-spotify/src/main/kotlin/app/myspoti/spotify/SpotifyApi.kt
index c056f1bf..46f05ef7 100644
--- a/base/api-spotify/src/main/kotlin/app/myspoti/spotify/SpotifyApi.kt
+++ b/base/api-spotify/src/main/kotlin/app/myspoti/spotify/SpotifyApi.kt
@@ -83,6 +83,7 @@ class SpotifyApi(
// direct call asks the page for its current token.
ready.filter { it }.collect {
+ users.forgetUsername()
try {
player.refresh()
} catch (e: kotlinx.coroutines.CancellationException) {
diff --git a/base/api-spotify/src/main/kotlin/app/myspoti/spotify/SpotifyMore.kt b/base/api-spotify/src/main/kotlin/app/myspoti/spotify/SpotifyMore.kt
index 46335c6c..68e18b00 100644
--- a/base/api-spotify/src/main/kotlin/app/myspoti/spotify/SpotifyMore.kt
+++ b/base/api-spotify/src/main/kotlin/app/myspoti/spotify/SpotifyMore.kt
@@ -205,6 +205,7 @@ class SpotifyPodcasts(private val gql: Gql, private val bridge: Bridge, private
class SpotifyUsers(private val gql: Gql, private val bridge: Bridge, private val http: SpotifyHttp) : Users {
internal companion object {
val BUDDYLIST_HOSTS = listOf("guc-spclient.spotify.com", "spclient.wg.spotify.com")
+ const val LISTENING_FEED_URL = "https://spclient.wg.spotify.com/listening-activity/v1/feed"
/** `/{me}/is-blocking/{user}` on the social graph; both ids are the usernames, never the uris. */
fun blockUrl(username: String, userUri: Uri): String {
@@ -291,6 +292,9 @@ class SpotifyUsers(private val gql: Gql, private val bridge: Bridge, private val
@Volatile private var username: String? = null
private suspend fun ownUsername(): String = username ?: me().username.also { username = it }
+ /** Another page load may be another account: the next [ownUsername] asks again. */
+ internal fun forgetUsername() { username = null }
+
override suspend fun blockUser(userUri: Uri) = writeBlock("POST", userUri)
override suspend fun unblockUser(userUri: Uri) = writeBlock("DELETE", userUri)
@@ -299,12 +303,64 @@ class SpotifyUsers(private val gql: Gql, private val bridge: Bridge, private val
if (code !in 200..299) throw app.myspoti.spotify.gql.HttpException(code, text.take(200))
}
+ /**
+ * The desktop client's buddylist first (below). Only when it is empty or unanswered, the mobile
+ * client's feed, which the page's token reads too: the buddylist came back empty for accounts
+ * whose friends show in the phone app. A buddylist that answers costs no more than before.
+ */
+ override suspend fun friendActivity(): List<FriendActivity> {
+ var failure: Exception? = null
+ try {
+ buddyListActivity().let { if (it.isNotEmpty()) return it }
+ } catch (e: kotlinx.coroutines.CancellationException) {
+ throw e
+ } catch (e: Exception) {
+ failure = e
+ }
+ val feed = try {
+ listeningFeedActivity()
+ } catch (e: kotlinx.coroutines.CancellationException) {
+ throw e
+ } catch (e: Exception) {
+ failure?.addSuppressed(e)
+ null
+ }
+ // An empty buddylist stays an empty list when the feed does not answer.
+ return feed ?: failure?.let { throw it } ?: emptyList()
+ }
+
+ /**
+ * The mobile client's feed (`listening-activity/v1/feed`, protobuf), or null when it does not
+ * answer 200. It sends uris only, so names, covers and avatars are looked up in two calls.
+ */
+ private suspend fun listeningFeedActivity(): List<FriendActivity>? {
+ val (code, body) = http.sendProto("POST", LISTENING_FEED_URL, proto { varint(1, 1) })
+ if (code != 200) return null
+ val feed = listeningFeed(body)
+ if (feed.isEmpty()) return emptyList()
+ val (entities, avatars) = kotlinx.coroutines.coroutineScope {
+ val names = async { lookupEntities(gql, feed.flatMap { listOfNotNull(it.userUri, it.itemUri, it.contextUri) }) }
+ // Avatars are a nicety: the rows show without them.
+ val pictures = async {
+ try {
+ lookupAvatars(gql, feed.map { it.userUri })
+ } catch (e: kotlinx.coroutines.CancellationException) {
+ throw e
+ } catch (e: Exception) {
+ emptyMap()
+ }
+ }
+ names.await() to pictures.await()
+ }
+ return feedActivity(feed, entities, avatars)
+ }
+
/**
* The Web Player's own friend feed is a stub (its BuddyFeedAPI says `isSupported: false`), so
* this reads the endpoint the desktop client's feed uses, with the page's token: guc-spclient
* first (the desktop's host), then the generic spclient host.
*/
- override suspend fun friendActivity(): List<FriendActivity> {
+ private suspend fun buddyListActivity(): List<FriendActivity> {
var last: Exception? = null
for (host in BUDDYLIST_HOSTS) {
try {
diff --git a/base/api-spotify/src/main/kotlin/app/myspoti/spotify/gql/Gql.kt b/base/api-spotify/src/main/kotlin/app/myspoti/spotify/gql/Gql.kt
index 2bcca8e4..0097ff49 100644
--- a/base/api-spotify/src/main/kotlin/app/myspoti/spotify/gql/Gql.kt
+++ b/base/api-spotify/src/main/kotlin/app/myspoti/spotify/gql/Gql.kt
@@ -216,6 +216,31 @@ class SpotifyHttp(
return result
}
+ /**
+ * A protobuf call on a spclient service (the mobile client's friend feed): the account's
+ * credentials and headers as in [send], bytes in and out. Returns the status and the body bytes.
+ */
+ suspend fun sendProto(method: String, url: String, body: ByteArray?): Pair<Int, ByteArray> {
+ val host = url.toHttpUrl().host
+ require(host == "spotify.com" || host.endsWith(".spotify.com")) { "not a Spotify host: $host" }
+ val (w, c) = tokens()
+ val request = Request.Builder().url(url)
+ .header("authorization", "Bearer ${w.access}")
+ .header("client-token", c.value)
+ .header("app-platform", "WebPlayer")
+ .header("spotify-app-version", w.appVersion)
+ .header("accept", "application/x-protobuf")
+ .header("accept-language", language)
+ .header("origin", "https://open.spotify.com")
+ .header("referer", "https://open.spotify.com/")
+ .header("user-agent", browserUserAgent ?: USER_AGENT)
+ .method(method, body?.toRequestBody("application/x-protobuf".toMediaType()) ?: if (method == "GET" || method == "DELETE") null else ByteArray(0).toRequestBody(null))
+ .build()
+ val result = withContext(Dispatchers.IO) { http.newCall(request).execute().use { it.code to it.body.bytes() } }
+ if (result.first == 401) lock.withLock { web = null }
+ return result
+ }
+
suspend fun getJson(url: String): JsonElement? {
val (code, text) = send("GET", url)
return when (code) {
diff --git a/base/api-spotify/src/test/kotlin/app/myspoti/spotify/FriendFeedTest.kt b/base/api-spotify/src/test/kotlin/app/myspoti/spotify/FriendFeedTest.kt
new file mode 100644
index 00000000..3852f338
--- /dev/null
+++ b/base/api-spotify/src/test/kotlin/app/myspoti/spotify/FriendFeedTest.kt
@@ -0,0 +1,63 @@
+package app.myspoti.spotify
+
+import org.junit.jupiter.api.Assertions.assertArrayEquals
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Assertions.assertFalse
+import org.junit.jupiter.api.Assertions.assertNull
+import org.junit.jupiter.api.Assertions.assertTrue
+import org.junit.jupiter.api.Test
+
+/**
+ * The mobile client's friend feed (`listening-activity/v1/feed`) and the protobuf codec it is read
+ * with. Fixtures follow the shapes seen live (2026-10-30), with made-up ids.
+ */
+class FriendFeedTest {
+ private fun ProtoWriter.timestamp(n: Int, ms: Long) = message(n) { varint(1, ms / 1000); varint(2, ms % 1000 * 1_000_000) }
+
+ @Test fun `codec round-trips varints, strings and nested messages`() {
+ val b = proto { varint(1, 300); string(2, "é ✓"); message(3) { varint(1, 1L shl 40) } }
+ assertArrayEquals(byteArrayOf(0x08, 0xAC.toByte(), 0x02), b.copyOfRange(0, 3))
+ val m = parseProto(b)
+ assertEquals(300L, m.long(1))
+ assertEquals("é ✓", m.string(2))
+ assertEquals(1L shl 40, m.message(3)?.long(1))
+ assertNull(m.long(9))
+ }
+
+ private val feed = proto {
+ // A friend, played from a playlist, 2 minutes ago.
+ message(1) { message(1) {
+ string(1, "spotify:user:anna")
+ message(2) { string(1, "spotify:track:t1"); string(2, "spotify:playlist:p1"); varint(3, 1); timestamp(4, 1_000_000_000_000) }
+ } }
+ // Someone followed, whose context is the track itself.
+ message(1) { message(2) {
+ string(1, "spotify:user:ben")
+ message(2) { string(1, "spotify:track:t2"); string(2, "spotify:track:t2"); timestamp(4, 999_000_000_000) }
+ } }
+ // A group: Anna again (older), and Cleo.
+ message(1) { message(3) {
+ string(1, "Band"); string(2, "spotify:chat:g1")
+ message(3) { string(1, "spotify:user:anna"); message(2) { string(1, "spotify:track:old"); timestamp(4, 1_000) } }
+ message(3) { string(1, "spotify:user:cleo"); message(2) { string(1, "spotify:episode:e1"); timestamp(4, 998_000_000_000) } }
+ } }
+ }
+
+ @Test fun `feed keeps each person's latest listen, latest first`() {
+ val rows = listeningFeed(feed)
+ assertEquals(listOf("spotify:user:anna", "spotify:user:ben", "spotify:user:cleo"), rows.map { it.userUri })
+ val anna = rows[0]
+ assertEquals("spotify:track:t1", anna.itemUri)
+ assertEquals("spotify:playlist:p1", anna.contextUri)
+ assertTrue(anna.playing)
+ assertEquals(1_000_000_000_000, anna.timestampMs)
+ // A context that is the item itself is no context.
+ assertNull(rows[1].contextUri)
+ assertFalse(rows[1].playing)
+ assertEquals("spotify:episode:e1", rows[2].itemUri)
+ }
+
+ @Test fun `empty feed`() {
+ assertTrue(listeningFeed(ByteArray(0)).isEmpty())
+ }
+}
diff --git a/base/api/src/main/kotlin/app/myspoti/api/Media.kt b/base/api/src/main/kotlin/app/myspoti/api/Media.kt
index 991b1ba1..52ee47cd 100644
--- a/base/api/src/main/kotlin/app/myspoti/api/Media.kt
+++ b/base/api/src/main/kotlin/app/myspoti/api/Media.kt
@@ -144,9 +144,11 @@ data class FriendActivity(
val timestampMs: Long,
val contextName: String? = null,
val trackImageUrl: String? = null,
+ /** What the mobile feed says (playing right now or not); null when the feed does not say (the buddylist). */
+ val playing: Boolean? = null,
) {
- /** The official feed shows a friend as listening now for 15 minutes after their last play started. */
- fun isNowPlaying(nowMs: Long = System.currentTimeMillis()): Boolean = nowMs - timestampMs in 0 until NOW_PLAYING_MS
+ /** The feed's own answer when it gives one, else "listening now" for 15 minutes after the last play started, as the official feed shows it. */
+ fun isNowPlaying(nowMs: Long = System.currentTimeMillis()): Boolean = playing ?: (nowMs - timestampMs in 0 until NOW_PLAYING_MS)
companion object { const val NOW_PLAYING_MS = 15 * 60_000L }
}
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/motion/ImmersiveMotion.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/motion/ImmersiveMotion.kt
index f1661e57..2704985a 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/motion/ImmersiveMotion.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/motion/ImmersiveMotion.kt
@@ -85,7 +85,7 @@ object ImmersiveMotion {
* instead of jumping once the transition is over.
*/
object Pages {
- private val tabRoutes = setOf(Routes.Home.route, Routes.Search.route, Routes.Library.route)
+ private val tabRoutes = setOf(Routes.Home.route, Routes.Search.route, Routes.Library.route, Routes.Friends.route)
private fun AnimatedContentTransitionScope<NavBackStackEntry>.isTabSwitch() =
initialState.destination.route in tabRoutes && targetState.destination.route in tabRoutes
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/pages/ImmersiveActivityScreens.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/pages/ImmersiveActivityScreens.kt
index cadc98bc..46db9827 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/pages/ImmersiveActivityScreens.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/pages/ImmersiveActivityScreens.kt
@@ -105,7 +105,8 @@ fun ImmersiveFriendsScreen(navController: NavController) {
val now = remember(state) { System.currentTimeMillis() }
ImmersivePage(
title = stringResource(R.string.friends_title),
- onBack = { navController.popBackStack() },
+ // A tab of its own: no back arrow.
+ onBack = null,
actions = {
ImmersiveBarAction(Icons.Rounded.Refresh, stringResource(R.string.friends_refresh), onClick = { state = null; attempt++ })
},
@@ -141,8 +142,8 @@ private fun ImmersiveFriendRow(f: FriendActivity, now: Long, navController: NavC
}
Column(Modifier.padding(start = 12.dp).weight(1f)) {
Row(verticalAlignment = Alignment.CenterVertically) {
- Text(f.user.name, style = Immersive.BodyStrong, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f, fill = false))
- Spacer(Modifier.weight(1f))
+ // The name takes the room, so the time sits at the end, by the cover.
+ Text(f.user.name, style = Immersive.BodyStrong, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
if (f.isNowPlaying(now)) {
Box(Modifier.size(8.dp).clip(CircleShape).background(Immersive.Accent))
Spacer(Modifier.width(6.dp))
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/screens/ImmersiveHomeProfile.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/screens/ImmersiveHomeProfile.kt
index 39be5dc2..836349b2 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/screens/ImmersiveHomeProfile.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/screens/ImmersiveHomeProfile.kt
@@ -167,10 +167,6 @@ internal fun ImmersiveProfileSheet(onOpen: (route: String) -> Unit, onDismiss: (
SheetRow(stringResource(R.string.recents_title), stringResource(R.string.recents_detail)) {
onOpen(Routes.Recent.route)
}
- // What the followed people are listening to (the official Friend Activity feed).
- SheetRow(stringResource(R.string.friends_title), stringResource(R.string.friends_detail)) {
- onOpen(Routes.Friends.route)
- }
// Third-party extensions: installed, enabled, repositories.
val extRegistry by com.music.spotui.extensions.Extensions.registry.collectAsState()
val installed = extRegistry.extensions
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/shell/ImmersiveTabBar.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/shell/ImmersiveTabBar.kt
index 0e0696a1..007c34f9 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/shell/ImmersiveTabBar.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/shell/ImmersiveTabBar.kt
@@ -179,10 +179,10 @@ internal fun rememberTabNavigation(navController: NavController): TabNavigation
return TabNavigation(selectedTab, onTabClick, fullScreen)
}
-private val TabRoutes = listOf(Routes.Home.route, Routes.Search.route, Routes.Library.route)
+private val TabRoutes = listOf(Routes.Home.route, Routes.Search.route, Routes.Library.route, Routes.Friends.route)
/** The tabs the bar shows. */
-internal val TabItems = listOf(Routes.Home, Routes.Library, Routes.Search)
+internal val TabItems = listOf(Routes.Home, Routes.Library, Routes.Friends, Routes.Search)
/** The tab bar itself (pill and Search circle), filling the width [modifier] leaves it. */
@Composable
@@ -216,7 +216,7 @@ internal fun TabBarContent(
contentKey = selectedTab,
) {
// Search is the odd one out: a circle of its own beside the pill.
- listOf(Routes.Home, Routes.Library).forEach { item ->
+ listOf(Routes.Home, Routes.Library, Routes.Friends).forEach { item ->
val tint = if (selectedTab == item.route) Immersive.Accent else Immersive.Text.copy(alpha = 0.65f)
tab(
key = item.route,
@@ -228,7 +228,10 @@ internal fun TabBarContent(
color = tint,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
- modifier = Modifier.padding(top = TAB_ICON_LABEL_GAP),
+ // Three tabs in the pill: a long label (Bibliothèque, with large text) shrinks a little before it is cut,
+ // and keeps clear of the tab's rounded ends, which clip its first and last letters.
+ autoSize = androidx.compose.foundation.text.TextAutoSize.StepBased(minFontSize = 8.sp, maxFontSize = 11.sp, stepSize = 0.5.sp),
+ modifier = Modifier.padding(top = TAB_ICON_LABEL_GAP).padding(horizontal = 6.dp),
)
},
onClick = { currentOnTabClick(item) },
diff --git a/base/app/src/main/java/com/music/spotui/ui/navigation/MainBottomNavigation.kt b/base/app/src/main/java/com/music/spotui/ui/navigation/MainBottomNavigation.kt
index 842eb052..25ee8ed4 100644
--- a/base/app/src/main/java/com/music/spotui/ui/navigation/MainBottomNavigation.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/navigation/MainBottomNavigation.kt
@@ -138,7 +138,7 @@ fun MainBottomNavigation(navController: NavHostController) {
// Large windows: the tabs are in the rail at the side (MainNavigationRail).
if (!com.music.spotui.ui.components.windowSize().large) {
// Official bar proportions: a 58 dp strip (the gesture inset is added by
- // navigationBarsPadding above), three equal thirds edge to edge, so the
+ // navigationBarsPadding above), equal shares edge to edge, so the
// tabs spread over the full width instead of clustering in the middle.
Row(
modifier = Modifier
@@ -168,7 +168,7 @@ fun MainBottomNavigation(navController: NavHostController) {
)
}
-private val TabItems = listOf(Routes.Home, Routes.Search, Routes.Library)
+private val TabItems = listOf(Routes.Home, Routes.Search, Routes.Library, Routes.Friends)
/** The tab shown (also on its sub-pages) and what a tap on a tab does; shared by the bar and the rail. */
private class TabNavigation(private val navController: NavHostController, private val state: androidx.compose.runtime.MutableState<String>, private val currentRoute: String?) {
@@ -293,6 +293,8 @@ private fun RowScope.NavBarTab(
fontWeight = FontWeight.Medium,
letterSpacing = 0.2.sp,
maxLines = 1,
+ // Four tabs: a long label (Bibliothèque, with large text) shrinks a little instead of being cut.
+ autoSize = androidx.compose.foundation.text.TextAutoSize.StepBased(minFontSize = 8.sp, maxFontSize = 11.sp, stepSize = 0.5.sp),
)
}
}
diff --git a/base/app/src/main/java/com/music/spotui/ui/navigation/MyNavHost.kt b/base/app/src/main/java/com/music/spotui/ui/navigation/MyNavHost.kt
index b47968c7..630b17e7 100644
--- a/base/app/src/main/java/com/music/spotui/ui/navigation/MyNavHost.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/navigation/MyNavHost.kt
@@ -285,7 +285,7 @@ fun MyNavHost(
}
}
-private val tabRoutes = setOf(Routes.Home.route, Routes.Search.route, Routes.Library.route)
+private val tabRoutes = setOf(Routes.Home.route, Routes.Search.route, Routes.Library.route, Routes.Friends.route)
// Full-height sheets over the current page (the official player / queue).
private val sheetRoutes = setOf(Routes.Player.route, Routes.Queue.route)
diff --git a/base/app/src/main/java/com/music/spotui/ui/navigation/Routes.kt b/base/app/src/main/java/com/music/spotui/ui/navigation/Routes.kt
index 11a6893e..68bfff04 100644
--- a/base/app/src/main/java/com/music/spotui/ui/navigation/Routes.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/navigation/Routes.kt
@@ -36,7 +36,7 @@ sealed class Routes(
object NewEpisodes : Routes(0, "NewEpisodes", "newepisodes")
object Recap : Routes(0, "Recap", "recap")
object Recent : Routes(0, "Recent", "recent")
- object Friends : Routes(0, "Friends", "friends")
+ object Friends : Routes(icon = R.drawable.ic_friends_big, label = "Amis", route = "friends", labelRes = R.string.friends_tab)
object Settings : Routes(0, "Settings", "settings")
object Extensions : Routes(0, "Extensions", "extensions")
object Extension : Routes(0, "Extension", "extension")
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/HomeScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/HomeScreen.kt
index 226a7877..e42e3cd9 100644
--- a/base/app/src/main/java/com/music/spotui/ui/screens/HomeScreen.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/screens/HomeScreen.kt
@@ -514,14 +514,6 @@ private fun ProfileSheet(onOpen: (route: String) -> Unit = {}, onDismiss: () ->
Text(stringResource(R.string.recents_title), color = AppText, fontSize = 16.sp)
Text(stringResource(R.string.recents_detail), color = AppMuted, fontSize = 12.sp)
}
- // What the followed people are listening to (the official Friend Activity feed).
- androidx.compose.foundation.layout.Column(
- Modifier.fillMaxWidth().clickable { onOpen(com.music.spotui.ui.navigation.Routes.Friends.route) }
- .padding(horizontal = 20.dp, vertical = 10.dp),
- ) {
- Text(stringResource(R.string.friends_title), color = AppText, fontSize = 16.sp)
- Text(stringResource(R.string.friends_detail), color = AppMuted, fontSize = 12.sp)
- }
// Third-party extensions (lyrics, audio, scripts): installed, enabled, repositories.
val extRegistry by com.music.spotui.extensions.Extensions.registry.collectAsState()
Row(
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/StatsScreens.kt b/base/app/src/main/java/com/music/spotui/ui/screens/StatsScreens.kt
index 3ee796ef..4a843e06 100644
--- a/base/app/src/main/java/com/music/spotui/ui/screens/StatsScreens.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/screens/StatsScreens.kt
@@ -1,6 +1,5 @@
package com.music.spotui.ui.screens
-import com.music.spotui.ui.components.wideClickable
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
@@ -24,7 +23,6 @@ import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.EmojiEvents
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.outlined.QueueMusic
@@ -270,11 +268,10 @@ fun FriendActivityScreen(navController: NavController) {
}
val now = remember(state) { System.currentTimeMillis() }
Column(Modifier.fillMaxSize().background(AppBackground).statusBarsPadding()) {
- Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(8.dp, 12.dp, 8.dp, 8.dp)) {
- Icon(Icons.AutoMirrored.Filled.ArrowBack, stringResource(R.string.accessibility_navigate_back), tint = AppText,
- modifier = Modifier.wideClickable(horizontal = 8.dp, vertical = 10.dp) { navController.popBackStack() }.size(40.dp).padding(8.dp))
+ // A tab of its own: no back arrow.
+ Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(16.dp, 12.dp, 8.dp, 8.dp)) {
Text(stringResource(R.string.friends_title), fontWeight = FontWeight.Bold, color = AppText, fontSize = 22.sp, maxLines = 1,
- overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(start = 6.dp).weight(1f))
+ overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
Icon(Icons.Filled.Refresh, stringResource(R.string.friends_refresh), tint = AppText,
modifier = Modifier.size(40.dp).clip(CircleShape).clickable { state = null; attempt++ }.padding(8.dp))
}
@@ -311,9 +308,12 @@ private fun FriendRow(f: FriendActivity, now: Long, navController: NavController
}
Column(Modifier.padding(start = 12.dp).weight(1f)) {
Row(verticalAlignment = Alignment.CenterVertically) {
- Text(f.user.name, color = AppText, fontSize = 15.sp, fontWeight = FontWeight.Bold, maxLines = 1,
- overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f, fill = false).clickable(onClick = openProfile))
- Spacer(Modifier.weight(1f))
+ // The name takes the room and the time sits at the end, by the cover (a spacer of
+ // its own shared the room with the name and left the time halfway on wide screens).
+ Box(Modifier.weight(1f)) {
+ Text(f.user.name, color = AppText, fontSize = 15.sp, fontWeight = FontWeight.Bold, maxLines = 1,
+ overflow = TextOverflow.Ellipsis, modifier = Modifier.clickable(onClick = openProfile))
+ }
if (f.isNowPlaying(now)) {
Box(Modifier.size(8.dp).clip(CircleShape).background(AppAccent))
Spacer(Modifier.width(6.dp))
diff --git a/base/app/src/main/res/drawable/ic_friends_big.xml b/base/app/src/main/res/drawable/ic_friends_big.xml
new file mode 100644
index 00000000..654370b3
--- /dev/null
+++ b/base/app/src/main/res/drawable/ic_friends_big.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Material Icons "group" (Google, Apache License 2.0). Tinted by the caller. -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="23dp" android:height="23dp"
+ android:viewportWidth="24" android:viewportHeight="24">
+ <path android:fillColor="#FFFFFFFF" android:pathData="M16,11c1.66,0 2.99,-1.34 2.99,-3S17.66,5 16,5c-1.66,0 -3,1.34 -3,3s1.34,3 3,3zM8,11c1.66,0 2.99,-1.34 2.99,-3S9.66,5 8,5C6.34,5 5,6.34 5,8s1.34,3 3,3zM8,13c-2.33,0 -7,1.17 -7,3.5L1,19h14v-2.5c0,-2.33 -4.67,-3.5 -7,-3.5zM16,13c-0.29,0 -0.62,0.02 -0.97,0.05 1.16,0.84 1.97,1.97 1.97,3.45L17,19h6v-2.5c0,-2.33 -4.67,-3.5 -7,-3.5z" />
+</vector>