Skip to content

Native Android client for Spotify, built with Jetpack Compose

Android TV in the look of Apple Music TV (JObersi10/apple-music-tv, GPL-3.0, its UI only): a floating pill of tabs (Home, Your Library, Search, Now Playing), Home's shelves as rows of covers with a big first one, cards that grow with a white halo on focus, a list's page with its cover, Play and Shuffle beside its songs, and a full-screen player over the cover's colours with shuffle, repeat, like, a seek bar the D-pad moves by 10 s, the synced lyrics on the right and controls that fade when idle; Material icons, no new library, credited in THIRD_PARTY_NOTICES

kota-zof32ccef5e60f
diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md
index c750b607..a2d7c73c 100644
--- a/THIRD_PARTY_NOTICES.md
+++ b/THIRD_PARTY_NOTICES.md
@@ -68,6 +68,24 @@ Code that BitChord itself carries from other projects, kept with its own header:
(https://github.com/EchoMusicApp/Echo-Music), GPL-3.0. The lens of `shell/GlassSelectionPill.kt` and
the minimizing chrome of `shell/ImmersiveChrome.kt` follow BitChord's `floatingtabbar/` files.
+## Apple Music TV — GPL-3.0
+https://github.com/JObersi10/apple-music-tv (commit `7e5c594`)
+
+By JObersi10. The Android TV look is ported from it. These files in
+`base/app/src/main/java/com/music/spotui/ui/tv/` are adapted from its
+`android/app/src/main/java/com/applemusicktv/ui/` files, stay under the GPL-3.0, and say so in
+their header:
+
+- `TvParts.kt`, from `components/TopNavBar.kt`, `AlbumCard.kt`, `SpotlightCards.kt` (GradientCard)
+ and `Skeleton.kt` (the floating tab pill, the focus scale, halo and border of the cards, the shelf skeleton)
+- `TvApp.kt`, from `AppShell.kt`, `screens/HomeScreen.kt` and `screens/PlaylistDetailScreen.kt`
+ (the shell, Home's shelves, a list's page)
+- `TvNowPlaying.kt`, from `screens/NowPlayingScreen.kt` (the full-screen player, its idle mode and
+ the D-pad seek bar)
+
+Only its UI is used: none of its playback, Widevine or network code, and none of its icons (Apple's
+SF Symbols), images or brand.
+
## Backdrop — Apache-2.0
https://github.com/Kyant0/backdrop (v2.0.0, `io.github.kyant0:backdrop`), Copyright 2025 Kyant0.
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 0042f011..147f09aa 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
@@ -1,4 +1,13 @@
-/* SPDX-License-Identifier: GPL-3.0-only */
+/*
+ * The shell, Home shelves and list page follow Apple Music TV
+ * (https://github.com/JObersi10/apple-music-tv), GPL-3.0, android/app/src/main/java/com/applemusicktv/ui/
+ * AppShell.kt, screens/HomeScreen.kt and screens/PlaylistDetailScreen.kt at 7e5c594.
+ * Modified for Myspoti, 2026-11.
+ *
+ * Changes: Myspoti's own data (Home feed, Your Library, search, lists) and engine; one stack of
+ * lists over the open tab instead of a navigation graph; no onboarding, video, radio, settings
+ * or update checks (those stay on the phone).
+ */
package com.music.spotui.ui.tv
import android.app.UiModeManager
@@ -7,15 +16,12 @@ import android.content.pm.PackageManager
import android.content.res.Configuration
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
-import androidx.compose.foundation.border
-import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
-import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
@@ -23,57 +29,64 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
-import androidx.compose.foundation.lazy.grid.items
+import androidx.compose.foundation.lazy.grid.itemsIndexed
import androidx.compose.foundation.lazy.items
+import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.PlayArrow
+import androidx.compose.material.icons.filled.Shuffle
+import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
+import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
-import androidx.compose.ui.draw.clip
-import androidx.compose.ui.draw.scale
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
-import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
-import androidx.compose.ui.semantics.contentDescription
-import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
-import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
-import com.bumptech.glide.integration.compose.GlideImage
+import androidx.lifecycle.viewmodel.compose.viewModel
import app.myspoti.engine.R
+import com.music.spotui.data.api.Api
import com.music.spotui.data.api.Response
import com.music.spotui.data.entity.ContextPageModel
+import com.music.spotui.data.entity.HomeItem
import com.music.spotui.data.entity.LibraryEntry
import com.music.spotui.data.entity.SongsModel
+import com.music.spotui.data.entity.withoutDj
import com.music.spotui.di.Graph
import com.music.spotui.di.SongPlayer
+import com.music.spotui.ui.viewmodel.HomeViewModel
+import com.music.spotui.ui.viewmodel.PlayerViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.first
/**
- * Android TV: a short version of the app for the remote. Your Library and Liked Songs, search, a
- * list's songs and the player's transport; everything moves with the D-pad (the focused item is
- * outlined and a little bigger) and Back goes up a level. The rest of the app (settings, extensions,
- * downloads, lyrics) stays on the phone; playback, extensions and Connect are the same engine.
+ * Android TV: a version of the app made for the remote. A floating bar of tabs (Home, Your
+ * Library, Search, Now Playing) over shelves of covers; a list opens over its tab and Back closes
+ * it; a song played goes to the full-screen player. Settings, extensions and downloads stay on the
+ * phone; playback, extensions and Connect are the same engine.
*/
object Tv {
/** A TV (leanback) device, or a phone or tablet in TV mode. */
@@ -82,57 +95,101 @@ object Tv {
context.packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
}
-private val Bg = Color(0xFF0E0E10)
-private val Card = Color(0xFF1C1C21)
-private val Accent = Color(0xFF1ED760)
-private val Dim = Color.White.copy(alpha = 0.65f)
+@Composable
+fun TvApp() {
+ var tab by remember { mutableStateOf(TvTab.Home) }
+ // The tab the player was opened from, for Back.
+ var from by remember { mutableStateOf(TvTab.Home) }
+ val lists = remember { mutableStateListOf<LibraryEntry>() }
+ fun select(t: TvTab) {
+ if (t == TvTab.NowPlaying && tab != TvTab.NowPlaying) from = tab
+ lists.clear()
+ tab = t
+ }
+ val open: (LibraryEntry) -> Unit = { lists += it }
+ val played: () -> Unit = { select(TvTab.NowPlaying) }
+
+ BackHandler(enabled = lists.isNotEmpty()) { lists.removeAt(lists.lastIndex) }
+ BackHandler(enabled = lists.isEmpty() && tab == TvTab.NowPlaying) { tab = from }
+ BackHandler(enabled = lists.isEmpty() && (tab == TvTab.Library || tab == TvTab.Search)) { tab = TvTab.Home }
-/** What the screen shows: a tab, or one list opened from it. */
-private sealed interface TvPage {
- data object Library : TvPage
- data object Search : TvPage
- data class List(val entry: LibraryEntry) : TvPage
+ val labels = mapOf(
+ TvTab.Home to stringResource(R.string.navigationbar_musicappitems_home_title),
+ TvTab.Library to stringResource(R.string.aa_library),
+ TvTab.Search to stringResource(R.string.navigationbar_musicappitems_search_title),
+ TvTab.NowPlaying to stringResource(R.string.immersive_shell_now_playing),
+ )
+ Box(Modifier.fillMaxSize().background(TvBg)) {
+ // The player runs under the bar to the top of the screen; the other pages start below it.
+ Box(Modifier.fillMaxSize().padding(top = if (tab == TvTab.NowPlaying) 0.dp else 72.dp)) {
+ when {
+ tab == TvTab.NowPlaying -> TvNowPlaying()
+ lists.isNotEmpty() -> TvSongs(lists.last(), played)
+ tab == TvTab.Home -> TvHome(open, played)
+ tab == TvTab.Library -> TvLibrary(open)
+ else -> TvSearch(open, played)
+ }
+ }
+ TvTopBar(tab, labels, ::select, Modifier.align(Alignment.TopCenter))
+ }
}
+/** Home: Spotify's shelves as rows of covers, the first one big. Artists and shows stay on the phone. */
@Composable
-fun TvApp() {
- val stack = remember { mutableStateListOf<TvPage>(TvPage.Library) }
- val page = stack.last()
- BackHandler(enabled = stack.size > 1) { stack.removeAt(stack.lastIndex) }
- Column(Modifier.fillMaxSize().background(Bg).padding(horizontal = 48.dp, vertical = 27.dp)) {
- Row(horizontalArrangement = Arrangement.spacedBy(16.dp), verticalAlignment = Alignment.CenterVertically) {
- Text("Myspoti", color = Accent, fontSize = 26.sp, fontWeight = FontWeight.Bold, modifier = Modifier.padding(end = 24.dp))
- TvTab(stringResource(R.string.aa_library), page == TvPage.Library || page is TvPage.List) { stack.clear(); stack += TvPage.Library }
- TvTab(stringResource(R.string.navigationbar_musicappitems_search_title), page == TvPage.Search) { stack.clear(); stack += TvPage.Search }
- }
- Spacer(Modifier.height(20.dp))
- Box(Modifier.weight(1f).fillMaxWidth()) {
- when (page) {
- TvPage.Library -> TvLibrary(onOpen = { stack += TvPage.List(it) })
- TvPage.Search -> TvSearch(onOpen = { stack += TvPage.List(it) })
- is TvPage.List -> TvSongs(page.entry)
+private fun TvHome(onOpen: (LibraryEntry) -> Unit, onPlayed: () -> Unit) {
+ val vm: HomeViewModel = viewModel()
+ val home by vm.home.collectAsState()
+ val context = LocalContext.current
+ val likedName = stringResource(R.string.collection_liked_songs_title)
+ val feed = (home as? Response.Success)?.data
+ val sections = remember(feed) {
+ feed?.sections.orEmpty().withoutDj()
+ .map { s -> s.copy(items = s.items.filter { it.entry(likedName) != null }) }
+ .filter { it.items.isNotEmpty() }
+ }
+ when {
+ feed == null && home is Response.Loading -> TvShelfSkeleton()
+ feed == null -> TvRetry { vm.retry() }
+ else -> {
+ val first = remember { FocusRequester() }
+ LazyColumn(Modifier.fillMaxSize(), contentPadding = PaddingValues(top = 20.dp, bottom = 60.dp), verticalArrangement = Arrangement.spacedBy(30.dp)) {
+ itemsIndexed(sections, key = { i, s -> "$i:${s.title}" }) { i, section ->
+ val lead = i == 0
+ Column(Modifier.fillMaxWidth()) {
+ val title = section.title.ifBlank { feed.greeting.ifBlank { context.getString(R.string.navigationbar_musicappitems_home_title) } }
+ Text(title, fontSize = if (lead) 24.sp else 20.sp, fontWeight = FontWeight.Bold, color = Color.White,
+ modifier = Modifier.padding(start = 48.dp, bottom = 14.dp))
+ LazyRow(contentPadding = PaddingValues(horizontal = 48.dp, vertical = 12.dp), horizontalArrangement = Arrangement.spacedBy(if (lead) 20.dp else 16.dp)) {
+ 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 entry = item.entry(likedName) ?: return@itemsIndexed
+ if (lead) TvGradientCard(item.name, item.subtitleText(), item.imageUrl, 240.dp, focus) { onOpen(entry) }
+ else TvAlbumCard(item.name, item.subtitleText(), item.imageUrl, 160.dp, modifier = focus) { onOpen(entry) }
+ }
+ }
+ }
+ }
}
+ LaunchedEffect(sections.isNotEmpty()) { if (sections.isNotEmpty()) runCatching { delay(80); first.requestFocus() } }
}
- TvNowPlaying()
}
}
-/** The focus look: outlined in the accent and slightly bigger, as TV launchers do. */
-@Composable
-private fun Modifier.tvFocusable(shape: RoundedCornerShape = RoundedCornerShape(10.dp), onClick: () -> Unit): Modifier {
- var focused by remember { mutableStateOf(false) }
- return this
- .scale(if (focused) 1.05f else 1f)
- .clip(shape)
- .border(2.dp, if (focused) Accent else Color.Transparent, shape)
- .onFocusChanged { focused = it.isFocused }
- .clickable(onClick = onClick)
+/** The list a Home card opens, or null for what the TV does not open (artists, shows). */
+private fun HomeItem.entry(likedName: String): LibraryEntry? = when (this) {
+ is HomeItem.Album -> if (id.isBlank()) null else LibraryEntry(id, name, artists.ifBlank { subtitle }, imageUrl, isPlaylist = false, uri = "spotify:album:$id")
+ is HomeItem.Playlist -> when {
+ id == Api.HomeCache.LIKED_SONGS_ID -> LibraryEntry("collection", likedName, "", imageUrl, isPlaylist = true, uri = LIKED)
+ id.isNotBlank() -> LibraryEntry(id, name, subtitle, imageUrl, isPlaylist = true, uri = "spotify:playlist:$id")
+ else -> null
+ }
+ else -> null
}
-@Composable
-private fun TvTab(label: String, selected: Boolean, onClick: () -> Unit) {
- Text(label, color = if (selected) Color.White else Dim, fontSize = 20.sp, fontWeight = if (selected) FontWeight.Bold else FontWeight.Normal,
- modifier = Modifier.tvFocusable(RoundedCornerShape(50), onClick).background(if (selected) Card else Color.Transparent).padding(horizontal = 20.dp, vertical = 8.dp))
+private fun HomeItem.subtitleText(): String = when (this) {
+ is HomeItem.Album -> artists.ifBlank { subtitle }
+ is HomeItem.Playlist -> subtitle
+ else -> ""
}
/** Liked Songs, then the playlists and albums of Your Library (a folder opens its own list of them). */
@@ -142,7 +199,7 @@ private fun TvLibrary(onOpen: (LibraryEntry) -> Unit) {
var folder by remember { mutableStateOf<LibraryEntry?>(null) }
var entries by remember { mutableStateOf<List<LibraryEntry>?>(null) }
var failed by remember { mutableStateOf(false) }
- var attempt by remember { mutableStateOf(0) }
+ var attempt by remember { mutableIntStateOf(0) }
BackHandler(enabled = folder != null) { folder = null }
LaunchedEffect(folder, attempt) {
failed = false
@@ -150,7 +207,7 @@ private fun TvLibrary(onOpen: (LibraryEntry) -> Unit) {
val flow = if (f == null) Graph.api.getLibraryRoot() else Graph.api.getLibraryFolder(f.folderUri)
when (val r = flow.first { it !is Response.Loading }) {
is Response.Success -> {
- val liked = LibraryEntry("collection", context.getString(R.string.collection_liked_songs_title), "", "", isPlaylist = true, uri = LIKED)
+ val liked = LibraryEntry("collection", context.getString(R.string.collection_liked_songs_title), "", Api.HomeCache.LIKED_COVER, isPlaylist = true, uri = LIKED)
entries = (if (f == null) listOf(liked) else emptyList()) + r.data.filter { it.folderUri.isNotEmpty() || it.opens() }.filterNot { it.uri == LIKED }
}
else -> failed = true
@@ -159,30 +216,26 @@ private fun TvLibrary(onOpen: (LibraryEntry) -> Unit) {
val list = entries
when {
failed && list == null -> TvRetry { attempt++ }
- list == null -> Unit
+ list == null -> TvShelfSkeleton()
else -> TvGrid(list) { e -> if (e.folderUri.isNotEmpty()) folder = e else onOpen(e) }
}
}
@Composable
-private fun TvGrid(entries: List<LibraryEntry>, onClick: (LibraryEntry) -> Unit) {
+private fun TvGrid(entries: List<LibraryEntry>, modifier: Modifier = Modifier, onClick: (LibraryEntry) -> Unit) {
val first = remember { FocusRequester() }
- LazyVerticalGrid(GridCells.Adaptive(170.dp), contentPadding = PaddingValues(8.dp), horizontalArrangement = Arrangement.spacedBy(20.dp),
- verticalArrangement = Arrangement.spacedBy(20.dp)) {
- items(entries, key = { it.uri.ifEmpty { it.folderUri.ifEmpty { it.spotifyId } } }) { e ->
- Column(Modifier.then(if (e === entries.first()) Modifier.focusRequester(first) else Modifier).tvFocusable { onClick(e) }.background(Card).padding(10.dp)) {
- TvCover(e.coverUri, Modifier.fillMaxWidth().aspectRatio(1f))
- Text(e.name, color = Color.White, fontSize = 15.sp, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(top = 8.dp))
- if (e.subtitle.isNotBlank()) Text(e.subtitle, color = Dim, fontSize = 13.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
- }
+ 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, modifier = if (i == 0) Modifier.focusRequester(first) else Modifier) { onClick(e) }
}
}
- LaunchedEffect(entries) { runCatching { delay(50); first.requestFocus() } }
+ LaunchedEffect(entries) { runCatching { delay(80); first.requestFocus() } }
}
/** Songs, playlists and albums matching what was typed (the TV's own keyboard opens on the field). */
@Composable
-private fun TvSearch(onOpen: (LibraryEntry) -> Unit) {
+private fun TvSearch(onOpen: (LibraryEntry) -> Unit, onPlayed: () -> Unit) {
val context = LocalContext.current
var query by remember { mutableStateOf("") }
var asked by remember { mutableStateOf("") }
@@ -203,32 +256,44 @@ private fun TvSearch(onOpen: (LibraryEntry) -> Unit) {
else -> failed = true
}
}
- LaunchedEffect(Unit) { runCatching { delay(50); field.requestFocus() } }
- Column {
+ LaunchedEffect(Unit) { runCatching { delay(80); field.requestFocus() } }
+ Column(Modifier.fillMaxSize().padding(top = 16.dp)) {
TextField(query, { query = it }, singleLine = true, placeholder = { Text(stringResource(R.string.immersive_shell_search_hint)) },
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search), keyboardActions = KeyboardActions(onSearch = { asked = query.trim() }),
- modifier = Modifier.width(520.dp).focusRequester(field))
- Spacer(Modifier.height(16.dp))
+ shape = RoundedCornerShape(12.dp),
+ colors = TextFieldDefaults.colors(
+ focusedContainerColor = Color(0xFF2C2C2E), unfocusedContainerColor = Color(0xFF1C1C1E),
+ focusedTextColor = Color.White, unfocusedTextColor = Color.White,
+ focusedIndicatorColor = Color.Transparent, unfocusedIndicatorColor = Color.Transparent, cursorColor = TvAccent,
+ ),
+ modifier = Modifier.padding(horizontal = 48.dp).width(560.dp).focusRequester(field))
+ Spacer(Modifier.height(20.dp))
when {
- failed -> Text(stringResource(R.string.search_failed), color = Dim, fontSize = 16.sp)
+ failed -> Text(stringResource(R.string.search_failed), color = TvSubtle, fontSize = 16.sp, modifier = Modifier.padding(start = 48.dp))
asked.isNotBlank() && songs.isEmpty() && lists.isEmpty() ->
- Text(context.getString(R.string.assisted_curation_search_empty_view_no_result_title, asked), color = Dim, fontSize = 16.sp)
- else -> Row(horizontalArrangement = Arrangement.spacedBy(32.dp)) {
- LazyColumn(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(6.dp)) {
- items(songs, key = { it.url }) { s -> TvSongRow(s) { play(s, null, listOf(s)) } }
+ Text(context.getString(R.string.assisted_curation_search_empty_view_no_result_title, asked), color = TvSubtle, fontSize = 16.sp,
+ modifier = Modifier.padding(start = 48.dp))
+ else -> Row(Modifier.fillMaxSize()) {
+ LazyColumn(Modifier.weight(1f).padding(start = 48.dp), contentPadding = PaddingValues(bottom = 40.dp), verticalArrangement = Arrangement.spacedBy(2.dp)) {
+ itemsIndexed(songs, key = { i, s -> "$i:${s.url}" }) { _, s ->
+ TvSongRow(s, null) { play(s, null, listOf(s)); onPlayed() }
+ }
+ }
+ Box(Modifier.weight(1f)) {
+ if (lists.isNotEmpty()) TvGrid(lists, onClick = onOpen)
}
- Box(Modifier.weight(1f)) { TvGrid(lists, onOpen) }
}
}
}
}
-/** A list's songs; a song played plays the list on from it. */
+/** A list's page: its cover, name, Play and Shuffle on the left; its songs on the right. */
@Composable
-private fun TvSongs(entry: LibraryEntry) {
+private fun TvSongs(entry: LibraryEntry, onPlayed: () -> Unit) {
+ val vm: PlayerViewModel = viewModel()
var page by remember(entry) { mutableStateOf<ContextPageModel?>(null) }
- var failed by remember { mutableStateOf(false) }
- var attempt by remember { mutableStateOf(0) }
+ var failed by remember(entry) { mutableStateOf(false) }
+ var attempt by remember { mutableIntStateOf(0) }
LaunchedEffect(entry, attempt) {
failed = false
val id = entry.uri.substringAfterLast(':')
@@ -249,93 +314,76 @@ private fun TvSongs(entry: LibraryEntry) {
val p = page
when {
failed && p == null -> TvRetry { attempt++ }
- p == null -> Unit
- else -> Row(horizontalArrangement = Arrangement.spacedBy(32.dp)) {
- Column(Modifier.width(260.dp)) {
- TvCover(p.coverUri.ifBlank { entry.coverUri }, Modifier.size(260.dp))
- Text(p.name.ifBlank { entry.name }, color = Color.White, fontSize = 22.sp, fontWeight = FontWeight.Bold, maxLines = 2, modifier = Modifier.padding(top = 12.dp))
- if (p.ownerName.isNotBlank()) Text(p.ownerName, color = Dim, fontSize = 15.sp)
+ p == null -> TvShelfSkeleton(rows = 2)
+ else -> Row(Modifier.fillMaxSize().padding(start = 64.dp, end = 48.dp, top = 24.dp), horizontalArrangement = Arrangement.spacedBy(56.dp)) {
+ val playFocus = remember { FocusRequester() }
+ Column(Modifier.width(300.dp)) {
+ TvCover(p.coverUri.ifBlank { entry.coverUri }, Modifier.size(300.dp), RoundedCornerShape(12.dp))
+ Text(p.name.ifBlank { entry.name }, color = Color.White, fontSize = 24.sp, fontWeight = FontWeight.Bold, maxLines = 2,
+ overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(top = 16.dp))
+ val owner = p.ownerName.ifBlank { entry.subtitle }
+ 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)) {
+ p.tracks.firstOrNull()?.let { vm.updateShuffleState(false); play(it, p.uri, p.tracks); onPlayed() }
+ }
+ TvPillButton(Icons.Default.Shuffle, stringResource(R.string.immersive_player_shuffle_on), filled = false) {
+ if (p.tracks.isNotEmpty()) { vm.updateShuffleState(true); play(p.tracks.random(), p.uri, p.tracks); onPlayed() }
+ }
+ }
}
- val first = remember { FocusRequester() }
- LazyColumn(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(6.dp)) {
- items(p.tracks, key = { it.url + it.id }) { s ->
- TvSongRow(s, if (s === p.tracks.first()) Modifier.focusRequester(first) else Modifier) { play(s, p.uri, p.tracks) }
+ LazyColumn(Modifier.weight(1f), contentPadding = PaddingValues(bottom = 40.dp), verticalArrangement = Arrangement.spacedBy(2.dp)) {
+ itemsIndexed(p.tracks, key = { i, s -> "$i:${s.url}" }) { i, s ->
+ TvSongRow(s, i + 1) { play(s, p.uri, p.tracks); onPlayed() }
}
}
- LaunchedEffect(p.tracks.isNotEmpty()) { if (p.tracks.isNotEmpty()) runCatching { delay(50); first.requestFocus() } }
+ LaunchedEffect(p.tracks.isNotEmpty()) { if (p.tracks.isNotEmpty()) runCatching { delay(80); playFocus.requestFocus() } }
}
}
}
+/** Play or Shuffle under a list's cover: the filled one in the accent. */
@Composable
-private fun TvSongRow(s: SongsModel, modifier: Modifier = Modifier, onClick: () -> Unit) {
- Row(modifier.fillMaxWidth().tvFocusable(onClick = onClick).background(Card).padding(10.dp), verticalAlignment = Alignment.CenterVertically) {
- TvCover(s.coverUri, Modifier.size(48.dp))
- Column(Modifier.padding(start = 14.dp)) {
- Text(s.title, color = Color.White, fontSize = 16.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
- Text(s.singer, color = Dim, fontSize = 13.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
- }
+private fun TvPillButton(icon: androidx.compose.ui.graphics.vector.ImageVector, label: String, filled: Boolean, modifier: Modifier = Modifier, onClick: () -> Unit) {
+ val fg = if (filled) Color.Black else Color.White
+ Row(
+ modifier.tvPill(RoundedCornerShape(10.dp), base = if (filled) TvAccent else Color(0x26FFFFFF),
+ focusedFill = if (filled) Color(0xFF3BE477) else Color(0x4DFFFFFF), focusedScale = 1.06f, onClick = onClick)
+ .padding(horizontal = 18.dp, vertical = 10.dp),
+ verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp),
+ ) {
+ Icon(icon, null, tint = fg, modifier = Modifier.size(20.dp))
+ Text(label, color = fg, fontSize = 15.sp, fontWeight = FontWeight.SemiBold)
}
}
-/** The song playing, how far it is, and previous, play/pause and next. */
+/** One song: its number (or cover), title and artist, and its length. */
@Composable
-private fun TvNowPlaying() {
- val state = Graph.currentSongState
- val title by state.title
- if (title.isBlank()) return
- val singer by state.singer
- val cover by state.coverUri
- val playing by state.playingState
- var progress by remember { mutableStateOf(0f) }
- LaunchedEffect(Unit) {
- while (true) {
- val d = SongPlayer.getDuration()
- progress = if (d > 0) (SongPlayer.getCurrentPosition().toFloat() / d).coerceIn(0f, 1f) else 0f
- delay(500)
- }
- }
- Column(Modifier.padding(top = 16.dp).fillMaxWidth().clip(RoundedCornerShape(12.dp)).background(Card)) {
- Box(Modifier.fillMaxWidth().height(3.dp).background(Color.White.copy(alpha = 0.15f))) {
- Box(Modifier.fillMaxWidth(progress).height(3.dp).background(Accent))
- }
- Row(Modifier.padding(12.dp), verticalAlignment = Alignment.CenterVertically) {
- TvCover(cover, Modifier.size(56.dp))
- Column(Modifier.weight(1f).padding(start = 14.dp)) {
- Text(title, color = Color.White, fontSize = 17.sp, fontWeight = FontWeight.Bold, maxLines = 1, overflow = TextOverflow.Ellipsis)
- Text(singer, color = Dim, fontSize = 14.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
- }
- TvButton(stringResource(R.string.immersive_player_previous), "⏮") { SongPlayer.previous() }
- TvButton(stringResource(if (playing) R.string.immersive_player_pause else R.string.immersive_player_play), if (playing) "⏸" else "▶") {
- if (SongPlayer.isPlaying()) SongPlayer.pause() else SongPlayer.play()
- }
- TvButton(stringResource(R.string.immersive_player_next), "⏭") { SongPlayer.next() }
+private fun TvSongRow(s: SongsModel, number: Int?, onClick: () -> Unit) {
+ Row(
+ Modifier.fillMaxWidth().tvPill(RoundedCornerShape(10.dp), focusedFill = Color(0x26FFFFFF), focusedScale = 1.02f, onClick = onClick)
+ .padding(horizontal = 14.dp, vertical = 10.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ if (number != null) Text("$number", color = TvSubtle, fontSize = 14.sp, modifier = Modifier.width(36.dp))
+ else TvCover(s.coverUri, Modifier.size(44.dp).padding(end = 0.dp), RoundedCornerShape(6.dp))
+ Column(Modifier.weight(1f).padding(start = if (number == null) 14.dp else 0.dp)) {
+ Text(s.title, color = Color.White, fontSize = 16.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
+ Text(s.singer, color = TvSubtle, fontSize = 13.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
- }
-}
-
-@Composable
-private fun TvButton(label: String, glyph: String, onClick: () -> Unit) {
- Box(Modifier.padding(horizontal = 6.dp).size(52.dp).tvFocusable(RoundedCornerShape(50), onClick).background(Color.White.copy(alpha = 0.08f))
- .semantics { contentDescription = label }, contentAlignment = Alignment.Center) {
- Text(glyph, color = Color.White, fontSize = 22.sp)
- }
-}
-
-@OptIn(ExperimentalGlideComposeApi::class)
-@Composable
-private fun TvCover(url: String, modifier: Modifier) {
- Box(modifier.clip(RoundedCornerShape(6.dp)).background(Color.White.copy(alpha = 0.06f))) {
- if (url.isNotBlank()) GlideImage(model = url, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.fillMaxSize())
+ if (s.durationMs > 0) Text(formatMs(s.durationMs.toLong()), color = TvSubtle, fontSize = 13.sp, modifier = Modifier.padding(start = 16.dp))
}
}
@Composable
private fun TvRetry(onRetry: () -> Unit) {
val focus = remember { FocusRequester() }
- Text(stringResource(R.string.retry_button), color = Color.White, fontSize = 18.sp,
- modifier = Modifier.focusRequester(focus).tvFocusable(onClick = onRetry).background(Card).padding(horizontal = 24.dp, vertical = 12.dp))
- LaunchedEffect(Unit) { runCatching { delay(50); focus.requestFocus() } }
+ Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
+ Text(stringResource(R.string.retry_button), color = Color.White, fontSize = 18.sp,
+ modifier = Modifier.focusRequester(focus).tvPill(RoundedCornerShape(10.dp), base = Color(0xFF1C1C1E), onClick = onRetry)
+ .padding(horizontal = 24.dp, vertical = 12.dp))
+ }
+ LaunchedEffect(Unit) { runCatching { delay(80); focus.requestFocus() } }
}
private const val LIKED = "spotify:collection:tracks"
@@ -343,6 +391,11 @@ private const val LIKED = "spotify:collection:tracks"
/** A Library row that holds songs: a playlist or an album (artists, shows and the rest stay on the phone). */
private fun LibraryEntry.opens() = ":playlist:" in uri || ":album:" in uri || uri == LIKED
+internal fun formatMs(ms: Long): String {
+ val s = (ms / 1000).coerceAtLeast(0)
+ return "%d:%02d".format(s / 60, s % 60)
+}
+
private fun play(song: SongsModel, contextUri: String?, songs: List<SongsModel>) {
SongPlayer.playSong(song.url, contextUri = contextUri, songs = songs)
Graph.currentSongState.updateSongState(song.coverUri, song.title, song.singer, true, song.id, songs.indexOf(song).coerceAtLeast(0), song.album)
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
new file mode 100644
index 00000000..a8a8f34d
--- /dev/null
+++ b/base/app/src/main/java/com/music/spotui/ui/tv/TvNowPlaying.kt
@@ -0,0 +1,269 @@
+/*
+ * Adapted from Apple Music TV (https://github.com/JObersi10/apple-music-tv), GPL-3.0,
+ * android/app/src/main/java/com/applemusicktv/ui/screens/NowPlayingScreen.kt at 7e5c594
+ * (NowPlayingScreen, PlayerProgressBar, rememberSmoothProgressMs).
+ * Modified for Myspoti, 2026-11.
+ *
+ * Changes: Myspoti's player state and actions (rememberImmersivePlayer), its mesh backdrop from
+ * the cover instead of the beat-driven orbs, its lyrics panel; shuffle, repeat and like on the
+ * transport row instead of an options menu; no motion cover, queue panel, sleep timer, live radio,
+ * screensaver or full-screen lyrics.
+ */
+package com.music.spotui.ui.tv
+
+import androidx.compose.animation.Crossfade
+import androidx.compose.animation.core.FastOutSlowInEasing
+import androidx.compose.animation.core.animateFloatAsState
+import androidx.compose.animation.core.tween
+import androidx.compose.foundation.ExperimentalFoundationApi
+import androidx.compose.foundation.background
+import androidx.compose.foundation.basicMarquee
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.focusable
+import androidx.compose.foundation.interaction.MutableInteractionSource
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.Favorite
+import androidx.compose.material.icons.filled.FavoriteBorder
+import androidx.compose.material.icons.filled.Pause
+import androidx.compose.material.icons.filled.PlayArrow
+import androidx.compose.material.icons.filled.Repeat
+import androidx.compose.material.icons.filled.RepeatOne
+import androidx.compose.material.icons.filled.Shuffle
+import androidx.compose.material.icons.filled.SkipNext
+import androidx.compose.material.icons.filled.SkipPrevious
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableLongStateOf
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.runtime.withFrameMillis
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.focus.focusRequester
+import androidx.compose.ui.focus.onFocusChanged
+import androidx.compose.ui.graphics.Brush
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.Shadow
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.input.key.Key
+import androidx.compose.ui.input.key.KeyEventType
+import androidx.compose.ui.input.key.key
+import androidx.compose.ui.input.key.onKeyEvent
+import androidx.compose.ui.input.key.onPreviewKeyEvent
+import androidx.compose.ui.input.key.type
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import androidx.navigation.compose.rememberNavController
+import app.myspoti.engine.R
+import com.music.spotui.ui.immersive.lyrics.ImmersiveLyricsPanel
+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.immersive.player.rememberImmersivePlayer
+import com.music.spotui.ui.look.MeshGradientBackground
+import com.music.spotui.ui.look.rememberArtworkColors
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.isActive
+import java.text.DateFormat
+import java.util.Date
+
+/** The controls hide after this long without the remote; the cover, title and lyrics stay. */
+private const val CHROME_HIDE_MS = 8_000L
+
+/**
+ * The full-screen player: the cover's colours as a slow mesh behind everything; on the left the
+ * cover, title, artist, the transport and a seek bar the D-pad scrubs by 10 s; on the right the
+ * synced lyrics. Idle, the controls fade and only the cover, its words and the lyrics remain.
+ */
+@Composable
+internal fun TvNowPlaying() {
+ // The TV opens no album or artist page: the controller only satisfies the bridge.
+ val bridge = rememberImmersivePlayer(rememberNavController())
+ val state = bridge.state
+ val actions = bridge.actions
+ val palette = rememberArtworkColors(state.coverUrl.ifBlank { null })
+
+ var chromeVisible by remember { mutableStateOf(true) }
+ var lastNavMs by remember { mutableLongStateOf(System.currentTimeMillis()) }
+ LaunchedEffect(chromeVisible, lastNavMs, state.playing) {
+ if (!chromeVisible || !state.playing) return@LaunchedEffect
+ while (isActive) {
+ delay(500)
+ if (System.currentTimeMillis() - lastNavMs > CHROME_HIDE_MS) { chromeVisible = false; break }
+ }
+ }
+ // Into idle slowly, back at once: the controls are there the moment the remote is touched.
+ val idle by animateFloatAsState(
+ if (chromeVisible) 0f else 1f,
+ if (chromeVisible) tween(240, easing = FastOutSlowInEasing) else tween(1600, easing = FastOutSlowInEasing),
+ label = "idle",
+ )
+ val chromeAlpha = 1f - idle
+
+ Box(
+ Modifier.fillMaxSize().background(TvBg).onPreviewKeyEvent { e ->
+ if (e.type == KeyEventType.KeyDown) {
+ lastNavMs = System.currentTimeMillis()
+ // The first press only brings the controls back: focus does not also jump.
+ if (!chromeVisible) { chromeVisible = true; return@onPreviewKeyEvent true }
+ }
+ false
+ },
+ ) {
+ MeshGradientBackground(palette, Modifier.fillMaxSize(), trackKey = state.title)
+ // Darker towards the right, where the lyrics are read, and at the bottom.
+ Box(Modifier.fillMaxSize().background(Brush.horizontalGradient(0f to Color(0x33000000), 0.45f to Color(0x55000000), 1f to Color(0xAA000000))))
+
+ if (state.title.isBlank()) {
+ Text(stringResource(R.string.immersive_shell_now_playing), color = Color(0xFF888888), fontSize = 20.sp, modifier = Modifier.align(Alignment.Center))
+ return@Box
+ }
+
+ 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)) {
+ Column(
+ Modifier.width(380.dp).fillMaxHeight().graphicsLayer {
+ // Idle, the controls still hold their space: the group eases down a little so the
+ // cover and its words sit in the middle.
+ val s = 1f + 0.03f * idle
+ scaleX = s; scaleY = s
+ translationY = idle * 64f
+ },
+ verticalArrangement = Arrangement.Center,
+ horizontalAlignment = Alignment.CenterHorizontally,
+ ) {
+ Crossfade(state.coverUrl, animationSpec = tween(800), label = "cover") { url ->
+ TvCover(url, Modifier.size(320.dp), RoundedCornerShape(18.dp))
+ }
+ Spacer(Modifier.height(18.dp))
+ TvMarquee(state.title, 26.sp, FontWeight.Bold, Color.White)
+ TvMarquee(state.artist, 18.sp, FontWeight.Medium, TvAccent)
+ Spacer(Modifier.height(18.dp))
+ TvTransport(state, actions, Modifier.graphicsLayer { alpha = chromeAlpha })
+ Spacer(Modifier.height(16.dp))
+ TvSeekBar(state, actions, Modifier.graphicsLayer { alpha = chromeAlpha })
+ }
+ // Lyrics are content, not chrome: they stay when the controls hide.
+ ImmersiveLyricsPanel(Modifier.weight(1f).fillMaxHeight(), PaddingValues(vertical = 8.dp))
+ }
+ }
+}
+
+@OptIn(ExperimentalFoundationApi::class)
+@Composable
+private fun TvMarquee(text: String, size: androidx.compose.ui.unit.TextUnit, weight: FontWeight, color: Color) {
+ Text(text, color = color, fontSize = size, fontWeight = weight, maxLines = 1, modifier = Modifier.fillMaxWidth().basicMarquee(),
+ style = TextStyle(textAlign = androidx.compose.ui.text.style.TextAlign.Center))
+}
+
+/** Shuffle, previous, play/pause, next, repeat and like; play/pause has the focus at first. */
+@Composable
+private fun TvTransport(state: ImmersivePlayerState, actions: ImmersivePlayerActions, modifier: Modifier) {
+ val playFocus = remember { FocusRequester() }
+ LaunchedEffect(Unit) { runCatching { delay(80); playFocus.requestFocus() } }
+ val dim = Color.White.copy(alpha = 0.6f)
+ Row(modifier, horizontalArrangement = Arrangement.spacedBy(14.dp), verticalAlignment = Alignment.CenterVertically) {
+ TvIconButton(Icons.Default.Shuffle,
+ stringResource(if (state.shuffle) R.string.immersive_player_shuffle_on else R.string.immersive_player_shuffle_off),
+ size = 44.dp, tint = if (state.shuffle) TvAccent else dim, onClick = actions.toggleShuffle)
+ TvIconButton(Icons.Default.SkipPrevious, stringResource(R.string.immersive_player_previous), size = 52.dp, onClick = actions.previous)
+ TvIconButton(
+ if (state.playing) Icons.Default.Pause else Icons.Default.PlayArrow,
+ stringResource(if (state.playing) R.string.immersive_player_pause else R.string.immersive_player_play),
+ size = 68.dp, tint = Color.Black, base = Color.White, modifier = Modifier.focusRequester(playFocus), onClick = actions.playPause,
+ )
+ TvIconButton(Icons.Default.SkipNext, stringResource(R.string.immersive_player_next), size = 52.dp, onClick = actions.next)
+ val repeatOn = state.repeatMode != ImmersiveRepeat.OFF
+ TvIconButton(
+ if (state.repeatMode == ImmersiveRepeat.ONE || state.repeatMode == ImmersiveRepeat.ONCE) Icons.Default.RepeatOne else Icons.Default.Repeat,
+ stringResource(when (state.repeatMode) {
+ ImmersiveRepeat.ALL -> R.string.immersive_player_repeat_all
+ ImmersiveRepeat.ONE -> R.string.immersive_player_repeat_one
+ ImmersiveRepeat.ONCE -> R.string.immersive_player_repeat_once
+ else -> R.string.immersive_player_repeat_off
+ }),
+ size = 44.dp, tint = if (repeatOn) TvAccent else dim, onClick = actions.cycleRepeat,
+ )
+ if (!state.isEpisode) TvIconButton(
+ if (state.liked) Icons.Default.Favorite else Icons.Default.FavoriteBorder,
+ stringResource(if (state.liked) R.string.immersive_player_unlike else R.string.immersive_player_like),
+ size = 44.dp, tint = if (state.liked) TvAccent else dim, onClick = actions.toggleLike,
+ )
+ }
+}
+
+/**
+ * The seek bar and its times. Focused, ← and → move a cursor by 10 s and OK seeks there; the
+ * playhead is read every frame here only, not by the whole screen.
+ */
+@Composable
+private fun TvSeekBar(state: ImmersivePlayerState, actions: ImmersivePlayerActions, modifier: Modifier) {
+ var positionMs by remember { mutableLongStateOf(state.positionMs()) }
+ LaunchedEffect(state.positionMs) { while (isActive) withFrameMillis { positionMs = state.positionMs() } }
+ val duration = state.durationMs.coerceAtLeast(1L)
+ var focused by remember { mutableStateOf(false) }
+ // The cursor starts at the playhead each time the bar takes the focus.
+ var scrubMs by remember(state.title) { mutableLongStateOf(positionMs) }
+ val progress = (positionMs.toFloat() / duration).coerceIn(0f, 1f)
+ val scrub = (scrubMs.toFloat() / duration).coerceIn(0f, 1f)
+ val shadow = Shadow(Color.Black.copy(alpha = 0.8f), blurRadius = 8f)
+ Column(modifier.fillMaxWidth()) {
+ Box(
+ Modifier.fillMaxWidth().padding(vertical = 6.dp)
+ .onFocusChanged { if (it.isFocused && !focused) scrubMs = positionMs; focused = it.isFocused }
+ .onKeyEvent { e ->
+ if (e.type != KeyEventType.KeyDown) return@onKeyEvent false
+ when (e.key) {
+ Key.DirectionLeft -> { scrubMs = (scrubMs - 10_000).coerceAtLeast(0); true }
+ Key.DirectionRight -> { scrubMs = (scrubMs + 10_000).coerceAtMost(duration); true }
+ else -> false
+ }
+ }
+ .focusable()
+ .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) { actions.seekTo(scrubMs); positionMs = scrubMs },
+ ) {
+ Box(Modifier.fillMaxWidth().height(if (focused) 8.dp else 4.dp).clip(RoundedCornerShape(4.dp)).background(Color(0x44FFFFFF))) {
+ Box(Modifier.fillMaxWidth(progress).fillMaxHeight().background(Color.White))
+ if (focused) Box(Modifier.fillMaxWidth(scrub).fillMaxHeight().background(TvAccent.copy(alpha = 0.6f)))
+ }
+ }
+ Row(Modifier.fillMaxWidth(), Arrangement.SpaceBetween) {
+ Text(formatMs(if (focused) scrubMs else positionMs), style = TextStyle(fontSize = 13.sp, color = if (focused) Color.White else Color(0xFFAAAAAA), shadow = shadow))
+ Text(formatMs(state.durationMs), style = TextStyle(fontSize = 13.sp, color = Color(0xFFAAAAAA), shadow = shadow))
+ }
+ }
+}
+
+/** The time of day, top right, in the TV's own format. */
+@Composable
+private fun TvClock(modifier: Modifier) {
+ var text by remember { mutableStateOf("") }
+ LaunchedEffect(Unit) {
+ val fmt = DateFormat.getTimeInstance(DateFormat.SHORT)
+ while (isActive) { text = fmt.format(Date()); delay(1_000) }
+ }
+ Text(text, modifier, style = TextStyle(fontSize = 17.sp, color = Color(0xCCFFFFFF), shadow = Shadow(Color.Black.copy(alpha = 0.8f), blurRadius = 8f)))
+}
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
new file mode 100644
index 00000000..1fc1cee3
--- /dev/null
+++ b/base/app/src/main/java/com/music/spotui/ui/tv/TvParts.kt
@@ -0,0 +1,248 @@
+/*
+ * Adapted from Apple Music TV (https://github.com/JObersi10/apple-music-tv), GPL-3.0,
+ * android/app/src/main/java/com/applemusicktv/ui/components/TopNavBar.kt, AlbumCard.kt,
+ * SpotlightCards.kt (GradientCard) and Skeleton.kt at 7e5c594.
+ * Modified for Myspoti, 2026-11.
+ *
+ * Changes: built on Compose foundation instead of androidx.tv (no new library on weak TVs): the
+ * focus scale, white halo and hairline border of tv-material's Card are drawn by hand. Myspoti's
+ * accent, Material icons (no SF Symbols), Glide for the covers, no motion artwork, no beat-reactive
+ * bars, no settings tab.
+ */
+package com.music.spotui.ui.tv
+
+import androidx.compose.animation.animateColorAsState
+import androidx.compose.animation.core.LinearEasing
+import androidx.compose.animation.core.RepeatMode
+import androidx.compose.animation.core.animateFloat
+import androidx.compose.animation.core.animateFloatAsState
+import androidx.compose.animation.core.infiniteRepeatable
+import androidx.compose.animation.core.rememberInfiniteTransition
+import androidx.compose.animation.core.tween
+import androidx.compose.foundation.background
+import androidx.compose.foundation.border
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.interaction.MutableInteractionSource
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.aspectRatio
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.MusicNote
+import androidx.compose.material3.Icon
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.draw.drawBehind
+import androidx.compose.ui.focus.onFocusChanged
+import androidx.compose.ui.geometry.CornerRadius
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.geometry.Size
+import androidx.compose.ui.graphics.Brush
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.graphics.vector.ImageVector
+import androidx.compose.ui.layout.ContentScale
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
+import com.bumptech.glide.integration.compose.GlideImage
+
+internal val TvBg = Color(0xFF000000)
+internal val TvAccent = Color(0xFF1ED760)
+internal val TvTitle = Color(0xFFF2F2F5)
+internal val TvSubtle = Color(0xFF8A8A8E)
+
+/** The tabs of the floating bar, in their order. */
+internal enum class TvTab { Home, Library, Search, NowPlaying }
+
+/**
+ * The focus look of a card: a soft scale, a white halo around it and a hairline white border,
+ * as tv-material's Card draws them. [onFocus] hears the focus too.
+ */
+@Composable
+internal fun Modifier.tvCard(
+ shape: RoundedCornerShape,
+ corner: Dp,
+ focusedScale: Float = 1.08f,
+ borderAlpha: Float = 0.55f,
+ onFocus: (Boolean) -> Unit = {},
+ onClick: () -> Unit,
+): Modifier {
+ var focused by remember { mutableStateOf(false) }
+ val scale by animateFloatAsState(if (focused) focusedScale else 1f, tween(150), label = "cardScale")
+ val halo by animateFloatAsState(if (focused) 1f else 0f, tween(150), label = "cardHalo")
+ return this
+ .graphicsLayer { scaleX = scale; scaleY = scale }
+ .drawBehind {
+ if (halo <= 0f) return@drawBehind
+ // A glow of 18 dp: three widening rounded rects, fading out.
+ val glow = 18.dp.toPx()
+ for (i in 1..3) {
+ val g = glow * i / 3f
+ drawRoundRect(
+ Color.White.copy(alpha = 0.07f * halo * (4 - i) / 3f),
+ topLeft = Offset(-g, -g), size = Size(size.width + 2 * g, size.height + 2 * g),
+ cornerRadius = CornerRadius(corner.toPx() + g),
+ )
+ }
+ }
+ .border(1.5.dp, Color.White.copy(alpha = borderAlpha * halo), shape)
+ .clip(shape)
+ .onFocusChanged { focused = it.isFocused || it.hasFocus; onFocus(focused) }
+ .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null, onClick = onClick)
+}
+
+/** A focusable round or pill control with a light fill when focused. */
+@Composable
+internal fun Modifier.tvPill(
+ shape: RoundedCornerShape = RoundedCornerShape(50),
+ base: Color = Color.Transparent,
+ focusedFill: Color = Color(0x33FFFFFF),
+ focusedScale: Float = 1.1f,
+ onClick: () -> Unit,
+): Modifier {
+ var focused by remember { mutableStateOf(false) }
+ val scale by animateFloatAsState(if (focused) focusedScale else 1f, tween(150), label = "pillScale")
+ val fill by animateColorAsState(if (focused) focusedFill else base, tween(150), label = "pillFill")
+ return this
+ .graphicsLayer { scaleX = scale; scaleY = scale }
+ .clip(shape)
+ .background(fill)
+ .onFocusChanged { focused = it.isFocused }
+ .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null, onClick = onClick)
+}
+
+/** The floating pill of tabs at the top; the white pill marks the open tab. */
+@Composable
+internal fun TvTopBar(selected: TvTab, labels: Map<TvTab, String>, onSelect: (TvTab) -> Unit, modifier: Modifier = Modifier) {
+ var barFocused by remember { mutableStateOf(false) }
+ // On Now Playing the bar fades away until the remote reaches it.
+ val alpha by animateFloatAsState(if (selected == TvTab.NowPlaying && !barFocused) 0f else 1f, tween(500), label = "barAlpha")
+ Box(
+ modifier.fillMaxWidth().onFocusChanged { barFocused = it.hasFocus }.graphicsLayer { this.alpha = alpha }.padding(vertical = 14.dp),
+ contentAlignment = Alignment.Center,
+ ) {
+ Row(
+ Modifier.clip(RoundedCornerShape(50)).background(Color(0xE61C1C1E))
+ .background(Brush.verticalGradient(0f to Color(0x14FFFFFF), 0.5f to Color.Transparent))
+ .padding(horizontal = 6.dp, vertical = 5.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(2.dp),
+ ) {
+ TvTab.entries.forEach { tab ->
+ val isSelected = tab == selected
+ var focused by remember { mutableStateOf(false) }
+ val bg by animateColorAsState(
+ when { isSelected -> Color.White; focused -> Color(0xFF2C2C2E); else -> Color.Transparent }, tween(180), label = "tabBg")
+ val fg by animateColorAsState(if (isSelected) Color.Black else if (focused) Color.White else Color(0xFF9A9A9A), tween(180), label = "tabFg")
+ Box(
+ Modifier.clip(RoundedCornerShape(50)).background(bg)
+ .onFocusChanged { focused = it.isFocused }
+ .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) { onSelect(tab) }
+ .padding(horizontal = 18.dp, vertical = 8.dp),
+ ) {
+ Text(labels[tab].orEmpty(), fontSize = 15.sp, color = fg,
+ fontWeight = if (isSelected) FontWeight.SemiBold else FontWeight.Medium)
+ }
+ }
+ }
+ }
+}
+
+/** A square cover with its title and subtitle under it, for shelves and grids. */
+@Composable
+internal fun TvAlbumCard(title: String, subtitle: String, coverUrl: String, size: Dp, round: Boolean = false, modifier: Modifier = Modifier, onClick: () -> Unit) {
+ val corner = if (round) size / 2 else 12.dp
+ val shape = RoundedCornerShape(corner)
+ Column(modifier.width(size)) {
+ TvCover(coverUrl, Modifier.fillMaxWidth().aspectRatio(1f).tvCard(shape, corner, onClick = onClick), shape)
+ Column(Modifier.padding(horizontal = 4.dp, vertical = 8.dp)) {
+ Text(title, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = TvTitle, maxLines = 1, overflow = TextOverflow.Ellipsis)
+ if (subtitle.isNotBlank()) {
+ Text(subtitle, fontSize = 12.sp, color = TvSubtle, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(top = 2.dp))
+ }
+ }
+ }
+}
+
+/** A big square card whose title sits on a tinted scrim over the cover (the lead shelf of Home). */
+@Composable
+internal fun TvGradientCard(title: String, subtitle: String, coverUrl: String, width: Dp, modifier: Modifier = Modifier, onClick: () -> Unit) {
+ val shape = RoundedCornerShape(16.dp)
+ // A dark scrim, not the cover's own colour: a palette read for every card is too much for a weak TV.
+ val tint = Color(0xFF101012)
+ Box(modifier.width(width).aspectRatio(1f).tvCard(shape, 16.dp, focusedScale = 1.06f, borderAlpha = 0.7f, onClick = onClick)) {
+ TvCover(coverUrl, Modifier.fillMaxSize(), shape)
+ Box(Modifier.fillMaxSize().background(Brush.verticalGradient(0.4f to Color.Transparent, 1f to tint.copy(alpha = 0.92f))))
+ Column(Modifier.align(Alignment.BottomStart).padding(14.dp)) {
+ Text(title, color = Color.White, fontSize = 18.sp, fontWeight = FontWeight.Bold, maxLines = 2, overflow = TextOverflow.Ellipsis)
+ if (subtitle.isNotBlank()) {
+ Text(subtitle, color = Color.White.copy(alpha = 0.78f), fontSize = 13.sp, maxLines = 1, overflow = TextOverflow.Ellipsis,
+ modifier = Modifier.padding(top = 2.dp))
+ }
+ }
+ }
+}
+
+@OptIn(ExperimentalGlideComposeApi::class)
+@Composable
+internal fun TvCover(url: String, modifier: Modifier, shape: RoundedCornerShape = RoundedCornerShape(8.dp)) {
+ Box(modifier.clip(shape).background(Color(0xFF1C1C1E)), contentAlignment = Alignment.Center) {
+ if (url.isNotBlank()) GlideImage(model = url, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.fillMaxSize())
+ else Icon(Icons.Default.MusicNote, null, tint = Color.White.copy(alpha = 0.2f), modifier = Modifier.size(40.dp))
+ }
+}
+
+/** A Material icon in a focusable round button. */
+@Composable
+internal fun TvIconButton(icon: ImageVector, label: String, size: Dp = 48.dp, tint: Color = Color.White, base: Color = Color.Transparent,
+ modifier: Modifier = Modifier, onClick: () -> Unit) {
+ Box(modifier.size(size).tvPill(base = base, onClick = onClick), contentAlignment = Alignment.Center) {
+ Icon(icon, label, tint = tint, modifier = Modifier.size(size * 0.55f))
+ }
+}
+
+/** A shimmering placeholder while a page loads: a big shelf first, then the standard ones. */
+@Composable
+internal fun TvShelfSkeleton(rows: Int = 3) {
+ val t = rememberInfiniteTransition(label = "sk")
+ 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) }
+ }
+}
+
+@Composable
+private fun SkeletonRow(bar: Color, cardSize: Dp, cards: Int) {
+ Column {
+ Box(Modifier.padding(start = 48.dp, bottom = 14.dp).width(180.dp).height(18.dp).clip(RoundedCornerShape(5.dp)).background(bar))
+ Row(Modifier.padding(start = 48.dp), horizontalArrangement = Arrangement.spacedBy(16.dp)) {
+ repeat(cards) {
+ Column {
+ Box(Modifier.size(cardSize).clip(RoundedCornerShape(12.dp)).background(bar))
+ Box(Modifier.padding(top = 8.dp).width(cardSize * 0.7f).height(11.dp).clip(RoundedCornerShape(4.dp)).background(bar))
+ }
+ }
+ }
+ }
+}