Skip to content

Native Android client for Spotify, built with Jetpack Compose

TV screenshots on the computer (TvScreenshotTest: Robolectric draws Home, a list, Search, an artist, the player and the device list at 1920x1080 with made-up data, Roborazzi saves them to app/build/outputs/roborazzi); what they showed fixed: smaller cards so a shelf shows more than three and a half, the player's cover at 260 dp so its seek bar fits on the screen, Shuffle instead of Shuffle: on under a list

kota-zof5cf847d2aa9
diff --git a/base/app/build.gradle.kts b/base/app/build.gradle.kts
index 02caa75d..6ee1b9e1 100644
--- a/base/app/build.gradle.kts
+++ b/base/app/build.gradle.kts
@@ -19,6 +19,12 @@ val RELEASE_ABIS = listOf("arm64-v8a", "armeabi-v7a")
val ABI_NAMES = mapOf("arm64-v8a" to "ARMv8", "armeabi-v7a" to "ARMv7")
android {
+ testOptions {
+ unitTests {
+ isIncludeAndroidResources = true
+ all { it.systemProperty("roborazzi.test.record", "true") }
+ }
+ }
namespace = "app.myspoti.engine"
compileSdk = 37
@@ -187,6 +193,14 @@ dependencies {
implementation("androidx.media3:media3-datasource:1.8.0")
implementation("androidx.media3:media3-database:1.8.0")
+ // Screenshots of the TV screens on the computer (TvScreenshotTest): Robolectric draws them, Roborazzi saves them.
+ testImplementation("org.robolectric:robolectric:4.14.1")
+ testImplementation("io.github.takahirom.roborazzi:roborazzi:1.40.1")
+ testImplementation("io.github.takahirom.roborazzi:roborazzi-compose:1.40.1")
+ testImplementation(platform(libs.compose.bom))
+ testImplementation("androidx.compose.ui:ui-test-junit4")
+ debugImplementation("androidx.compose.ui:ui-test-manifest")
+
diff --git a/base/app/src/main/java/com/music/spotui/ui/tv/TvApp.kt b/base/app/src/main/java/com/music/spotui/ui/tv/TvApp.kt
index 69e20e07..df1c6269 100644
--- a/base/app/src/main/java/com/music/spotui/ui/tv/TvApp.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/tv/TvApp.kt
@@ -183,8 +183,8 @@ internal fun TvHomeShelves(greeting: String, feedSections: List<HomeSection>, on
itemsIndexed(section.items, key = { j, it -> "$j:${it.name}:${it.imageUrl}" }) { j, item ->
val focus = if (lead && j == 0) Modifier.focusRequester(first) else Modifier
val page = item.page(likedName) ?: return@itemsIndexed
- if (lead) TvGradientCard(item.name, item.subtitleText(), item.imageUrl, 240.dp, focus) { onOpen(page) }
- else TvAlbumCard(item.name, item.subtitleText(), item.imageUrl, 160.dp, round = item is HomeItem.Artist, modifier = focus) { onOpen(page) }
+ if (lead) TvGradientCard(item.name, item.subtitleText(), item.imageUrl, 200.dp, focus) { onOpen(page) }
+ else TvAlbumCard(item.name, item.subtitleText(), item.imageUrl, 140.dp, round = item is HomeItem.Artist, modifier = focus) { onOpen(page) }
}
}
}
@@ -247,7 +247,7 @@ private fun TvGrid(entries: List<LibraryEntry>, modifier: Modifier = Modifier, o
LazyVerticalGrid(GridCells.Adaptive(176.dp), modifier, contentPadding = PaddingValues(horizontal = 48.dp, vertical = 20.dp),
horizontalArrangement = Arrangement.spacedBy(20.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {
itemsIndexed(entries, key = { _, it -> it.uri.ifEmpty { it.folderUri.ifEmpty { it.spotifyId } } }) { i, e ->
- TvAlbumCard(e.name, e.subtitle, e.coverUri, 160.dp, round = ":artist:" in e.uri, modifier = if (i == 0) Modifier.focusRequester(first) else Modifier) { onClick(e) }
+ TvAlbumCard(e.name, e.subtitle, e.coverUri, 150.dp, round = ":artist:" in e.uri, modifier = if (i == 0) Modifier.focusRequester(first) else Modifier) { onClick(e) }
}
}
LaunchedEffect(entries) { runCatching { delay(80); first.requestFocus() } }
@@ -316,7 +316,7 @@ internal fun TvSearchResults(f: SearchResults, onOpen: (TvPage) -> Unit, onSong:
if (artists.isNotEmpty()) item("artists") {
TvShelf(stringResource(R.string.assisted_curation_search_filter_artists)) {
itemsIndexed(artists, key = { i, a -> "$i:${a.id}" }) { _, a ->
- TvAlbumCard(a.name, "", a.coverUri, 150.dp, round = true) { onOpen(TvPage.Artist(a.id, a.name)) }
+ TvAlbumCard(a.name, "", a.coverUri, 130.dp, round = true) { onOpen(TvPage.Artist(a.id, a.name)) }
}
}
}
@@ -324,7 +324,7 @@ internal fun TvSearchResults(f: SearchResults, onOpen: (TvPage) -> Unit, onSong:
if (albums.isNotEmpty()) item("albums") {
TvShelf(stringResource(R.string.assisted_curation_search_filter_albums)) {
itemsIndexed(albums, key = { i, a -> "$i:${a.spotifyId}" }) { _, a ->
- TvAlbumCard(a.name, a.artists, a.coverUri, 160.dp) {
+ TvAlbumCard(a.name, a.artists, a.coverUri, 140.dp) {
onOpen(TvPage.Songs(LibraryEntry(a.spotifyId, a.name, a.artists, a.coverUri, isPlaylist = false, uri = "spotify:album:${a.spotifyId}")))
}
}
@@ -333,7 +333,7 @@ internal fun TvSearchResults(f: SearchResults, onOpen: (TvPage) -> Unit, onSong:
if (f.playlists.isNotEmpty()) item("playlists") {
TvShelf(stringResource(R.string.assisted_curation_search_filter_playlists)) {
itemsIndexed(f.playlists, key = { i, e -> "$i:${e.uri}" }) { _, e ->
- TvAlbumCard(e.name, e.subtitle, e.coverUri, 160.dp) { onOpen(TvPage.Songs(e)) }
+ TvAlbumCard(e.name, e.subtitle, e.coverUri, 140.dp) { onOpen(TvPage.Songs(e)) }
}
}
}
@@ -341,7 +341,7 @@ internal fun TvSearchResults(f: SearchResults, onOpen: (TvPage) -> Unit, onSong:
if (shows.isNotEmpty()) item("shows") {
TvShelf(stringResource(R.string.assisted_curation_search_filter_podcasts)) {
itemsIndexed(shows, key = { i, sh -> "$i:${sh.id}" }) { _, sh ->
- TvAlbumCard(sh.name, sh.publisher, sh.coverUri, 160.dp) { onOpen(TvPage.Show(sh.id, sh.name)) }
+ TvAlbumCard(sh.name, sh.publisher, sh.coverUri, 140.dp) { onOpen(TvPage.Show(sh.id, sh.name)) }
}
}
}
@@ -395,7 +395,7 @@ internal fun TvSongsPage(entry: LibraryEntry, p: ContextPageModel, onPlay: () ->
if (owner.isNotBlank()) Text(owner, color = TvAccent, fontSize = 16.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
Row(Modifier.padding(top = 18.dp), horizontalArrangement = Arrangement.spacedBy(12.dp)) {
TvPillButton(Icons.Default.PlayArrow, stringResource(R.string.immersive_player_play), filled = true, modifier = Modifier.focusRequester(playFocus), onClick = onPlay)
- TvPillButton(Icons.Default.Shuffle, stringResource(R.string.immersive_player_shuffle_on), filled = false, onClick = onShuffle)
+ TvPillButton(Icons.Default.Shuffle, stringResource(R.string.immersive_shell_shuffle), filled = false, onClick = onShuffle)
}
}
LazyColumn(Modifier.weight(1f), contentPadding = PaddingValues(bottom = 40.dp), verticalArrangement = Arrangement.spacedBy(2.dp)) {
diff --git a/base/app/src/main/java/com/music/spotui/ui/tv/TvNowPlaying.kt b/base/app/src/main/java/com/music/spotui/ui/tv/TvNowPlaying.kt
index b78acada..d1d4a2ca 100644
--- a/base/app/src/main/java/com/music/spotui/ui/tv/TvNowPlaying.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/tv/TvNowPlaying.kt
@@ -177,7 +177,7 @@ internal fun TvPlayerScreen(
TvClock(Modifier.align(Alignment.TopEnd).padding(end = 32.dp, top = 18.dp).graphicsLayer { alpha = chromeAlpha })
- Row(Modifier.fillMaxSize().padding(horizontal = 72.dp, vertical = 48.dp), horizontalArrangement = Arrangement.spacedBy(64.dp)) {
+ Row(Modifier.fillMaxSize().padding(horizontal = 72.dp, vertical = 36.dp), horizontalArrangement = Arrangement.spacedBy(64.dp)) {
Column(
Modifier.width(380.dp).fillMaxHeight().graphicsLayer {
// Idle, the controls still hold their space: the group eases down a little so the
@@ -190,7 +190,7 @@ internal fun TvPlayerScreen(
horizontalAlignment = Alignment.CenterHorizontally,
) {
Crossfade(state.coverUrl, animationSpec = tween(800), label = "cover") { url ->
- TvCover(url, Modifier.size(320.dp), RoundedCornerShape(18.dp))
+ TvCover(url, Modifier.size(260.dp), RoundedCornerShape(18.dp))
}
Spacer(Modifier.height(18.dp))
TvMarquee(state.title, 26.sp, FontWeight.Bold, Color.White)
diff --git a/base/app/src/main/java/com/music/spotui/ui/tv/TvPages.kt b/base/app/src/main/java/com/music/spotui/ui/tv/TvPages.kt
index e98b02d2..637fed3a 100644
--- a/base/app/src/main/java/com/music/spotui/ui/tv/TvPages.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/tv/TvPages.kt
@@ -144,7 +144,7 @@ internal fun TvArtistPage(o: ArtistOverviewModel, onOpen: (TvPage) -> Unit, onPl
if (releases.isNotEmpty()) item("releases") {
TvShelf(stringResource(R.string.popular_releases_section_title)) {
itemsIndexed(releases, key = { i, a -> "$i:${a.spotifyId}" }) { _, a ->
- TvAlbumCard(a.name, a.year, a.coverUri, 160.dp) {
+ TvAlbumCard(a.name, a.year, a.coverUri, 140.dp) {
onOpen(TvPage.Songs(LibraryEntry(a.spotifyId, a.name, a.artists, a.coverUri, isPlaylist = false, uri = "spotify:album:${a.spotifyId}")))
}
}
@@ -154,7 +154,7 @@ internal fun TvArtistPage(o: ArtistOverviewModel, onOpen: (TvPage) -> Unit, onPl
if (related.isNotEmpty()) item("related") {
TvShelf(stringResource(R.string.fans_also_like_section_title)) {
itemsIndexed(related, key = { i, a -> "$i:${a.id}" }) { _, a ->
- TvAlbumCard(a.name, "", a.coverUri, 150.dp, round = true) { onOpen(TvPage.Artist(a.id, a.name)) }
+ TvAlbumCard(a.name, "", a.coverUri, 130.dp, round = true) { onOpen(TvPage.Artist(a.id, a.name)) }
}
}
}
diff --git a/base/app/src/main/java/com/music/spotui/ui/tv/TvParts.kt b/base/app/src/main/java/com/music/spotui/ui/tv/TvParts.kt
index 04933af9..6b584514 100644
--- a/base/app/src/main/java/com/music/spotui/ui/tv/TvParts.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/tv/TvParts.kt
@@ -227,8 +227,8 @@ internal fun TvShelfSkeleton(rows: Int = 3) {
val a by t.animateFloat(0.05f, 0.16f, infiniteRepeatable(tween(900, easing = LinearEasing), RepeatMode.Reverse), label = "a")
val bar = Color.White.copy(alpha = a)
Column(Modifier.fillMaxSize().padding(top = 20.dp), verticalArrangement = Arrangement.spacedBy(28.dp)) {
- SkeletonRow(bar, 210.dp, 5)
- repeat(rows) { SkeletonRow(bar, 150.dp, 7) }
+ SkeletonRow(bar, 200.dp, 5)
+ repeat(rows) { SkeletonRow(bar, 140.dp, 7) }
}
}
diff --git a/base/app/src/test/java/com/music/spotui/ui/tv/TvScreenshotTest.kt b/base/app/src/test/java/com/music/spotui/ui/tv/TvScreenshotTest.kt
new file mode 100644
index 00000000..101c5132
--- /dev/null
+++ b/base/app/src/test/java/com/music/spotui/ui/tv/TvScreenshotTest.kt
@@ -0,0 +1,138 @@
+/* SPDX-License-Identifier: GPL-3.0-only */
+package com.music.spotui.ui.tv
+
+import android.app.Application
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.padding
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.test.junit4.createComposeRule
+import androidx.compose.ui.test.onRoot
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import com.github.takahirom.roborazzi.captureRoboImage
+import com.music.spotui.data.entity.AlbumsModel
+import com.music.spotui.data.entity.ArtistOverviewModel
+import com.music.spotui.data.entity.ArtistTrackUi
+import com.music.spotui.data.entity.ArtistsModel
+import com.music.spotui.data.entity.ContextPageModel
+import com.music.spotui.data.entity.HomeItem
+import com.music.spotui.data.entity.HomeSection
+import com.music.spotui.data.entity.LibraryEntry
+import com.music.spotui.data.entity.SearchResults
+import com.music.spotui.data.entity.SongsModel
+import com.music.spotui.di.SongPlayer
+import com.music.spotui.ui.immersive.player.ImmersivePlayerActions
+import com.music.spotui.ui.immersive.player.ImmersivePlayerState
+import com.music.spotui.ui.immersive.player.ImmersiveRepeat
+import com.music.spotui.ui.look.MeshPalette
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+import org.robolectric.annotation.Config
+import org.robolectric.annotation.GraphicsMode
+
+/**
+ * The TV screens drawn on the computer at 1920×1080, with made-up data and no network: the covers
+ * stay as placeholders. Run with `./gradlew :app:testDebugUnitTest --tests '*TvScreenshotTest*'`;
+ * the images land in app/build/outputs/roborazzi/.
+ */
+@RunWith(RobolectricTestRunner::class)
+@GraphicsMode(GraphicsMode.Mode.NATIVE)
+@Config(sdk = [35], qualifiers = "w960dp-h540dp-land-television-xhdpi", application = Application::class)
+class TvScreenshotTest {
+ @get:Rule val rule = createComposeRule()
+
+ private fun shoot(name: String, content: @Composable () -> Unit) {
+ // The player never idles (its clock, the marquee, the playhead): time is moved by hand.
+ rule.mainClock.autoAdvance = false
+ rule.setContent(content)
+ rule.mainClock.advanceTimeBy(1_000)
+ rule.onRoot().captureRoboImage("build/outputs/roborazzi/tv-$name.png")
+ }
+
+ private fun song(i: Int, title: String, artist: String) =
+ SongsModel(i, title, "Album", artist, "", "spotify:track:$i", durationMs = 180_000 + i * 7_000)
+
+ private val songs = listOf(
+ song(1, "Midnight City", "M83"), song(2, "Breathe Deeper", "Tame Impala"), song(3, "Nightcall", "Kavinsky"),
+ song(4, "Instant Crush", "Daft Punk, Julian Casablancas"), song(5, "Electric Feel", "MGMT"), song(6, "Redbone", "Childish Gambino"),
+ song(7, "The Less I Know the Better", "Tame Impala"), song(8, "Kids", "MGMT"), song(9, "Genesis", "Justice"), song(10, "Odd Look", "Kavinsky, The Weeknd"),
+ )
+
+ private fun playlists(n: Int, prefix: String) = List(n) { HomeItem.Playlist("$prefix ${it + 1}", "", "Mix of the week", id = "pl$prefix$it") }
+
+ @Test fun home() = shoot("home") {
+ TvFrame(TvTab.Home, {}) {
+ TvHomeShelves("Good evening", listOf(
+ HomeSection("", playlists(6, "Daily Mix")),
+ HomeSection("Made for you", playlists(9, "Discover")),
+ HomeSection("Recently played", playlists(9, "Radio")),
+ )) {}
+ }
+ }
+
+ @Test fun list() = shoot("list") {
+ val entry = LibraryEntry("pl1", "Night Drive", "Myspoti", "", isPlaylist = true, uri = "spotify:playlist:pl1")
+ TvFrame(TvTab.Library, {}) {
+ TvSongsPage(entry, ContextPageModel("spotify:playlist:pl1", "playlist", "Night Drive", "", ownerName = "Myspoti", tracks = songs), {}, {}, {})
+ }
+ }
+
+ @Test fun search() = shoot("search") {
+ TvFrame(TvTab.Search, {}) {
+ TvSearchResults(SearchResults(
+ songs = songs.take(8),
+ artists = listOf("M83", "Tame Impala", "Kavinsky", "MGMT", "Justice", "Daft Punk", "Air").mapIndexed { i, n -> ArtistsModel(n, "", id = "a$i") },
+ albums = List(8) { AlbumsModel(it, "M83", "", "Album ${it + 1}", "2011", spotifyId = "al$it") },
+ ), {}, {})
+ }
+ }
+
+ @Test fun artist() = shoot("artist") {
+ TvFrame(TvTab.Search, {}) {
+ TvArtistPage(ArtistOverviewModel(
+ id = "a1", name = "Tame Impala", monthlyListeners = 31_245_871,
+ topTracks = songs.map { ArtistTrackUi(it) },
+ popularReleases = List(8) { AlbumsModel(it, "Tame Impala", "", "Release ${it + 1}", "2020", spotifyId = "r$it") },
+ relatedArtists = listOf("MGMT", "Pond", "Unknown Mortal Orchestra", "Mac DeMarco").mapIndexed { i, n -> ArtistsModel(n, "", id = "r$i") },
+ ), {}, {})
+ }
+ }
+
+ @Test fun player() = shoot("player") {
+ TvFrame(TvTab.NowPlaying, {}) {
+ TvPlayerScreen(
+ ImmersivePlayerState(title = "Breathe Deeper", artist = "Tame Impala", playing = true, positionMs = { 74_000L }, durationMs = 372_000L,
+ shuffle = true, repeatMode = ImmersiveRepeat.ALL, liked = true),
+ ImmersivePlayerActions(),
+ MeshPalette(listOf(Color(0xFF5B2A86), Color(0xFFC04A7A), Color(0xFF1F3B73), Color(0xFFE08A4F))),
+ onArtist = {}, onDevices = {},
+ ) { _, modifier -> FakeLyrics(modifier) }
+ }
+ }
+
+ @Test fun devices() = shoot("devices") {
+ TvDevicesList(listOf(
+ SongPlayer.ConnectDevice("1", "Salon TV", "TV", isSelf = true, isActive = false),
+ SongPlayer.ConnectDevice("2", "Pixel 9", "SMARTPHONE", isSelf = false, isActive = true),
+ SongPlayer.ConnectDevice("3", "Kitchen speaker", "CAST_AUDIO", isSelf = false, isActive = false),
+ )) {}
+ }
+
+ /** Stands in for the lyrics panel, which needs the engine. */
+ @Composable
+ private fun FakeLyrics(modifier: Modifier) {
+ Column(modifier.padding(top = 40.dp)) {
+ listOf("I don't know where I'm going", "But I know I'm on my way", "Breathe deeper, feel the night", "Every colour in the light", "We could stay here")
+ .forEachIndexed { i, line ->
+ Text(line, color = Color.White.copy(alpha = if (i == 2) 1f else 0.35f), fontSize = 34.sp, fontWeight = FontWeight.Bold,
+ modifier = Modifier.padding(vertical = 12.dp))
+ }
+ }
+ }
+}