Skip to content

Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.

Collapsing home header, sharper cards, library rewrite

Leloniof90605a6ceac
diff --git a/.claude/settings.local.json b/.claude/settings.local.json
index 4e02bc4..feb4880 100644
--- a/.claude/settings.local.json
+++ b/.claude/settings.local.json
@@ -60,7 +60,8 @@
"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 *)",
"Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Rewrite the home page on the glass material *)",
- "Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Home: profile header, recency-ordered playlists, plainer cards *)"
+ "Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Home: profile header, recency-ordered playlists, plainer cards *)",
+ "Bash(git -c user.name=Emanuele -c [email protected] commit -qm 'Collapsing home header, sharper cards, library rewrite *)"
]
}
}
diff --git a/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin b/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/configure_fingerprint.bin
index 769c936..57a01c2 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 Logl
j
h/Users/emanuele/Progetto Spotify/app/.cxx/RelWithDebInfo/151m4dr6/arm64-v8a/additional_project_files.txtC
A
-?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint  �����3  ����3i
+?com.android.build.gradle.internal.cxx.io.EncodedFileFingerPrint  �����3  ����3i
g
-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� ����3n
l
-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  �����3d
b
-`/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 @ ����3e
c
-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�� ����3i
g
-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 �" ����3o
m
-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  ( ����3g
e
-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 ����3D
B
-@/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 file
diff --git a/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt b/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt
index 0e37434..8c0c14a 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/SpotApp.kt
@@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
+import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBars
@@ -50,6 +51,7 @@ import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
+import androidx.compose.ui.zIndex
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.media3.common.PlaybackParameters
@@ -277,6 +279,8 @@ fun SpotApp(
onRetry = { viewModel.refresh() },
onLogOut = viewModel::logOut,
onOpenPlaylist = { navController.openPlaylist(viewModel, it) },
+ playlistOrder = playlistOrder,
+ backdrop = artBackdrop,
)
}
@@ -484,12 +488,37 @@ private fun BottomBar(
.padding(bottom = bottomInset + 8.dp, top = 4.dp),
verticalAlignment = Alignment.CenterVertically,
) {
- LiquidBottomTabs(
+ Box(Modifier.weight(1f)) {
+ // While the search screen is open, taps on the tabs have to be
+ // caught here rather than by the bar.
+ //
+ // The bar draws its sliding indicator *over* the selected tab, and
+ // that indicator carries the drag gesture, so it swallows taps on
+ // whatever it is sitting on. Search is not one of the tabs, so the
+ // selection falls back to Home — and tapping Home then hit the
+ // indicator, matched the index the bar already held, and produced no
+ // event at all. That was the "search does not close" bug.
+ if (route == Routes.SEARCH) {
+ Row(Modifier.matchParentSize().zIndex(1f)) {
+ routes.forEach { tab ->
+ Box(
+ Modifier
+ .weight(1f)
+ .fillMaxHeight()
+ .clickable(
+ interactionSource = null,
+ indication = null,
+ ) { onSelect(tab) },
+ )
+ }
+ }
+ }
+
+ LiquidBottomTabs(
selectedTabIndex = selectedTabIndex,
onTabSelected = { onSelect(routes[it]) },
backdrop = backdrop,
tabsCount = routes.size,
- modifier = Modifier.weight(1f),
// Both upstream defaults are wrong here: the accent is a system blue
// that belongs to no part of this palette, and the container is a
// 40% fill that made the bar a solid slab beside the other glass.
@@ -505,6 +534,7 @@ private fun BottomBar(
Icons.Outlined.LibraryMusic,
selected == 1,
) { onSelect(Routes.LIBRARY) }
+ }
}
Spacer(Modifier.width(10.dp))
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.kt
index 88ea8bc..336e736 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
@@ -14,6 +14,7 @@ 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.rememberLazyListState
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
@@ -23,18 +24,24 @@ import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.derivedStateOf
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.blur
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.TransformOrigin
+import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.lerp
import com.kyant.backdrop.Backdrop
import dev.emanuele.spot.data.CatalogPlaylist
import dev.emanuele.spot.data.CatalogTrack
@@ -133,49 +140,44 @@ fun HomeScreen(
val showArtists = filter == Feed.ALL || filter == Feed.ARTISTS
val showLibrary = filter == Feed.ALL || filter == Feed.LIBRARY
- LazyColumn(Modifier.fillMaxSize(), contentPadding = contentPadding) {
- item(contentType = "greeting") {
- Row(
- Modifier
- .fillMaxWidth()
- .padding(start = 24.dp, end = 24.dp, top = 34.dp),
- verticalAlignment = Alignment.CenterVertically,
- ) {
- Column(Modifier.weight(1f)) {
- Text(
- greeting().uppercase(),
- style = MaterialTheme.typography.labelLarge,
- color = InkDim,
- )
- Text(
- state.displayName,
- style = MaterialTheme.typography.displayLarge,
- maxLines = 1,
- overflow = TextOverflow.Ellipsis,
- modifier = Modifier.padding(top = 2.dp),
- )
- }
+ val listState = rememberLazyListState()
- // Falls back to the generated cover keyed on the name,
- // which is the same thing every other missing image in
- // the app gets rather than a grey circle.
- Artwork(
- url = state.avatarUrl,
- title = state.displayName,
- modifier = Modifier
- .padding(start = 14.dp)
- .size(46.dp)
- .softShadow(CircleShape, elevation = 10.dp),
- corner = 23.dp,
- decodeSize = 46.dp,
- )
- }
+ // How far the header has collapsed, 0 to 1.
+ //
+ // Read from the list rather than driven by a nested-scroll
+ // connection: the header is a sibling of the list, not part of it,
+ // so it never consumes scroll and the list keeps its own fling
+ // untouched. Past the first item the header is simply fully
+ // collapsed — asking for the exact offset of something scrolled far
+ // off screen means measuring items that no longer exist.
+ val collapse by remember {
+ derivedStateOf {
+ if (listState.firstVisibleItemIndex > 0) 1f
+ else (listState.firstVisibleItemScrollOffset / COLLAPSE_DISTANCE_PX)
+ .coerceIn(0f, 1f)
}
+ }
- item(contentType = "filters") {
- FilterRow(filter, backdrop) { filter = it }
- }
+ Column(Modifier.fillMaxSize()) {
+ Header(
+ name = state.displayName,
+ avatarUrl = state.avatarUrl,
+ collapse = collapse,
+ filter = filter,
+ backdrop = backdrop,
+ topPadding = contentPadding.calculateTopPadding(),
+ onFilter = { filter = it },
+ )
+ LazyColumn(
+ Modifier.fillMaxSize(),
+ state = listState,
+ // The header already covers the status bar, so only the
+ // bottom inset is left for the list.
+ contentPadding = PaddingValues(
+ bottom = contentPadding.calculateBottomPadding(),
+ ),
+ ) {
if (showReleases && feed.newReleases.isNotEmpty()) {
item(contentType = "heading") { Heading("Novità") }
// Cards rather than another row of thumbnails. A carousel
@@ -228,11 +230,94 @@ fun HomeScreen(
}
item(contentType = "tail") { Box(Modifier.height(24.dp)) }
+ }
}
}
}
}
+/**
+ * Name, picture and filters, always on screen.
+ *
+ * It shrinks rather than sliding away: the filter chips are a control, and a
+ * control that has to be scrolled back to before it can be used may as well not
+ * be there. What collapses is only the part that is decoration — the greeting
+ * line and the size of the name.
+ */
+@Composable
+private fun Header(
+ name: String,
+ avatarUrl: String?,
+ collapse: Float,
+ filter: Feed,
+ backdrop: Backdrop,
+ topPadding: Dp,
+ onFilter: (Feed) -> Unit,
+) {
+ Column(
+ Modifier
+ .fillMaxWidth()
+ .padding(top = topPadding),
+ ) {
+ Row(
+ Modifier
+ .fillMaxWidth()
+ .padding(
+ start = 24.dp,
+ end = 24.dp,
+ top = lerp(20.dp, 6.dp, collapse),
+ ),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Column(Modifier.weight(1f)) {
+ // Height goes with the alpha. Fading it alone would leave the
+ // header the same size with a blank line in it.
+ if (collapse < 1f) {
+ Text(
+ greeting().uppercase(),
+ style = MaterialTheme.typography.labelLarge,
+ color = InkDim,
+ maxLines = 1,
+ modifier = Modifier
+ .height(lerp(18.dp, 0.dp, collapse))
+ .graphicsLayer { alpha = 1f - collapse },
+ )
+ }
+ Text(
+ name,
+ style = MaterialTheme.typography.displayLarge,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ // Scaled rather than swapped for a smaller style: a style
+ // change is a jump, and this has to track a finger.
+ modifier = Modifier.graphicsLayer {
+ val scale = 1f - 0.34f * collapse
+ scaleX = scale
+ scaleY = scale
+ transformOrigin = TransformOrigin(0f, 0.5f)
+ },
+ )
+ }
+
+ // Falls back to the generated cover keyed on the name, which is what
+ // every other missing image in the app gets rather than a grey
+ // circle.
+ Artwork(
+ url = avatarUrl,
+ title = name,
+ modifier = Modifier
+ .padding(start = 14.dp)
+ .size(lerp(46.dp, 36.dp, collapse))
+ .softShadow(CircleShape, elevation = 10.dp),
+ corner = 23.dp,
+ decodeSize = 46.dp,
+ )
+ }
+
+ FilterRow(filter, backdrop, onFilter)
+ }
+}
+
@Composable
private fun FilterRow(selected: Feed, backdrop: Backdrop, onSelect: (Feed) -> Unit) {
LazyRow(
@@ -276,56 +361,63 @@ private fun FeedCard(item: SearchItem, onClick: () -> Unit) {
val shape = RoundedCornerShape(28.dp)
Box(
Modifier
- .padding(horizontal = 20.dp, vertical = 7.dp)
+ .padding(horizontal = 20.dp, vertical = 8.dp)
.fillMaxWidth()
- .height(320.dp)
- .softShadow(shape, elevation = 22.dp, spot = 0.24f)
+ .softShadow(shape, elevation = 26.dp, spot = 0.55f)
.clip(shape)
.clickable(onClick = onClick),
) {
+ // The same cover twice, and that is the point.
+ //
+ // Spotify serves album art at 640px and no larger, so a cover stretched
+ // across a 1080px-wide card is upscaled by nearly two and looks soft —
+ // which is exactly the "low quality covers" this replaced. Blurred, that
+ // upscaling is invisible, so the background can be full width while the
+ // cover that has to be sharp is displayed well under its native size.
Artwork(
url = item.artworkUrl,
title = item.title,
- modifier = Modifier.fillMaxSize(),
+ modifier = Modifier
+ .matchParentSize()
+ .blur(36.dp),
corner = 0.dp,
+ decodeSize = 200.dp,
)
-
- // The caption sits straight on the cover, so this gradient is what makes
- // it readable rather than decoration. Weighted to the bottom third: any
- // higher and it starts dimming the part of the picture the card exists
- // to show.
- Box(
- Modifier
- .fillMaxSize()
- .background(
- Brush.verticalGradient(
- 0f to Color.Transparent,
- 0.55f to Color.Black.copy(alpha = 0.18f),
- 1f to Color.Black.copy(alpha = 0.78f),
- ),
- ),
- )
+ Box(Modifier.matchParentSize().background(Color.Black.copy(alpha = 0.42f)))
Column(
Modifier
- .align(Alignment.BottomStart)
- .padding(horizontal = 22.dp, vertical = 20.dp),
+ .fillMaxWidth()
+ .padding(20.dp),
+ horizontalAlignment = Alignment.CenterHorizontally,
) {
+ Artwork(
+ url = item.artworkUrl,
+ title = item.title,
+ modifier = Modifier
+ .size(COVER_SIZE)
+ .softShadow(RoundedCornerShape(18.dp), elevation = 24.dp, spot = 0.5f),
+ corner = 18.dp,
+ decodeSize = COVER_SIZE,
+ )
Text(
item.title,
style = MaterialTheme.typography.headlineLarge,
color = Color.White,
+ textAlign = TextAlign.Center,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
+ modifier = Modifier.padding(top = 18.dp),
)
if (item.subtitle.isNotBlank()) {
Text(
item.subtitle,
style = MaterialTheme.typography.bodyMedium,
color = Color.White.copy(alpha = 0.76f),
+ textAlign = TextAlign.Center,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
- modifier = Modifier.padding(top = 2.dp),
+ modifier = Modifier.padding(top = 3.dp),
)
}
}
@@ -480,6 +572,18 @@ private fun greeting(): String = when (Calendar.getInstance().get(Calendar.HOUR_
/** A harder film for the chip that is on; see the note at the call site. */
private val SelectedFilm = Color.White.copy(alpha = 0.26f)
+/**
+ * How far the list scrolls before the header is fully collapsed, in pixels.
+ *
+ * Pixels rather than dp because it is compared against a scroll offset, which
+ * the list reports in pixels; converting per frame to compare two numbers would
+ * be work for nothing.
+ */
+private const val COLLAPSE_DISTANCE_PX = 140f
+
+/** Comfortably under the 640px Spotify serves, so it is never upscaled. */
+private val COVER_SIZE = 210.dp
+
private const val FEED_SIZE = 6
private const val CAROUSEL_SIZE = 8
diff --git a/app/src/main/java/dev/emanuele/spot/ui/library/LibraryScreen.kt b/app/src/main/java/dev/emanuele/spot/ui/library/LibraryScreen.kt
index 8fdad9c..d4235ca 100644
--- a/app/src/main/java/dev/emanuele/spot/ui/library/LibraryScreen.kt
+++ b/app/src/main/java/dev/emanuele/spot/ui/library/LibraryScreen.kt
@@ -8,25 +8,65 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
+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.LazyColumn
import androidx.compose.foundation.lazy.items
-import androidx.compose.material3.Button
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.automirrored.filled.List
+import androidx.compose.material.icons.filled.GridView
import androidx.compose.material3.CircularProgressIndicator
-import androidx.compose.material3.HorizontalDivider
+import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
-import androidx.compose.material3.TextButton
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.graphics.Color
+import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
+import com.kyant.backdrop.Backdrop
import dev.emanuele.spot.data.CatalogPlaylist
+import dev.emanuele.spot.data.sortedByRecentlyOpened
import dev.emanuele.spot.ui.MainViewModel
import dev.emanuele.spot.ui.components.Artwork
+import dev.emanuele.spot.ui.glass.LiquidButton
+import dev.emanuele.spot.ui.player.GlassFilm
+import dev.emanuele.spot.ui.theme.Ink
+import dev.emanuele.spot.ui.theme.InkDim
+import dev.emanuele.spot.ui.theme.softShadow
+/** How the playlists are arranged. */
+private enum class Layout { GRID, LIST }
+
+/** What the library is sorted by. */
+private enum class Order(val label: String) {
+ RECENT("Aperte di recente"),
+ NAME("Nome"),
+ ADDED("Ordine di Spotify"),
+}
+
+/**
+ * Every playlist on the account.
+ *
+ * Rewritten alongside the home page and for the same reason: this was a plain
+ * Material list with a divider between every row, which is the one thing on
+ * screen that cannot be made of glass. It is now the same material as the rest —
+ * and, being the screen you come to when you know what you are looking for, it
+ * gets the controls the home page has no room for: a grid, and a sort.
+ */
@Composable
fun LibraryScreen(
state: MainViewModel.UiState,
@@ -35,6 +75,9 @@ fun LibraryScreen(
onRetry: () -> Unit,
onLogOut: () -> Unit,
onOpenPlaylist: (CatalogPlaylist) -> Unit,
+ /** URIs most recently opened first; see PlaylistOrderStore. */
+ playlistOrder: List<String>,
+ backdrop: Backdrop,
) {
when (state) {
MainViewModel.UiState.LoggedOut -> Centered {
@@ -42,111 +85,244 @@ fun LibraryScreen(
Text(
"Client non ufficiale per account Premium",
style = MaterialTheme.typography.bodyMedium,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- )
- Button(onClick = onLogIn, modifier = Modifier.padding(top = 14.dp)) {
- Text("Accedi con Spotify")
- }
- }
-
- MainViewModel.UiState.Connecting -> Centered {
- CircularProgressIndicator(
- color = MaterialTheme.colorScheme.primary,
- strokeWidth = 2.dp,
- )
- Text(
- "Connessione…",
- style = MaterialTheme.typography.labelLarge,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
+ color = InkDim,
+ textAlign = TextAlign.Center,
+ modifier = Modifier.padding(horizontal = 40.dp),
)
+ GlassAction("Accedi con Spotify", backdrop, onLogIn)
}
- MainViewModel.UiState.Loading -> Centered {
- CircularProgressIndicator(
- color = MaterialTheme.colorScheme.primary,
- strokeWidth = 2.dp,
- )
+ MainViewModel.UiState.Connecting,
+ MainViewModel.UiState.Loading,
+ -> Centered {
+ CircularProgressIndicator(color = Ink, strokeWidth = 2.dp)
}
is MainViewModel.UiState.Failed -> Centered {
Text(
state.message,
style = MaterialTheme.typography.bodyMedium,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
+ color = InkDim,
+ textAlign = TextAlign.Center,
modifier = Modifier.padding(horizontal = 40.dp),
)
- Button(onClick = onRetry) { Text("Riprova") }
- TextButton(onClick = onLogOut) { Text("Esci") }
+ GlassAction("Riprova", backdrop, onRetry)
+ GlassAction("Esci", backdrop, onLogOut)
}
- is MainViewModel.UiState.Ready -> LazyColumn(
- modifier = Modifier.fillMaxSize(),
- contentPadding = contentPadding,
- ) {
- item(contentType = "header") {
- Column(Modifier.padding(start = 24.dp, end = 24.dp, top = 40.dp, bottom = 28.dp)) {
- Text(
- state.displayName.uppercase(),
- style = MaterialTheme.typography.labelLarge,
- color = MaterialTheme.colorScheme.primary,
- )
- Text(
- "Libreria",
- style = MaterialTheme.typography.displayLarge,
- modifier = Modifier.padding(top = 2.dp),
- )
- Text(
- "${state.playlists.size} playlist",
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- modifier = Modifier.padding(top = 6.dp),
+ is MainViewModel.UiState.Ready -> {
+ var layout by remember { mutableStateOf(Layout.GRID) }
+ var order by remember { mutableStateOf(Order.RECENT) }
+
+ val playlists = remember(state.playlists, playlistOrder, order) {
+ when (order) {
+ Order.RECENT -> state.playlists.sortedByRecentlyOpened(playlistOrder)
+ Order.NAME -> state.playlists.sortedWith(
+ compareBy(String.CASE_INSENSITIVE_ORDER) { it.name },
)
+ // The order the account added them, which is what the
+ // rootlist arrives in.
+ Order.ADDED -> state.playlists
}
}
- // contentType lets the lazy list reuse row layouts instead of
- // rebuilding one per item as it scrolls.
- items(state.playlists, key = { it.uri }, contentType = { "playlist" }) { playlist ->
- PlaylistRow(playlist) { onOpenPlaylist(playlist) }
+ Column(Modifier.fillMaxSize()) {
+ Header(
+ count = playlists.size,
+ layout = layout,
+ order = order,
+ backdrop = backdrop,
+ topPadding = contentPadding.calculateTopPadding(),
+ onLayout = { layout = it },
+ onOrder = { order = it },
+ )
+
+ val listPadding = PaddingValues(
+ start = 20.dp,
+ end = 20.dp,
+ top = 8.dp,
+ bottom = contentPadding.calculateBottomPadding(),
+ )
+
+ when (layout) {
+ Layout.GRID -> LazyVerticalGrid(
+ columns = GridCells.Fixed(2),
+ contentPadding = listPadding,
+ horizontalArrangement = Arrangement.spacedBy(14.dp),
+ verticalArrangement = Arrangement.spacedBy(18.dp),
+ modifier = Modifier.fillMaxSize(),
+ ) {
+ items(playlists, key = { it.uri }) { playlist ->
+ GridTile(playlist) { onOpenPlaylist(playlist) }
+ }
+ }
+
+ Layout.LIST -> LazyColumn(
+ contentPadding = listPadding,
+ verticalArrangement = Arrangement.spacedBy(4.dp),
+ modifier = Modifier.fillMaxSize(),
+ ) {
+ items(playlists, key = { it.uri }) { playlist ->
+ ListRow(playlist) { onOpenPlaylist(playlist) }
+ }
+ }
+ }
}
}
}
}
@Composable
-private fun PlaylistRow(playlist: CatalogPlaylist, onClick: () -> Unit) {
- Column {
+private fun Header(
+ count: Int,
+ layout: Layout,
+ order: Order,
+ backdrop: Backdrop,
+ topPadding: Dp,
+ onLayout: (Layout) -> Unit,
+ onOrder: (Order) -> Unit,
+) {
+ Column(
+ Modifier
+ .fillMaxWidth()
+ .padding(top = topPadding),
+ ) {
Row(
- modifier = Modifier
+ Modifier
.fillMaxWidth()
- .clickable(onClick = onClick)
- .padding(horizontal = 24.dp, vertical = 12.dp),
+ .padding(start = 24.dp, end = 20.dp, top = 16.dp),
verticalAlignment = Alignment.CenterVertically,
) {
- Artwork(
- url = playlist.artworkUrl,
- title = playlist.name,
- modifier = Modifier.size(46.dp),
- corner = 14.dp,
- decodeSize = 46.dp,
- )
- Text(
- text = playlist.name,
- style = MaterialTheme.typography.titleMedium,
- maxLines = 2,
- overflow = TextOverflow.Ellipsis,
- modifier = Modifier
- .padding(start = 16.dp)
- .weight(1f),
- )
+ Column(Modifier.weight(1f)) {
+ Text("Libreria", style = MaterialTheme.typography.displayLarge)
+ Text(
+ "$count playlist",
+ style = MaterialTheme.typography.bodySmall,
+ color = InkDim,
+ )
+ }
+
+ // One button that swaps between the two arrangements rather than a
+ // pair of them: with two options, a toggle showing the *other* one
+ // is both smaller and unambiguous.
+ LiquidButton(
+ onClick = { onLayout(if (layout == Layout.GRID) Layout.LIST else Layout.GRID) },
+ backdrop = backdrop,
+ modifier = Modifier.size(42.dp),
+ contentHeight = 42.dp,
+ contentPadding = 0.dp,
+ blurRadius = 8.dp,
+ surfaceColor = GlassFilm,
+ ) {
+ Icon(
+ if (layout == Layout.GRID) Icons.AutoMirrored.Filled.List
+ else Icons.Filled.GridView,
+ contentDescription = "Cambia disposizione",
+ tint = Ink,
+ modifier = Modifier.size(20.dp),
+ )
+ }
}
- HorizontalDivider(
- modifier = Modifier.padding(start = 86.dp, end = 24.dp),
- color = MaterialTheme.colorScheme.outlineVariant,
+
+ // The sort is three chips rather than a menu: there are only three, and
+ // a menu hides which one is active behind a tap.
+ Row(
+ Modifier
+ .fillMaxWidth()
+ .padding(start = 20.dp, end = 20.dp, top = 14.dp, bottom = 6.dp),
+ horizontalArrangement = Arrangement.spacedBy(8.dp),
+ ) {
+ Order.entries.forEach { entry ->
+ val selected = entry == order
+ LiquidButton(
+ onClick = { onOrder(entry) },
+ backdrop = backdrop,
+ contentHeight = 36.dp,
+ contentPadding = 14.dp,
+ blurRadius = 8.dp,
+ surfaceColor = if (selected) SelectedFilm else GlassFilm,
+ ) {
+ Text(
+ entry.label,
+ style = MaterialTheme.typography.bodySmall,
+ color = if (selected) Ink else InkDim,
+ maxLines = 1,
+ )
+ }
+ }
+ }
+ }
+}
+
+@Composable
+private fun GridTile(playlist: CatalogPlaylist, onClick: () -> Unit) {
+ Column(Modifier.clickable(onClick = onClick)) {
+ Artwork(
+ url = playlist.artworkUrl,
+ title = playlist.name,
+ modifier = Modifier
+ .fillMaxWidth()
+ .aspectRatio(1f)
+ .softShadow(RoundedCornerShape(20.dp), elevation = 18.dp, spot = 0.4f),
+ corner = 20.dp,
+ decodeSize = 220.dp,
+ )
+ Text(
+ playlist.name,
+ style = MaterialTheme.typography.titleMedium,
+ maxLines = 2,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier.padding(top = 10.dp, start = 2.dp, end = 2.dp),
)
}
}
+@Composable
+private fun ListRow(playlist: CatalogPlaylist, onClick: () -> Unit) {
+ Row(
+ Modifier
+ .fillMaxWidth()
+ .clip(RoundedCornerShape(16.dp))
+ .clickable(onClick = onClick)
+ .padding(vertical = 8.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Artwork(
+ url = playlist.artworkUrl,
+ title = playlist.name,
+ modifier = Modifier
+ .size(52.dp)
+ .softShadow(RoundedCornerShape(14.dp), elevation = 10.dp),
+ corner = 14.dp,
+ decodeSize = 52.dp,
+ )
+ Text(
+ playlist.name,
+ style = MaterialTheme.typography.titleMedium,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier
+ .padding(start = 16.dp)
+ .weight(1f),
+ )
+ }
+}
+
+/** A glass pill, for the handful of places that need a button at all. */
+@Composable
+private fun GlassAction(label: String, backdrop: Backdrop, onClick: () -> Unit) {
+ LiquidButton(
+ onClick = onClick,
+ backdrop = backdrop,
+ contentHeight = 50.dp,
+ contentPadding = 26.dp,
+ blurRadius = 8.dp,
+ surfaceColor = GlassFilm,
+ ) {
+ Text(label, style = MaterialTheme.typography.titleMedium, color = Ink)
+ }
+}
+
@Composable
private fun Centered(content: @Composable () -> Unit) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
@@ -156,3 +332,6 @@ private fun Centered(content: @Composable () -> Unit) {
) { content() }
}
}
+
+/** A harder film for the chip that is on, matching the home page. */
+private val SelectedFilm = Color.White.copy(alpha = 0.26f)