Skip to content

Native Android client for Spotify, built with Jetpack Compose

Motion where things popped: pages fade in over their placeholder (not when shown from the cache), placeholders fade in after their delay, play and pause morph on every big play button and in both looks' players, toggles (shuffle, save, follow, download) fade their colour, the Classic queue is keyed by song so removing or skipping slides the rows, Immersive home shelves fade in over the skeleton; all short (150 to 220 ms) and off with Remove animations

kota-zo152a4e39c6e4
diff --git a/base/app/src/main/java/com/music/spotui/ui/components/AppComponents.kt b/base/app/src/main/java/com/music/spotui/ui/components/AppComponents.kt
index 54bc44d1..d1338c63 100644
--- a/base/app/src/main/java/com/music/spotui/ui/components/AppComponents.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/components/AppComponents.kt
@@ -62,46 +62,64 @@ import kotlinx.coroutines.delay
/**
* Loading placeholder, as in the official app: static grey shapes of the page to
* come, no spinner. Shown only if loading lasts (cached pages appear without it),
- * and never animated (no frames spent while waiting).
+ * with a short fade in, then still (no frames spent while waiting).
*/
@Composable
fun Loader(kind: SkeletonKind = SkeletonKind.List) {
- var visible by remember { mutableStateOf(false) }
- LaunchedEffect(Unit) { delay(200); visible = true }
+ val shown = placeholderAlpha()
Column(
Modifier
.fillMaxSize()
.background(Color(AppBackground.toArgb()))
.padding(horizontal = 16.dp, vertical = 12.dp),
) {
- if (!visible) return@Column
+ if (shown.value == 0f) return@Column
val tile = tone(0xFF242424)
val line = tone(0xFF2A2A2A)
- when (kind) {
- SkeletonKind.Home -> {
- repeat(4) {
- Row(Modifier.fillMaxWidth().padding(bottom = 8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
- repeat(2) { Box(Modifier.weight(1f).height(56.dp).clip(RoundedCornerShape(4.dp)).background(tile)) }
+ // The shapes fade in, the page's background stays opaque under them.
+ Column(Modifier.fillMaxWidth().graphicsLayer { alpha = shown.value }) {
+ when (kind) {
+ SkeletonKind.Home -> {
+ repeat(4) {
+ Row(Modifier.fillMaxWidth().padding(bottom = 8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
+ repeat(2) { Box(Modifier.weight(1f).height(56.dp).clip(RoundedCornerShape(4.dp)).background(tile)) }
+ }
}
- }
- repeat(2) {
- Box(Modifier.padding(top = 24.dp, bottom = 12.dp).width(180.dp).height(18.dp).clip(RoundedCornerShape(4.dp)).background(line))
- Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
- repeat(3) { Box(Modifier.size(140.dp).clip(RoundedCornerShape(4.dp)).background(tile)) }
+ repeat(2) {
+ Box(Modifier.padding(top = 24.dp, bottom = 12.dp).width(180.dp).height(18.dp).clip(RoundedCornerShape(4.dp)).background(line))
+ Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
+ repeat(3) { Box(Modifier.size(140.dp).clip(RoundedCornerShape(4.dp)).background(tile)) }
+ }
}
}
+ SkeletonKind.Header -> {
+ Box(Modifier.align(Alignment.CenterHorizontally).padding(top = 24.dp, bottom = 20.dp).size(220.dp).clip(RoundedCornerShape(4.dp)).background(tile))
+ Box(Modifier.width(200.dp).height(22.dp).clip(RoundedCornerShape(4.dp)).background(line))
+ Box(Modifier.padding(top = 10.dp, bottom = 20.dp).width(120.dp).height(14.dp).clip(RoundedCornerShape(4.dp)).background(line))
+ SkeletonRows(tile, line, 6)
+ }
+ SkeletonKind.List -> SkeletonRows(tile, line, 9)
}
- SkeletonKind.Header -> {
- Box(Modifier.align(Alignment.CenterHorizontally).padding(top = 24.dp, bottom = 20.dp).size(220.dp).clip(RoundedCornerShape(4.dp)).background(tile))
- Box(Modifier.width(200.dp).height(22.dp).clip(RoundedCornerShape(4.dp)).background(line))
- Box(Modifier.padding(top = 10.dp, bottom = 20.dp).width(120.dp).height(14.dp).clip(RoundedCornerShape(4.dp)).background(line))
- SkeletonRows(tile, line, 6)
- }
- SkeletonKind.List -> SkeletonRows(tile, line, 9)
}
}
}
+/**
+ * The opacity of a loading placeholder: 0 for its first 200 ms (a quick load shows nothing),
+ * then a short fade in instead of a pop. At once under "Remove animations".
+ */
+@Composable
+private fun placeholderAlpha(): androidx.compose.runtime.State<Float> {
+ var visible by remember { mutableStateOf(false) }
+ LaunchedEffect(Unit) { delay(200); visible = true }
+ val reduce = com.music.spotui.ui.look.rememberReduceMotion()
+ return androidx.compose.animation.core.animateFloatAsState(
+ if (visible) 1f else 0f,
+ if (reduce) androidx.compose.animation.core.snap() else androidx.compose.animation.core.tween(Motion.FADE_MS),
+ label = "placeholder",
+ )
+}
+
enum class SkeletonKind { List, Home, Header }
/**
@@ -111,10 +129,9 @@ enum class SkeletonKind { List, Home, Header }
*/
@Composable
fun SkeletonList(count: Int = 6, round: Boolean = false, modifier: Modifier = Modifier) {
- var visible by remember { mutableStateOf(false) }
- LaunchedEffect(Unit) { delay(200); visible = true }
- Column(modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp)) {
- if (!visible) return@Column
+ val shown = placeholderAlpha()
+ Column(modifier.fillMaxWidth().graphicsLayer { alpha = shown.value }.padding(horizontal = 16.dp, vertical = 8.dp)) {
+ if (shown.value == 0f) return@Column
if (round) repeat(count) {
Row(Modifier.padding(vertical = 8.dp), verticalAlignment = Alignment.CenterVertically) {
Box(Modifier.size(48.dp).clip(androidx.compose.foundation.shape.CircleShape).background(tone(0xFF242424)))
@@ -127,10 +144,9 @@ fun SkeletonList(count: Int = 6, round: Boolean = false, modifier: Modifier = Mo
/** Lyrics loading: lines of grey bars of varied widths, in the lyrics' own colour. */
@Composable
fun SkeletonLyrics(color: Color, modifier: Modifier = Modifier) {
- var visible by remember { mutableStateOf(false) }
- LaunchedEffect(Unit) { delay(200); visible = true }
- Column(modifier.fillMaxWidth().padding(horizontal = 24.dp, vertical = 16.dp)) {
- if (!visible) return@Column
+ val shown = placeholderAlpha()
+ Column(modifier.fillMaxWidth().graphicsLayer { alpha = shown.value }.padding(horizontal = 24.dp, vertical = 16.dp)) {
+ if (shown.value == 0f) return@Column
for (w in floatArrayOf(0.85f, 0.6f, 0.75f, 0.5f, 0.9f, 0.65f, 0.7f, 0.45f)) {
Box(Modifier.padding(vertical = 9.dp).fillMaxWidth(w).height(22.dp).clip(RoundedCornerShape(6.dp)).background(color.copy(alpha = 0.18f)))
}
diff --git a/base/app/src/main/java/com/music/spotui/ui/components/Motion.kt b/base/app/src/main/java/com/music/spotui/ui/components/Motion.kt
index 33f0f7ca..9595e2a7 100644
--- a/base/app/src/main/java/com/music/spotui/ui/components/Motion.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/components/Motion.kt
@@ -86,28 +86,48 @@ fun Modifier.pressScale(source: MutableInteractionSource, pressedScale: Float =
}
/**
- * The play/pause glyph of the official app: the new one springs in from a smaller size
- * while the old one fades out, instead of swapping in a single frame. [playing] picks
- * the pause glyph.
+ * The few durations the Classic look's small transitions share (the same values as the
+ * Immersive look's [com.music.spotui.ui.immersive.motion.ImmersiveMotion], so both feel alike):
+ * a colour or glyph changing state, and content arriving in place of its placeholder.
+ */
+object Motion {
+ const val FADE_MS = 150
+ const val CONTENT_MS = 220
+}
+
+/**
+ * One glyph replacing another (play/pause, a heart filling, a follow check), as in the official
+ * app: the new one springs in from a smaller size while the old one fades out, instead of
+ * swapping in a single frame. Shown at once on first display; a plain swap under "Remove
+ * animations". [target] is what the glyph shows (a Boolean, an icon...).
*/
@Composable
-fun PlayPauseIcon(
- playing: Boolean,
- contentDescription: String?,
- tint: Color,
- modifier: Modifier = Modifier,
-) {
+fun <T> GlyphSwap(target: T, modifier: Modifier = Modifier, content: @Composable (T) -> Unit) {
val reduce = com.music.spotui.ui.look.rememberReduceMotion()
AnimatedContent(
- targetState = playing,
+ targetState = target,
+ modifier = modifier,
transitionSpec = {
if (reduce) EnterTransition.None togetherWith ExitTransition.None
else (scaleIn(spring(dampingRatio = 0.55f, stiffness = Spring.StiffnessMediumLow), initialScale = 0.6f) + fadeIn(tween(120))) togetherWith
(scaleOut(tween(120), targetScale = 0.6f) + fadeOut(tween(90)))
},
contentAlignment = Alignment.Center,
- label = "playPause",
- ) { isPlaying ->
+ label = "glyphSwap",
+ ) { content(it) }
+}
+
+/**
+ * The play/pause glyph of the official app, on [GlyphSwap]. [playing] picks the pause glyph.
+ */
+@Composable
+fun PlayPauseIcon(
+ playing: Boolean,
+ contentDescription: String?,
+ tint: Color,
+ modifier: Modifier = Modifier,
+) {
+ GlyphSwap(playing) { isPlaying ->
Icon(
painter = painterResource(if (isPlaying) R.drawable.ic_playing else R.drawable.play_svgrepo_com),
contentDescription = contentDescription,
@@ -117,6 +137,43 @@ fun PlayPauseIcon(
}
}
+/**
+ * A page that loads: its content fades in over its placeholder ([Loader]) instead of replacing
+ * it in one frame. A page shown from the cache (not loading at first) appears at once, and an
+ * update of a page already shown keeps its composition and its state (same [loading], no fade).
+ * A plain cut under "Remove animations". [content] gets whether it draws the loading state.
+ */
+@Composable
+fun LoadedFade(loading: Boolean, modifier: Modifier = Modifier, content: @Composable (loading: Boolean) -> Unit) {
+ val reduce = com.music.spotui.ui.look.rememberReduceMotion()
+ androidx.compose.animation.Crossfade(
+ targetState = loading,
+ modifier = modifier,
+ animationSpec = if (reduce) androidx.compose.animation.core.snap() else tween(Motion.CONTENT_MS),
+ label = "loadedFade",
+ ) { content(it) }
+}
+
+/**
+ * A row of a lazy list arriving in place of the list's placeholder rows: it fades in once instead
+ * of popping. A list laid out with its rows at once (from the cache) shows them still, and rows
+ * scrolled into view never fade (Compose animates only items new to the list). Nothing moves:
+ * no placement animation. Nothing under "Remove animations". Only for items with stable keys.
+ */
+@Composable
+fun LazyItemScope.arrivingRow(): Modifier =
+ if (com.music.spotui.ui.look.rememberReduceMotion()) Modifier
+ else Modifier.animateItem(fadeInSpec = tween(Motion.CONTENT_MS), placementSpec = null, fadeOutSpec = null)
+
+/**
+ * A placeholder row of a lazy list: it fades out as the real rows ([arrivingRow]) fade in over
+ * it, instead of vanishing in one frame. Nothing under "Remove animations".
+ */
+@Composable
+fun LazyItemScope.leavingPlaceholder(): Modifier =
+ if (com.music.spotui.ui.look.rememberReduceMotion()) Modifier
+ else Modifier.animateItem(fadeInSpec = null, placementSpec = null, fadeOutSpec = tween(Motion.CONTENT_MS))
+
/**
* A row of a lazy list that reorders or loses items: it slides to its new place, on the spring
* of the library's rows. No fades (a row that comes or goes simply is, or is not, there), and
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/components/ImmersiveButtons.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/components/ImmersiveButtons.kt
index 8561c486..0eb72508 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/components/ImmersiveButtons.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/components/ImmersiveButtons.kt
@@ -5,6 +5,9 @@
*/
package com.music.spotui.ui.immersive.components
+import androidx.compose.animation.animateColorAsState
+import androidx.compose.animation.core.snap
+import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@@ -23,6 +26,7 @@ import androidx.compose.material.icons.rounded.Shuffle
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
@@ -34,7 +38,10 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import app.myspoti.engine.R
+import com.music.spotui.ui.components.GlyphSwap
import com.music.spotui.ui.immersive.Immersive
+import com.music.spotui.ui.immersive.motion.ImmersiveMotion
+import com.music.spotui.ui.look.rememberReduceMotion
/** The height of the page action buttons (Play / Shuffle), and what their skeleton reserves. */
val ImmersiveActionButtonHeight = 50.dp
@@ -54,19 +61,23 @@ fun ImmersiveButton(
shape: Shape = Immersive.Button,
enabled: Boolean = true,
) {
- val content = if (filled) Color.White else Immersive.Accent
+ // Lighting up (Shuffle on) fades the fill and the content instead of swapping them in one frame.
+ val reduce = rememberReduceMotion()
+ val content by animateColorAsState(if (filled) Color.White else Immersive.Accent, stateFade(reduce), label = "buttonContent")
+ val fill by animateColorAsState(if (filled) Immersive.Accent else Immersive.Raised, stateFade(reduce), label = "buttonFill")
Row(
modifier = modifier
.immersiveClickable(onClick = onClick, enabled = enabled)
.height(ImmersiveActionButtonHeight)
.clip(shape)
- .background(if (filled) Immersive.Accent else Immersive.Raised)
+ .background(fill)
.padding(horizontal = 20.dp),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
) {
if (icon != null) {
- Icon(icon, contentDescription = null, tint = content, modifier = Modifier.size(22.dp))
+ // Play turning into Pause: the glyphs swap as the player's do.
+ GlyphSwap(icon) { Icon(it, contentDescription = null, tint = content, modifier = Modifier.size(22.dp)) }
Spacer(Modifier.width(8.dp))
}
Text(
@@ -87,6 +98,9 @@ fun ImmersiveCircleButton(
tint: Color = Immersive.Accent,
size: androidx.compose.ui.unit.Dp = 44.dp,
) {
+ // A toggle (save, follow, download) changes glyph and colour in a short spring and fade
+ // instead of in one frame; nothing runs on first display.
+ val shownTint by animateColorAsState(tint, stateFade(rememberReduceMotion()), label = "circleTint")
Box(
modifier = modifier
.immersiveClickable(onClick = onClick)
@@ -95,10 +109,14 @@ fun ImmersiveCircleButton(
.background(Immersive.Raised),
contentAlignment = Alignment.Center,
) {
- Icon(icon, contentDescription = contentDescription, tint = tint, modifier = Modifier.size(22.dp))
+ GlyphSwap(icon) { Icon(it, contentDescription = contentDescription, tint = shownTint, modifier = Modifier.size(22.dp)) }
}
}
+/** A colour changing with a control's state: a short fade, a cut under "reduce motion". */
+private fun stateFade(reduce: Boolean): androidx.compose.animation.core.AnimationSpec<Color> =
+ if (reduce) snap() else tween(ImmersiveMotion.FADE_MS)
+
/**
* The Play / Shuffle pair under an album's or a playlist's header: two equal-width buttons, side
* by side, inset by the page gutter. Hide it until there is something to play.
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/components/ImmersiveSkeletons.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/components/ImmersiveSkeletons.kt
index 4872c437..fc01057a 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/components/ImmersiveSkeletons.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/components/ImmersiveSkeletons.kt
@@ -11,6 +11,7 @@ import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
+import com.music.spotui.ui.components.leavingPlaceholder
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
@@ -201,16 +202,16 @@ fun ImmersiveShelfSkeleton(
}
}
-/** Home while the first page of shelves is still loading. */
+/** Home while the first page of shelves is still loading; it fades out as the shelves fade in. */
fun LazyListScope.immersiveFeedSkeleton(shelves: Int = 3, firstIsHero: Boolean = true) {
if (firstIsHero) {
- item(key = "skeleton:hero") { ImmersiveHeroShelfSkeleton() }
+ item(key = "skeleton:hero") { Box(leavingPlaceholder()) { ImmersiveHeroShelfSkeleton() } }
items(shelves - 1, key = { "skeleton:shelf:$it" }) { index ->
- ImmersiveShelfSkeleton(index = index + 1)
+ Box(leavingPlaceholder()) { ImmersiveShelfSkeleton(index = index + 1) }
}
} else {
items(shelves, key = { "skeleton:shelf:$it" }) { index ->
- ImmersiveShelfSkeleton(index = index)
+ Box(leavingPlaceholder()) { ImmersiveShelfSkeleton(index = index) }
}
}
}
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersiveMiniPlayer.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersiveMiniPlayer.kt
index eeeae84d..21bf24ed 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersiveMiniPlayer.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersiveMiniPlayer.kt
@@ -141,7 +141,9 @@ fun ImmersiveMiniPlayer(modifier: Modifier = Modifier) {
)
}
}
- if (buffering) {
+ // The spinner and the button hand over in a short fade, not in one frame.
+ com.music.spotui.ui.components.LoadedFade(buffering) { loading ->
+ if (loading) {
Box(Modifier.size(GLYPH_SLOT), contentAlignment = Alignment.Center) {
CircularProgressIndicator(color = Immersive.Text, strokeWidth = 2.dp, modifier = Modifier.size(22.dp))
}
@@ -155,14 +157,18 @@ fun ImmersiveMiniPlayer(modifier: Modifier = Modifier) {
},
contentAlignment = Alignment.Center,
) {
- Icon(
- imageVector = if (playing) Icons.Rounded.Pause else Icons.Rounded.PlayArrow,
- contentDescription = stringResource(if (playing) R.string.immersive_player_pause else R.string.immersive_player_play),
- tint = Immersive.Text,
- modifier = Modifier.size(GLYPH_SIZE),
- )
+ // Play and pause swap as in the full player.
+ com.music.spotui.ui.components.GlyphSwap(playing) { on ->
+ Icon(
+ imageVector = if (on) Icons.Rounded.Pause else Icons.Rounded.PlayArrow,
+ contentDescription = stringResource(if (on) R.string.immersive_player_pause else R.string.immersive_player_play),
+ tint = Immersive.Text,
+ modifier = Modifier.size(GLYPH_SIZE),
+ )
+ }
}
}
+ }
Box(
Modifier.size(GLYPH_SLOT).clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) {
Haptics.click()
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersivePodcastPlayer.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersivePodcastPlayer.kt
index 86a9319b..0db2a219 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersivePodcastPlayer.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersivePodcastPlayer.kt
@@ -486,7 +486,8 @@ private fun TransportButton(icon: ImageVector, contentDescription: String, size:
},
contentAlignment = Alignment.Center,
) {
- Icon(icon, contentDescription = contentDescription, tint = Color.White, modifier = Modifier.size(size))
+ // Play and pause swap as in the music player.
+ com.music.spotui.ui.components.GlyphSwap(icon) { Icon(it, contentDescription = contentDescription, tint = Color.White, modifier = Modifier.size(size)) }
}
}
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/player/PlayerControls.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/player/PlayerControls.kt
index 1f4cb397..00a8d341 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/player/PlayerControls.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/player/PlayerControls.kt
@@ -256,7 +256,9 @@ internal fun TransportRow(
heightScale = PLAYER_SKIP_HEIGHT_SCALE,
onClick = onPrevious,
)
- if (isLoading) {
+ // The spinner and the button hand over in a short fade, not in one frame.
+ com.music.spotui.ui.components.LoadedFade(isLoading) { loading ->
+ if (loading) {
// Same footprint as the play/pause target: a smaller box would shunt everything below it.
Box(Modifier.size(playTouch), contentAlignment = Alignment.Center) {
CircularProgressIndicator(color = Color.White, strokeWidth = 3.dp, modifier = Modifier.size(38.dp))
@@ -270,6 +272,7 @@ internal fun TransportRow(
onClick = onPlayPause,
)
}
+ }
TransportGlyph(
icon = Icons.Rounded.SkipNext,
contentDescription = stringResource(R.string.immersive_player_next),
@@ -306,14 +309,17 @@ private fun TransportGlyph(
},
contentAlignment = Alignment.Center,
) {
- Icon(
- imageVector = icon,
- contentDescription = contentDescription,
- tint = Color.White,
- modifier = Modifier
- .size(size)
- .then(if (heightScale != 1f) Modifier.graphicsLayer { scaleY = heightScale } else Modifier),
- )
+ // Play and pause swap as in the Classic player (the skip glyphs never change).
+ com.music.spotui.ui.components.GlyphSwap(icon) { glyph ->
+ Icon(
+ imageVector = glyph,
+ contentDescription = contentDescription,
+ tint = Color.White,
+ modifier = Modifier
+ .size(size)
+ .then(if (heightScale != 1f) Modifier.graphicsLayer { scaleY = heightScale } else Modifier),
+ )
+ }
}
}
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/screens/ImmersiveHomeScreen.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/screens/ImmersiveHomeScreen.kt
index a5273ac6..91597c51 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/screens/ImmersiveHomeScreen.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/screens/ImmersiveHomeScreen.kt
@@ -9,6 +9,7 @@ import com.music.spotui.ui.immersive.shell.immersiveHazeSource
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
+import com.music.spotui.ui.components.arrivingRow
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
@@ -177,14 +178,19 @@ fun ImmersiveHomeScreen(navController: NavController) {
feed != null && feed.sections.isNotEmpty() -> {
shortcuts?.let { tiles ->
item(key = "home:shortcuts") {
- ShortcutGrid(navController, tiles, playingContext)
+ // The feed fades in over its placeholder (see immersiveFeedSkeleton).
+ Box(arrivingRow()) {
+ ShortcutGrid(navController, tiles, playingContext)
+ }
}
}
carousels.forEachIndexed { index, section ->
item(key = "home:section:$index:${section.title}") {
// The lead carousel gets the big cards, unless it is a row of artists.
val hero = index == 0 && section.items.none { it is HomeItem.Artist }
- if (hero) HeroSection(navController, section, playingContext) else ShelfSection(navController, section, playingContext)
+ Box(arrivingRow()) {
+ if (hero) HeroSection(navController, section, playingContext) else ShelfSection(navController, section, playingContext)
+ }
}
}
// Sections from extensions (home.sections), after Spotify's own.
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/ArtistScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/ArtistScreen.kt
index e4dd23db..498981e5 100644
--- a/base/app/src/main/java/com/music/spotui/ui/screens/ArtistScreen.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/screens/ArtistScreen.kt
@@ -106,7 +106,10 @@ fun ArtistScreen(navController: NavController, artistName: String, artistId: Str
.fillMaxSize()
.background(Color(AppBackground.toArgb()))
) {
- when (val state = overview) {
+ // The page fades in over its placeholder instead of replacing it in one frame.
+ com.music.spotui.ui.components.LoadedFade(overview is Response.Loading) { loading ->
+ if (loading) Loader(SkeletonKind.Header)
+ else when (val state = overview) {
is Response.Loading -> Loader(SkeletonKind.Header)
is Response.Error -> androidx.compose.foundation.layout.Column(Modifier.fillMaxSize().statusBarsPadding()) {
androidx.compose.material3.Icon(
@@ -122,6 +125,7 @@ fun ArtistScreen(navController: NavController, artistName: String, artistId: Str
navController, artistViewModel, state.data, artistName,
)
}
+ }
}
}
@@ -366,8 +370,8 @@ private fun ArtistOverviewContent(
,
contentAlignment = Alignment.Center,
) {
- Icon(
- painter = painterResource(id = if (isThisArtist && playingNow) R.drawable.ic_playing else R.drawable.play_svgrepo_com),
+ com.music.spotui.ui.components.PlayPauseIcon(
+ playing = isThisArtist && playingNow,
contentDescription = if (isThisArtist && playingNow) stringResource(R.string.content_description_pause_button) else stringResource(R.string.content_description_play_button),
tint = Color.Black,
modifier = Modifier.size(26.dp),
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/ContextScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/ContextScreen.kt
index d9917d6b..c74eb6e0 100644
--- a/base/app/src/main/java/com/music/spotui/ui/screens/ContextScreen.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/screens/ContextScreen.kt
@@ -564,14 +564,19 @@ fun ContextScreen(navController: NavController, type: String, id: String) {
// During composition, so a cached page is there for the very first frame.
remember(type, id) { vm.load(type, id) }
val resp by vm.page.collectAsState()
- Box(modifier = Modifier.fillMaxSize().background(PageBackground)) {
- when (val r = resp) {
- is Response.Loading -> Loader(SkeletonKind.Header)
- is Response.Error -> com.music.spotui.ui.components.ErrorRetry(
- stringResource(R.string.page_load_failed),
- Modifier.align(Alignment.Center),
- ) { vm.reload() }
- is Response.Success -> ContextContent(navController, vm, r.data)
+ // The page fades in over its placeholder instead of replacing it in one frame.
+ com.music.spotui.ui.components.LoadedFade(resp is Response.Loading, Modifier.fillMaxSize().background(PageBackground)) { loading ->
+ Box(modifier = Modifier.fillMaxSize()) {
+ // The placeholder fading out stays the placeholder, whatever the response is now.
+ if (loading) Loader(SkeletonKind.Header)
+ else when (val r = resp) {
+ is Response.Error -> com.music.spotui.ui.components.ErrorRetry(
+ stringResource(R.string.page_load_failed),
+ Modifier.align(Alignment.Center),
+ ) { vm.reload() }
+ is Response.Success -> ContextContent(navController, vm, r.data)
+ is Response.Loading -> Loader(SkeletonKind.Header)
+ }
}
}
}
@@ -955,16 +960,30 @@ private fun ContextContent(navController: NavController, vm: ContextViewModel, p
}
Spacer(Modifier.weight(1f))
val smart = SmartShuffle.on.value == p.uri
+ // The glyph and its dot light up in a short fade instead of in one frame.
+ val shuffleLit = shuffle || smart
+ val shuffleTint by androidx.compose.animation.animateColorAsState(
+ if (shuffleLit) SpotifyGreen else AppText.copy(alpha = 0.8f),
+ if (com.music.spotui.ui.look.rememberReduceMotion()) androidx.compose.animation.core.snap()
+ else androidx.compose.animation.core.tween(com.music.spotui.ui.components.Motion.FADE_MS),
+ label = "shuffleTint",
+ )
+ val shuffleDot by androidx.compose.animation.core.animateFloatAsState(
+ if (shuffleLit) 1f else 0f,
+ if (com.music.spotui.ui.look.rememberReduceMotion()) androidx.compose.animation.core.snap()
+ else androidx.compose.animation.core.tween(com.music.spotui.ui.components.Motion.FADE_MS),
+ label = "shuffleDot",
+ )
Box {
Icon(
painter = painterResource(id = R.drawable.ic_player_shuffle),
contentDescription = stringResource(if (smart) R.string.smart_shuffle_title else R.string.play_mode_item_shuffle_title),
- tint = if (shuffle || smart) SpotifyGreen else AppText.copy(alpha = 0.8f),
+ tint = shuffleTint,
modifier = Modifier
.size(26.dp)
.drawWithContent {
drawContent()
- if (shuffle || smart) drawCircle(SpotifyGreen, radius = 2.dp.toPx(),
+ if (shuffleDot > 0f) drawCircle(SpotifyGreen.copy(alpha = shuffleDot), radius = 2.dp.toPx(),
center = androidx.compose.ui.geometry.Offset(size.width / 2, size.height + 7.dp.toPx()))
}
.clickable(
@@ -1003,8 +1022,8 @@ private fun ContextContent(navController: NavController, vm: ContextViewModel, p
.clip(CircleShape)
.background(SpotifyGreen),
) {
- Icon(
- painter = painterResource(id = if (isThisContext && playing) R.drawable.ic_playing else R.drawable.play_svgrepo_com),
+ com.music.spotui.ui.components.PlayPauseIcon(
+ playing = isThisContext && playing,
contentDescription = if (isThisContext && playing) stringResource(R.string.content_description_pause_button) else stringResource(R.string.content_description_play_button),
tint = Color.Black,
modifier = Modifier.size(24.dp),
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/DownloadsScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/DownloadsScreen.kt
index 92f97414..2a798497 100644
--- a/base/app/src/main/java/com/music/spotui/ui/screens/DownloadsScreen.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/screens/DownloadsScreen.kt
@@ -162,7 +162,7 @@ fun DownloadsScreen(navController: NavController) {
}
.clip(CircleShape).background(com.music.spotui.ui.theme.AppAccent),
) {
- Icon(painterResource(if (playingHere && SongPlayer.isPlaying()) R.drawable.ic_playing else R.drawable.play_svgrepo_com),
+ com.music.spotui.ui.components.PlayPauseIcon(playingHere && SongPlayer.isPlaying(),
stringResource(R.string.content_description_play_button), tint = Color.Black, modifier = Modifier.size(26.dp))
}
}
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/HomeScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/HomeScreen.kt
index c420db6b..1d9532fe 100644
--- a/base/app/src/main/java/com/music/spotui/ui/screens/HomeScreen.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/screens/HomeScreen.kt
@@ -97,10 +97,12 @@ fun HomeScreen(navController: NavController){
.background(Color(AppBackground.toArgb()))
) {
val feed = (home as? Response.Success)?.data
-
+ val hasFeed = feed != null && feed.sections.isNotEmpty()
+ // The feed fades in over the placeholder instead of replacing it in one frame.
+ com.music.spotui.ui.components.LoadedFade(!hasFeed) { waiting ->
when {
// Preferred: the real personalized Spotify home feed.
- feed != null && feed.sections.isNotEmpty() -> {
+ !waiting && feed != null -> {
HomeFeedContent(navController, feed, homeViewModel.facet.value) { homeViewModel.selectFacet(it) }
}
@@ -110,7 +112,8 @@ fun HomeScreen(navController: NavController){
HomeHeaderRow(navController, homeViewModel.facet.value) { homeViewModel.selectFacet(it) }
Box(modifier = Modifier.weight(1f).fillMaxWidth(), contentAlignment = Alignment.Center) {
when {
- home is Response.Loading -> Loader(SkeletonKind.Home)
+ // Fading out as the feed fades in: still the placeholder.
+ home is Response.Loading || hasFeed -> Loader(SkeletonKind.Home)
else -> androidx.compose.foundation.layout.Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(
text = if (home is Response.Error) stringResource(R.string.home_error) else stringResource(R.string.home_empty),
@@ -125,6 +128,7 @@ fun HomeScreen(navController: NavController){
}
}
}
+ }
}
}
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/LocalFilesScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/LocalFilesScreen.kt
index 3d43bfa9..6a86af9a 100644
--- a/base/app/src/main/java/com/music/spotui/ui/screens/LocalFilesScreen.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/screens/LocalFilesScreen.kt
@@ -149,7 +149,7 @@ fun LocalFilesScreen(navController: NavController) {
}
.clip(CircleShape).background(com.music.spotui.ui.theme.AppAccent),
) {
- Icon(painterResource(if (playingLocal && SongPlayer.isPlaying()) R.drawable.ic_playing else R.drawable.play_svgrepo_com),
+ com.music.spotui.ui.components.PlayPauseIcon(playingLocal && SongPlayer.isPlaying(),
stringResource(R.string.content_description_play_button), tint = Color.Black, modifier = Modifier.size(26.dp))
}
}
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/QueueScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/QueueScreen.kt
index 179ef3f3..85c89900 100644
--- a/base/app/src/main/java/com/music/spotui/ui/screens/QueueScreen.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/screens/QueueScreen.kt
@@ -1,5 +1,6 @@
package com.music.spotui.ui.screens
+import com.music.spotui.ui.components.animatedRow
import com.music.spotui.ui.theme.AppText
import androidx.compose.ui.res.stringResource
@@ -99,35 +100,51 @@ fun QueueScreen(navController: NavController) {
.navigationBarsPadding()
) {
q.current?.let {
- item {
+ item(key = "now") {
QueueHeader(stringResource(R.string.default_notification_channel_name))
QueueRow(song = it, highlight = true, onClick = {})
}
}
+ // Keyed by song and occurrence (as the Immersive queue): a row removed or played lets
+ // the ones under it slide up instead of every row after it being drawn anew.
+ val keys = queueKeys(q.queued + q.nextUp)
if (q.queued.isNotEmpty()) {
- item { QueueHeader(stringResource(R.string.next_in_queue)) }
- itemsIndexed(q.queued, key = { i, it -> "q" + i + it.uid + it.uri }) { _, item ->
- SwipeRemove(item) { QueueRow(song = item.song, highlight = false, onClick = { SongPlayer.skipTo(item) }) }
+ item(key = "heading-queued") { QueueHeader(stringResource(R.string.next_in_queue), animatedRow()) }
+ itemsIndexed(q.queued, key = { i, _ -> keys[i] }) { _, item ->
+ Box(animatedRow()) {
+ SwipeRemove(item) { QueueRow(song = item.song, highlight = false, onClick = { SongPlayer.skipTo(item) }) }
+ }
}
}
if (q.nextUp.isNotEmpty()) {
- item { QueueHeader(stringResource(R.string.next_up)) }
- itemsIndexed(q.nextUp, key = { i, it -> "n" + i + it.uid + it.uri }) { _, item ->
- SwipeRemove(item) { QueueRow(song = item.song, highlight = false, onClick = { SongPlayer.skipTo(item) }) }
+ item(key = "heading-next") { QueueHeader(stringResource(R.string.next_up), animatedRow()) }
+ itemsIndexed(q.nextUp, key = { i, _ -> keys[q.queued.size + i] }) { _, item ->
+ Box(animatedRow()) {
+ SwipeRemove(item) { QueueRow(song = item.song, highlight = false, onClick = { SongPlayer.skipTo(item) }) }
+ }
}
}
}
}
}
+/** One key per row: the song's uri, with its occurrence after the first ("uri~2"), never twice the same. */
+private fun queueKeys(rows: List<SongPlayer.QueueItem>): List<String> {
+ val seen = HashMap<String, Int>()
+ return rows.map { item ->
+ val count = seen.merge(item.uri, 1, Int::plus)!!
+ if (count == 1) item.uri else "${item.uri}~$count"
+ }
+}
+
@Composable
-private fun QueueHeader(text: String) {
+private fun QueueHeader(text: String, modifier: Modifier = Modifier) {
Text(
text,
color = AppText,
fontSize = 16.sp,
fontWeight = FontWeight.Bold,
- modifier = Modifier.padding(16.dp, 18.dp, 16.dp, 6.dp)
+ modifier = modifier.padding(16.dp, 18.dp, 16.dp, 6.dp)
)
}