Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.
Kotlin alternativeandroidandroid-applicationclientglassmorphisminnertubelibrespotliquid-glassspotifyspotify-connectspotifyapiyoutube-musicyoutube-playerytdlnis
Turn the home page into a feed
Lelonio27ab09e8cfff
diff --git a/.claude/settings.local.json b/.claude/settings.local.jsonindex 882b0b2..5276750 100644--- a/.claude/settings.local.json+++ b/.claude/settings.local.json@@ -57,7 +57,8 @@"Bash(sed -n '/^fun LiquidBottomTabs\\(/,/^\\) {/p' app/src/main/java/dev/emanuele/spot/ui/glass/LiquidBottomTabs.kt)","Bash(sed -n '/^fun.*LiquidBottomTab\\\\b/,/^\\) {/p' app/src/main/java/dev/emanuele/spot/ui/glass/LiquidBottomTab.kt)","Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Restore the bottom bar'\\\\''s colours after the file rebuild *)",- "Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Lay the bottom tabs out with LiquidBottomTab *)"+ "Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Lay the bottom tabs out with LiquidBottomTab *)",+ "Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Turn the home page into a feed *)"]}}diff --git a/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin b/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.binindex dcf7aa1..d77276b 100644--- a/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin+++ b/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin@@ -2,27 +2,27 @@ C/C++ Structured Logljh/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/additional_project_files.txtCA-?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint �����3 ����3i+?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint �����3 ����3ig-e/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/android_gradle_build.json �����3� ����3n+e/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/android_gradle_build.json �����3� ����3nl-j/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/android_gradle_build_mini.json �����3� �����3[+j/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/android_gradle_build_mini.json �����3� �����3[Y-W/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build.ninja �����3�� ����3_+W/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build.ninja �����3�� ����3_]-[/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build.ninja.txt �����3d+[/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build.ninja.txt �����3db-`/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build_file_index.txt �����3 @ ����3e+`/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/build_file_index.txt �����3 @ ����3ec-a/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/compile_commands.json �����3�� ����3i+a/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/compile_commands.json �����3�� ����3ig-e/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/compile_commands.json.bin �����3 �" ����3o+e/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/compile_commands.json.bin �����3 �" ����3om-k/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/metadata_generation_command.txt �����3+k/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/metadata_generation_command.txt �����3� ����3b`-^/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/prefab_config.json �����3 ( ����3g+^/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/prefab_config.json �����3 ( ����3ge-c/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/symbol_folder_index.txt �����3 b ����3D+c/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/symbol_folder_index.txt �����3 b ����3DB-@/Users/emanuele/Progetto Spotify/app/src/main/cpp/CMakeLists.txt �����3 � �Ȅ��3\ No newline at end of file+@/Users/emanuele/Progetto Spotify/app/src/main/cpp/CMakeLists.txt �����3 � �Ȅ��3\ No newline at end of filediff --git a/app/src/main/java/dev/emanuele/spot/data/SpotifyApi.kt b/app/src/main/java/dev/emanuele/spot/data/SpotifyApi.ktindex 0e4ca9b..de51282 100644--- a/app/src/main/java/dev/emanuele/spot/data/SpotifyApi.kt+++ b/app/src/main/java/dev/emanuele/spot/data/SpotifyApi.kt@@ -38,6 +38,26 @@ interface SpotifyApi {@Query("offset") offset: Int = 0,): PageDto<PlaylistTrackDto>+ /**+ * Albums and singles released recently.+ *+ * Not personalised — Spotify's own recommendation endpoints were closed to+ * new applications, so this is the closest thing still open, and it is the+ * catalogue's front page rather than the user's. What makes the home feed+ * personal is what surrounds it: their own top artists, their playlists and+ * what they actually played.+ */+ @GET("v1/browse/new-releases")+ suspend fun newReleases(@Query("limit") limit: Int = 12): NewReleasesDto++ /** Needs the `user-top-read` scope; 403 without it. */+ @GET("v1/me/top/artists")+ suspend fun topArtists(+ @Query("limit") limit: Int = 12,+ /** `short_term` is roughly the last month, which is what "lately" means. */+ @Query("time_range") timeRange: String = "short_term",+ ): PageDto<ArtistDto>+/*** An artist's most-played tracks.*@@ -126,11 +146,16 @@ data class AlbumDto(/** ISO date, and not always a full one — Spotify returns bare years too. */@SerialName("release_date") val releaseDate: String? = null,@SerialName("total_tracks") val totalTracks: Int = 0,+ /** Present on browse and search results, absent when an album is nested in a track. */+ val artists: List<ArtistDto> = emptyList(),)@Serializabledata class TopTracksDto(val tracks: List<TrackDto> = emptyList())+@Serializable+data class NewReleasesDto(val albums: PageDto<AlbumDto>? = null)+@Serializabledata class PlaylistDto(val id: String,diff --git a/app/src/main/java/dev/emanuele/spot/ui/MainViewModel.kt b/app/src/main/java/dev/emanuele/spot/ui/MainViewModel.ktindex 3cac1f3..c8b76a0 100644--- a/app/src/main/java/dev/emanuele/spot/ui/MainViewModel.kt+++ b/app/src/main/java/dev/emanuele/spot/ui/MainViewModel.kt@@ -83,6 +83,65 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {)val state: StateFlow<UiState> = _state.asStateFlow()+ /**+ * The home feed's catalogue sections.+ *+ * Everything here comes from the Web API and therefore needs the user's own+ * application, so an empty feed is an ordinary state rather than an error:+ * the rest of the home page — playlists, what was played — works without it.+ */+ data class FeedState(+ val newReleases: List<SearchItem> = emptyList(),+ val topArtists: List<SearchItem> = emptyList(),+ val loading: Boolean = false,+ )++ private val _feed = MutableStateFlow(FeedState())+ val feed: StateFlow<FeedState> = _feed.asStateFlow()+ private var feedJob: Job? = null++ /**+ * Loads the feed, quietly.+ *+ * Each section is fetched on its own and a failure drops just that section:+ * top artists need the `user-top-read` scope, and an account that connected+ * its application before that scope was asked for answers 403 there while+ * everything else still works. One combined call would lose the lot.+ */+ fun loadFeed() {+ if (!container.webApi.isReady || feedJob?.isActive == true) return+ if (_feed.value.newReleases.isNotEmpty()) return++ _feed.value = _feed.value.copy(loading = true)+ feedJob = viewModelScope.launch {+ val releases = runCatching {+ container.api.newReleases().albums?.items.orEmpty().mapNotNull { album ->+ SearchItem(+ uri = album.uri ?: return@mapNotNull null,+ title = album.name,+ subtitle = album.artists.joinToString(", ") { it.name },+ artworkUrl = album.images.firstOrNull()?.url,+ )+ }+ }.onFailure { android.util.Log.w(TAG, "new releases unavailable: ${describe(it)}") }+ .getOrDefault(emptyList())++ val artists = runCatching {+ container.api.topArtists().items.mapNotNull { artist ->+ SearchItem(+ uri = artist.uri ?: return@mapNotNull null,+ title = artist.name,+ subtitle = "Artista",+ artworkUrl = artist.images.firstOrNull()?.url,+ )+ }+ }.onFailure { android.util.Log.w(TAG, "top artists unavailable: ${describe(it)}") }+ .getOrDefault(emptyList())++ _feed.value = FeedState(newReleases = releases, topArtists = artists, loading = false)+ }+ }+private val _playlist = MutableStateFlow(PlaylistState())val playlist: StateFlow<PlaylistState> = _playlist.asStateFlow()@@ -173,15 +232,24 @@ class MainViewModel(app: Application) : AndroidViewModel(app) {_webApi.value = _webApi.value.copy(connecting = true, error = null)container.webApi.setClientId(clientId)runCatching {- // No scopes: search reads public catalogue data, and asking for- // permissions the feature does not use would put a consent screen in- // front of the user for nothing.- SpotifyOAuth.authorize(getApplication(), clientId = clientId, scopes = emptyList())+ // Search needs no scope — it reads public catalogue data — but the+ // home feed's "artisti che ascolti" is the user's own listening,+ // and that is gated behind `user-top-read`. It is the only+ // permission asked for, and an account connected before this+ // existed keeps working: the section simply stays empty until the+ // application is reconnected.+ SpotifyOAuth.authorize(+ getApplication(),+ clientId = clientId,+ scopes = listOf("user-top-read"),+ )}.onSuccess {container.webApi.tokens.save(it)_webApi.value = _webApi.value.copy(connecting = false, connected = true)_search.value = _search.value.copy(needsSetup = false)+ // The feed could not have loaded before this point.+ loadFeed()// Re-run whatever the user had already typed._search.value.query.takeIf { q -> q.isNotBlank() }?.let(::onSearchQuery)}diff --git a/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt b/app/src/main/java/dev/emanuele/spot/ui/SpotApp.ktindex 16f990c..73ebe10 100644--- a/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt+++ b/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt@@ -121,6 +121,12 @@ fun SpotApp(val webApi by viewModel.webApi.collectAsStateWithLifecycle()val reverb by AudioEffects.reverb.collectAsStateWithLifecycle()val presets by viewModel.effectPresets.collectAsStateWithLifecycle()+ val feed by viewModel.feed.collectAsStateWithLifecycle()++ // Once, on the first composition that has a usable Web API session. The+ // ViewModel keeps what it fetched, so navigating away and back does not+ // spend the quota again.+ LaunchedEffect(webApi.connected) { viewModel.loadFeed() }// Two layers, and the split is not optional.//// `pageBackdrop` records the artwork *and* the screen on top of it, and is@@ -235,6 +241,11 @@ fun SpotApp(onOpenPlayer = { navController.navigate(Routes.PLAYER) },recent = recent,onPlayRecent = onPlay,+ feed = feed,+ onOpenItem = { item ->+ viewModel.openContext(item.uri, item.title, item.artworkUrl)+ navController.navigate(Routes.PLAYLIST)+ },)}diff --git a/app/src/main/java/dev/emanuele/spot/ui/home/HomeScreen.kt b/app/src/main/java/dev/emanuele/spot/ui/home/HomeScreen.ktindex 22007ee..660bf19 100644--- a/app/src/main/java/dev/emanuele/spot/ui/home/HomeScreen.kt+++ b/app/src/main/java/dev/emanuele/spot/ui/home/HomeScreen.kt@@ -1,5 +1,6 @@package dev.emanuele.spot.ui.home+import androidx.compose.foundation.backgroundimport androidx.compose.foundation.clickableimport androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Box@@ -16,6 +17,7 @@ import androidx.compose.foundation.lazy.LazyColumnimport androidx.compose.foundation.lazy.LazyRowimport androidx.compose.foundation.lazy.itemsimport androidx.compose.foundation.lazy.itemsIndexed+import androidx.compose.foundation.shape.CircleShapeimport androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.material3.Buttonimport androidx.compose.material3.CircularProgressIndicator@@ -26,10 +28,14 @@ import androidx.compose.runtime.Composableimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.clip+import androidx.compose.ui.graphics.Brush+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.text.style.TextOverflowimport androidx.compose.ui.unit.dpimport dev.emanuele.spot.data.CatalogPlaylistimport dev.emanuele.spot.data.CatalogTrack+import dev.emanuele.spot.data.SearchItemimport dev.emanuele.spot.ui.MainViewModelimport dev.emanuele.spot.ui.components.Artworkimport dev.emanuele.spot.ui.player.PlaybackState@@ -48,6 +54,8 @@ fun HomeScreen(onOpenPlayer: () -> Unit,recent: List<CatalogTrack>,onPlayRecent: (List<CatalogTrack>, Int) -> Unit,+ feed: MainViewModel.FeedState,+ onOpenItem: (SearchItem) -> Unit,) {when (state) {MainViewModel.UiState.LoggedOut -> Centered {@@ -107,6 +115,42 @@ fun HomeScreen(}}+ if (feed.newReleases.isNotEmpty()) {+ item(contentType = "section") {+ SectionTitle("Novità", Modifier.padding(top = 30.dp))+ }+ // Cards rather than another row of thumbnails, and only a few of+ // them. A carousel says "here is a list, pick one"; this section+ // is meant to be looked at, so each release gets the width of the+ // screen and the cover is allowed to carry it. Six, because a+ // feed that never ends turns the sections below it into+ // something nobody scrolls to.+ items(+ feed.newReleases.take(FEED_SIZE),+ key = { it.uri },+ contentType = { "feedCard" },+ ) { item ->+ FeedCard(item) { onOpenItem(item) }+ }+ }++ if (feed.topArtists.isNotEmpty()) {+ item(contentType = "section") {+ SectionTitle("Artisti che ascolti", Modifier.padding(top = 34.dp))+ }+ item(contentType = "artists") {+ LazyRow(+ contentPadding = PaddingValues(horizontal = 24.dp),+ horizontalArrangement = Arrangement.spacedBy(14.dp),+ modifier = Modifier.padding(top = 14.dp),+ ) {+ items(feed.topArtists, key = { it.uri }) { artist ->+ ArtistTile(artist) { onOpenItem(artist) }+ }+ }+ }+ }+item(contentType = "section") {SectionTitle("Le tue playlist", Modifier.padding(top = 30.dp))}@@ -204,6 +248,102 @@ private fun ResumeCard(playback: PlaybackState, onClick: () -> Unit) {}}+/**+ * One release, the full width of the page.+ *+ * The title sits *on* the cover rather than under it. Every other listing in+ * this app puts a caption beneath a square, which is right when you are+ * scanning a row of twenty; here there are six, and the point is that each one+ * is worth stopping on. The gradient exists because covers are not designed to+ * have text over them — without it the title lands on whatever the artwork+ * happens to be doing in that corner.+ */+@Composable+private fun FeedCard(item: SearchItem, onClick: () -> Unit) {+ val shape = RoundedCornerShape(26.dp)+ Box(+ Modifier+ .padding(horizontal = 20.dp, vertical = 8.dp)+ .fillMaxWidth()+ .height(300.dp)+ .softShadow(shape, elevation = 20.dp, spot = 0.22f)+ .clip(shape)+ .clickable(onClick = onClick),+ ) {+ Artwork(+ url = item.artworkUrl,+ title = item.title,+ modifier = Modifier.fillMaxSize(),+ corner = 0.dp,+ )++ Box(+ Modifier+ .fillMaxSize()+ .background(+ Brush.verticalGradient(+ 0f to Color.Transparent,+ 0.45f to Color.Black.copy(alpha = 0.25f),+ 1f to Color.Black.copy(alpha = 0.80f),+ ),+ ),+ )++ Column(+ Modifier+ .align(Alignment.BottomStart)+ .padding(20.dp),+ ) {+ Text(+ item.title,+ style = MaterialTheme.typography.headlineLarge,+ color = Color.White,+ maxLines = 2,+ overflow = TextOverflow.Ellipsis,+ )+ if (item.subtitle.isNotBlank()) {+ Text(+ item.subtitle,+ style = MaterialTheme.typography.bodyMedium,+ color = Color.White.copy(alpha = 0.75f),+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ modifier = Modifier.padding(top = 2.dp),+ )+ }+ }+ }+}++/** Round, because that is how every music app has drawn an artist for a decade. */+@Composable+private fun ArtistTile(artist: SearchItem, onClick: () -> Unit) {+ Column(+ Modifier+ .width(112.dp)+ .clickable(onClick = onClick),+ horizontalAlignment = Alignment.CenterHorizontally,+ ) {+ Artwork(+ url = artist.artworkUrl,+ title = artist.title,+ modifier = Modifier+ .size(112.dp)+ .softShadow(CircleShape, elevation = 12.dp),+ corner = 56.dp,+ decodeSize = 112.dp,+ )+ Text(+ artist.title,+ style = MaterialTheme.typography.bodyMedium,+ maxLines = 2,+ overflow = TextOverflow.Ellipsis,+ textAlign = TextAlign.Center,+ modifier = Modifier.padding(top = 10.dp),+ )+ }+}+@Composableprivate fun TrackTile(track: CatalogTrack, onClick: () -> Unit) {Column(@@ -318,5 +458,6 @@ private fun greeting(): String = when (Calendar.getInstance().get(Calendar.HOUR_else -> "Buonasera"}+private const val FEED_SIZE = 6private const val CAROUSEL_SIZE = 8private const val REST_SIZE = 6