Skip to content

Native Android client for Spotify, built with Jetpack Compose

Immersive player: shuffle and repeat always in reach (#93), and a landscape layout with every control for songs and podcasts

kota-zo6a8977d570d6
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersivePlayer.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersivePlayer.kt
index 7dec203c..18e26767 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersivePlayer.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersivePlayer.kt
@@ -7,7 +7,8 @@
* of the artwork to a small header (title beside it) when the lyrics or the queue open, the
* title row with its round glyphs, the scrubber, transport, volume and bottom rows, and the
* sheet's drag to close. The full-bleed banner, Canvas clips, track-swipe on the cover, version
- * switching, landscape/tablet layouts, the lyric strip and the dock are left out.
+ * switching, the lyric strip and the dock are left out. The landscape layout (cover beside the
+ * controls) is Myspoti's own.
*/
package com.music.spotui.ui.immersive.player
@@ -32,6 +33,11 @@ import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.RowScope
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.runtime.State
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
@@ -215,10 +221,24 @@ fun ImmersivePlayer(
// Back leaves the panel first; the sheet (outside) closes on the next one.
BackHandler(enabled = panel != Panel.NONE) { panel = Panel.NONE }
- Box(modifier.fillMaxSize().background(Color.Black)) {
+ BoxWithConstraints(modifier.fillMaxSize().background(Color.Black)) {
+ // Wider than tall (a phone on its side, a tablet): the cover beside the controls.
+ val landscape = maxWidth > maxHeight
MeshGradientBackground(palette = palette, trackKey = state.coverUrl)
CompositionLocalProvider(LocalPlayerTint provides tint) {
- Column(Modifier.fillMaxSize().statusBarsPadding().navigationBarsPadding()) {
+ if (landscape) LandscapePlayer(
+ state = state,
+ actions = actions,
+ tint = tint,
+ panel = panel,
+ pauseScale = pauseScale,
+ volume = volume,
+ onToggleLyrics = { panel = if (lyricsOpen) Panel.NONE else Panel.LYRICS },
+ onToggleQueue = { panel = if (queueOpen) Panel.NONE else Panel.QUEUE },
+ onOpenDevices = { showDevices = true },
+ onMore = if (navController != null && state.song != null) ({ showMenu = true }) else null,
+ onSource = { showQuality = true },
+ ) else Column(Modifier.fillMaxSize().statusBarsPadding().navigationBarsPadding()) {
// The handle: always hands its drags to the sheet.
Box(
Modifier.fillMaxWidth().height(DISMISS_STRIP_HEIGHT).dragToClose()
@@ -330,87 +350,11 @@ fun ImmersivePlayer(
.dragToClose(),
verticalAlignment = Alignment.CenterVertically,
) {
- // The header is a fixed HEADER_HEIGHT: with a source line the three lines are
- // set tighter, so none is clipped at the bottom.
- val sourceLabel = com.music.spotui.ui.components.playingSourceLabel()
- val hasSource = sourceLabel.isNotBlank() && !state.adPlaying
- val lineH = if (hasSource) 22.sp else 24.sp
- Column(
- Modifier
- .weight(1f)
- // Scaling the already measured type is a draw-only operation.
- .graphicsLayer {
- val scale = 1f - 0.2f * p()
- scaleX = scale
- scaleY = scale
- transformOrigin = TransformOrigin(0f, 0.5f)
- },
- ) {
- Row(verticalAlignment = Alignment.CenterVertically) {
- Text(
- text = if (state.adPlaying) stringResource(R.string.immersive_player_ad) else state.title,
- style = Immersive.Title.copy(fontSize = 20.sp, lineHeight = lineH),
- maxLines = 1,
- overflow = TextOverflow.Ellipsis,
- modifier = Modifier
- .weight(1f, fill = false)
- .then(if (scrolls) Modifier.basicMarquee(iterations = Int.MAX_VALUE) else Modifier)
- .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) { actions.openAlbum() },
- )
- if (state.explicit && !state.adPlaying) {
- Spacer(Modifier.width(6.dp))
- Box(
- Modifier.size(16.dp).clip(RoundedCornerShape(3.dp)).background(tint.copy(alpha = 0.5f)),
- contentAlignment = Alignment.Center,
- ) {
- Text(
- text = stringResource(R.string.explicit_badge),
- style = Immersive.Caption.copy(fontSize = 10.sp, lineHeight = 10.sp, fontWeight = FontWeight.Bold),
- color = Color.Black,
- )
- }
- }
- }
- if (!state.adPlaying) {
- Text(
- text = state.artist,
- style = Immersive.Title.copy(fontSize = 20.sp, lineHeight = lineH, fontWeight = FontWeight.W500),
- color = tint.copy(alpha = 0.55f),
- maxLines = 1,
- overflow = TextOverflow.Ellipsis,
- modifier = Modifier
- .then(if (scrolls) Modifier.basicMarquee(iterations = Int.MAX_VALUE) else Modifier)
- .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) { actions.openArtist() },
- )
- }
- // What the sound is when Myspoti's own player plays it (an extension's stream, a
- // download); a tap opens what plays and its quality. Same state as the Classic player.
- if (hasSource) Text(
- text = sourceLabel,
- style = Immersive.Caption.copy(lineHeight = 14.sp),
- color = tint.copy(alpha = 0.45f),
- maxLines = 1,
- overflow = TextOverflow.Ellipsis,
- modifier = Modifier
- .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) { showQuality = true },
- )
- }
- Spacer(Modifier.width(10.dp))
- // Beside the credits rather than in the toggle row: liking is about this song.
- CircleGlyph(
- icon = if (state.liked) Icons.Rounded.Star else Icons.Rounded.StarBorder,
- contentDescription = stringResource(if (state.liked) R.string.immersive_player_unlike else R.string.immersive_player_like),
- onClick = actions.toggleLike,
- active = state.liked,
+ PlayerCredits(
+ state = state, actions = actions, tint = tint, scrolls = scrolls, collapse = { p() },
+ onMore = if (navController != null && state.song != null) ({ showMenu = true }) else null,
+ onSource = { showQuality = true },
)
- if (navController != null && state.song != null) {
- Spacer(Modifier.width(8.dp))
- CircleGlyph(
- icon = Icons.Rounded.MoreHoriz,
- contentDescription = stringResource(R.string.immersive_player_more),
- onClick = { showMenu = true },
- )
- }
}
}
@@ -423,38 +367,13 @@ fun ImmersivePlayer(
.padding(horizontal = PLAYER_GUTTER)
.align(Alignment.CenterHorizontally),
) {
- PlayerScrubber(state = state, onSeek = actions.seekTo)
- Spacer(Modifier.height(8.dp))
- TransportRow(
- isPlaying = state.playing,
- isLoading = state.buffering,
- onPrevious = actions.previous,
- onPlayPause = actions.playPause,
- onNext = actions.next,
- )
- Spacer(Modifier.height(12.dp))
- VolumeRow(volume)
- // The volume slider already has room below its drawn track.
- Spacer(Modifier.height(6.dp))
- PlayerActionRow(
- lyricsOpen = lyricsOpen,
- queueOpen = queueOpen,
- shuffleEnabled = state.shuffle || state.smart,
- smartEnabled = state.smart,
- repeatMode = state.repeatMode,
- deviceActive = state.deviceName != null,
+ PlayerControlsBlock(
+ state = state, actions = actions, volume = volume, lyricsOpen = lyricsOpen, queueOpen = queueOpen, showVolume = true,
// Lyrics and the queue are two things to show in one place: opening one closes the other.
onToggleLyrics = { panel = if (lyricsOpen) Panel.NONE else Panel.LYRICS },
onToggleQueue = { panel = if (queueOpen) Panel.NONE else Panel.QUEUE },
- onToggleShuffle = actions.toggleShuffle,
- onCycleRepeat = actions.cycleRepeat,
onOpenDevices = { showDevices = true },
)
- // Buttons from extensions (player.buttons), under the player's own controls.
- val extTrack = remember(state.title, state.artist) { com.music.spotui.extensions.Extensions.currentTrack() }
- com.music.spotui.extensions.MirrorIndicator()
- com.music.spotui.extensions.ExtensionPlayerButtons(extTrack)
- Spacer(Modifier.height(18.dp))
}
}
}
@@ -474,3 +393,242 @@ fun ImmersivePlayer(
)
}
}
+
+/**
+ * The credits row of the player: title (with its explicit badge), artist and the source line,
+ * then the like glyph and, when [onMore] is given, the more glyph. [collapse] is the cover's
+ * travel to the header (0 whole, 1 collapsed); the credits shrink with it.
+ */
+@OptIn(ExperimentalFoundationApi::class)
+@Composable
+private fun RowScope.PlayerCredits(
+ state: ImmersivePlayerState,
+ actions: ImmersivePlayerActions,
+ tint: Color,
+ scrolls: Boolean,
+ collapse: () -> Float,
+ onMore: (() -> Unit)?,
+ onSource: () -> Unit,
+) {
+ // The header is a fixed HEADER_HEIGHT: with a source line the three lines are
+ // set tighter, so none is clipped at the bottom.
+ val sourceLabel = com.music.spotui.ui.components.playingSourceLabel()
+ val hasSource = sourceLabel.isNotBlank() && !state.adPlaying
+ val lineH = if (hasSource) 22.sp else 24.sp
+ Column(
+ Modifier
+ .weight(1f)
+ // Scaling the already measured type is a draw-only operation.
+ .graphicsLayer {
+ val scale = 1f - 0.2f * collapse()
+ scaleX = scale
+ scaleY = scale
+ transformOrigin = TransformOrigin(0f, 0.5f)
+ },
+ ) {
+ Row(verticalAlignment = Alignment.CenterVertically) {
+ Text(
+ text = if (state.adPlaying) stringResource(R.string.immersive_player_ad) else state.title,
+ style = Immersive.Title.copy(fontSize = 20.sp, lineHeight = lineH),
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier
+ .weight(1f, fill = false)
+ .then(if (scrolls) Modifier.basicMarquee(iterations = Int.MAX_VALUE) else Modifier)
+ .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) { actions.openAlbum() },
+ )
+ if (state.explicit && !state.adPlaying) {
+ Spacer(Modifier.width(6.dp))
+ Box(
+ Modifier.size(16.dp).clip(RoundedCornerShape(3.dp)).background(tint.copy(alpha = 0.5f)),
+ contentAlignment = Alignment.Center,
+ ) {
+ Text(
+ text = stringResource(R.string.explicit_badge),
+ style = Immersive.Caption.copy(fontSize = 10.sp, lineHeight = 10.sp, fontWeight = FontWeight.Bold),
+ color = Color.Black,
+ )
+ }
+ }
+ }
+ if (!state.adPlaying) {
+ Text(
+ text = state.artist,
+ style = Immersive.Title.copy(fontSize = 20.sp, lineHeight = lineH, fontWeight = FontWeight.W500),
+ color = tint.copy(alpha = 0.55f),
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier
+ .then(if (scrolls) Modifier.basicMarquee(iterations = Int.MAX_VALUE) else Modifier)
+ .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) { actions.openArtist() },
+ )
+ }
+ // What the sound is when Myspoti's own player plays it (an extension's stream, a
+ // download); a tap opens what plays and its quality. Same state as the Classic player.
+ if (hasSource) Text(
+ text = sourceLabel,
+ style = Immersive.Caption.copy(lineHeight = 14.sp),
+ color = tint.copy(alpha = 0.45f),
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier
+ .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null, onClick = onSource),
+ )
+ }
+ Spacer(Modifier.width(10.dp))
+ // Beside the credits rather than in the toggle row: liking is about this song.
+ CircleGlyph(
+ icon = if (state.liked) Icons.Rounded.Star else Icons.Rounded.StarBorder,
+ contentDescription = stringResource(if (state.liked) R.string.immersive_player_unlike else R.string.immersive_player_like),
+ onClick = actions.toggleLike,
+ active = state.liked,
+ )
+ if (onMore != null) {
+ Spacer(Modifier.width(8.dp))
+ CircleGlyph(
+ icon = Icons.Rounded.MoreHoriz,
+ contentDescription = stringResource(R.string.immersive_player_more),
+ onClick = onMore,
+ )
+ }
+}
+
+/** Scrubber, transport, volume, the bottom row and the extensions' buttons: the controls under the cover. */
+@Composable
+private fun PlayerControlsBlock(
+ state: ImmersivePlayerState,
+ actions: ImmersivePlayerActions,
+ volume: PlayerVolume,
+ lyricsOpen: Boolean,
+ queueOpen: Boolean,
+ showVolume: Boolean,
+ onToggleLyrics: () -> Unit,
+ onToggleQueue: () -> Unit,
+ onOpenDevices: () -> Unit,
+) {
+ PlayerScrubber(state = state, onSeek = actions.seekTo)
+ Spacer(Modifier.height(8.dp))
+ TransportRow(
+ isPlaying = state.playing,
+ isLoading = state.buffering,
+ onPrevious = actions.previous,
+ onPlayPause = actions.playPause,
+ onNext = actions.next,
+ )
+ Spacer(Modifier.height(if (showVolume) 12.dp else 4.dp))
+ if (showVolume) {
+ VolumeRow(volume)
+ // The volume slider already has room below its drawn track.
+ Spacer(Modifier.height(6.dp))
+ }
+ PlayerActionRow(
+ lyricsOpen = lyricsOpen,
+ queueOpen = queueOpen,
+ shuffleEnabled = state.shuffle || state.smart,
+ smartEnabled = state.smart,
+ repeatMode = state.repeatMode,
+ deviceActive = state.deviceName != null,
+ onToggleLyrics = onToggleLyrics,
+ onToggleQueue = onToggleQueue,
+ onToggleShuffle = actions.toggleShuffle,
+ onCycleRepeat = actions.cycleRepeat,
+ onOpenDevices = onOpenDevices,
+ )
+ // Buttons from extensions (player.buttons), under the player's own controls.
+ val extTrack = remember(state.title, state.artist) { com.music.spotui.extensions.Extensions.currentTrack() }
+ com.music.spotui.extensions.MirrorIndicator()
+ com.music.spotui.extensions.ExtensionPlayerButtons(extTrack)
+ Spacer(Modifier.height(18.dp))
+}
+
+/**
+ * The landscape layout: the cover on the left (the lyrics or the queue take its place when they
+ * are up), on the right the credits, the scrubber, every transport control and the bottom row.
+ * The right side scrolls if a small window cannot hold it, so no control is out of reach.
+ */
+@OptIn(ExperimentalGlideComposeApi::class)
+@Composable
+private fun LandscapePlayer(
+ state: ImmersivePlayerState,
+ actions: ImmersivePlayerActions,
+ tint: Color,
+ panel: Int,
+ pauseScale: State<Float>,
+ volume: PlayerVolume,
+ onToggleLyrics: () -> Unit,
+ onToggleQueue: () -> Unit,
+ onOpenDevices: () -> Unit,
+ onMore: (() -> Unit)?,
+ onSource: () -> Unit,
+) {
+ Column(Modifier.fillMaxSize().statusBarsPadding().navigationBarsPadding()) {
+ // The handle: always hands its drags to the sheet.
+ Box(
+ Modifier.fillMaxWidth().height(DISMISS_STRIP_HEIGHT).dragToClose()
+ .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) { actions.close() },
+ contentAlignment = Alignment.Center,
+ ) {
+ Box(Modifier.width(36.dp).height(5.dp).clip(CircleShape).background(tint.copy(alpha = 0.35f)))
+ }
+ Row(
+ Modifier.weight(1f).fillMaxWidth().padding(start = PLAYER_GUTTER, end = PLAYER_GUTTER, bottom = 8.dp),
+ horizontalArrangement = Arrangement.spacedBy(PLAYER_GUTTER),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ BoxWithConstraints(Modifier.weight(1f).fillMaxHeight(), contentAlignment = Alignment.Center) {
+ val side = minOf(maxWidth, maxHeight)
+ Crossfade(targetState = panel, animationSpec = tween(250), modifier = Modifier.fillMaxSize(), label = "playerLandscapePanel") { shown ->
+ when (shown) {
+ Panel.LYRICS -> ImmersiveLyricsPanel(Modifier.fillMaxSize(), PaddingValues(vertical = 4.dp))
+ Panel.QUEUE -> ImmersiveQueuePanel(Modifier.fillMaxSize(), PaddingValues(vertical = 4.dp))
+ else -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
+ Box(
+ Modifier
+ .size(side)
+ .graphicsLayer {
+ // The pause step back, as in the portrait layout.
+ scaleX = pauseScale.value
+ scaleY = pauseScale.value
+ shadowElevation = 10.dp.toPx()
+ shape = ArtCorner
+ clip = true
+ }
+ .background(Color.Black.copy(alpha = 0.18f))
+ .dragToClose(),
+ ) {
+ GlideImage(
+ model = state.coverUrl.takeIf { it.isNotBlank() },
+ contentDescription = null,
+ contentScale = ContentScale.Crop,
+ transition = CrossFade,
+ loading = placeholder(R.drawable.placeholder),
+ failure = placeholder(R.drawable.placeholder),
+ modifier = Modifier.fillMaxSize(),
+ requestBuilderTransform = { it.override(COVER_DECODE_PX) },
+ )
+ }
+ }
+ }
+ }
+ }
+ BoxWithConstraints(Modifier.weight(1f).fillMaxHeight(), contentAlignment = Alignment.Center) {
+ // The volume bar is the first thing to go when the window is low: the hardware keys do it too.
+ val showVolume = maxHeight >= LANDSCAPE_VOLUME_MIN_HEIGHT
+ Column(Modifier.widthIn(max = PLAYER_MAX_WIDTH).verticalScroll(rememberScrollState())) {
+ Row(Modifier.fillMaxWidth().height(HEADER_HEIGHT), verticalAlignment = Alignment.CenterVertically) {
+ PlayerCredits(state, actions, tint, scrolls = true, collapse = { 0f }, onMore = onMore, onSource = onSource)
+ }
+ Spacer(Modifier.height(8.dp))
+ PlayerControlsBlock(
+ state = state, actions = actions, volume = volume,
+ lyricsOpen = panel == Panel.LYRICS, queueOpen = panel == Panel.QUEUE, showVolume = showVolume,
+ onToggleLyrics = onToggleLyrics, onToggleQueue = onToggleQueue, onOpenDevices = onOpenDevices,
+ )
+ }
+ }
+ }
+ }
+}
+
+/** The right-hand column needs about this much height to show the volume bar as well. */
+private val LANDSCAPE_VOLUME_MIN_HEIGHT = 400.dp
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 fecfe085..08fb609d 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
@@ -12,6 +12,11 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.RowScope
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.ui.unit.Dp
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
@@ -145,10 +150,174 @@ fun ImmersivePodcastPlayer(navController: NavController) {
if (showId.isNotBlank()) navController.navigate(showRoute(showId, showName))
}
- Box(Modifier.fillMaxSize().background(Color.Black)) {
+ val coverArt: @Composable (Dp) -> Unit = { size ->
+ Box(
+ Modifier
+ .size(size)
+ .graphicsLayer {
+ // The pause step back, as on the music player.
+ val scale = if (reduce) 1f else pauseScale.value
+ scaleX = scale
+ scaleY = scale
+ shadowElevation = 10.dp.toPx()
+ shape = ArtCorner
+ clip = true
+ }
+ .background(Color.Black.copy(alpha = 0.18f))
+ .dragToClose(),
+ ) {
+ GlideImage(
+ model = state.coverUrl.takeIf { it.isNotBlank() },
+ contentDescription = null,
+ contentScale = ContentScale.Crop,
+ transition = CrossFade,
+ loading = placeholder(R.drawable.placeholder),
+ failure = placeholder(R.drawable.placeholder),
+ modifier = Modifier.fillMaxSize(),
+ requestBuilderTransform = { it.override(COVER_DECODE_PX) },
+ )
+ }
+ }
+ // The episode and its show, the star of the saved episodes and the episode's menu.
+ val credits: @Composable RowScope.() -> Unit = {
+ val sourceLabel = playingSourceLabel()
+ Column(Modifier.weight(1f)) {
+ Text(
+ text = title,
+ style = Immersive.Title.copy(fontSize = 20.sp, lineHeight = if (sourceLabel.isNotBlank()) 22.sp else 24.sp),
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier
+ .then(if (reduce) Modifier else Modifier.basicMarquee(iterations = Int.MAX_VALUE))
+ .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) {
+ navController.navigate(episodeRoute(episodeId, title))
+ },
+ )
+ Text(
+ text = showName,
+ style = Immersive.Title.copy(
+ fontSize = 20.sp,
+ lineHeight = if (sourceLabel.isNotBlank()) 22.sp else 24.sp,
+ fontWeight = FontWeight.W500,
+ ),
+ color = tint.copy(alpha = 0.55f),
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier
+ .then(if (reduce) Modifier else Modifier.basicMarquee(iterations = Int.MAX_VALUE))
+ .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) { openShow() },
+ )
+ // What the sound is when Myspoti's own player plays it; a tap opens its quality.
+ if (sourceLabel.isNotBlank()) Text(
+ text = sourceLabel,
+ style = Immersive.Caption.copy(lineHeight = 14.sp),
+ color = tint.copy(alpha = 0.45f),
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier.clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) { showQuality = true },
+ )
+ }
+ Spacer(Modifier.width(10.dp))
+ CircleGlyph(
+ icon = if (saved) Icons.Rounded.Star else Icons.Rounded.StarBorder,
+ contentDescription = stringResource(if (saved) R.string.immersive_player_unlike else R.string.immersive_player_like),
+ onClick = { SongPlayer.setSaved(uri, !saved) },
+ active = saved,
+ )
+ Spacer(Modifier.width(8.dp))
+ CircleGlyph(
+ icon = Icons.Rounded.MoreHoriz,
+ contentDescription = stringResource(R.string.episode_options),
+ onClick = { showMenu = true },
+ )
+ }
+ // Scrubber, podcast transport and the row of speed, sleep timer, devices and queue.
+ val controls: @Composable () -> Unit = {
+ PlayerScrubber(state = state, onSeek = actions.seekTo)
+ Spacer(Modifier.height(8.dp))
+ PodcastTransportRow(
+ isPlaying = state.playing,
+ isLoading = state.buffering,
+ onBack = { SongPlayer.skipBy(-SKIP_MS) },
+ onPlayPause = actions.playPause,
+ onForward = { SongPlayer.skipBy(SKIP_MS) },
+ )
+ Spacer(Modifier.height(12.dp))
+ Row(
+ modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp),
+ horizontalArrangement = Arrangement.SpaceBetween,
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ SpeedChip(label = stringResource(R.string.player_speed_chip, speedLabel(SongPlayer.speed.value)), onClick = { showSpeed = true })
+ BottomGlyph(
+ icon = Icons.Rounded.Timer,
+ contentDescription = stringResource(R.string.player_sleep_timer),
+ onClick = { showSleep = true },
+ highlighted = SongPlayer.sleepEndsAt.value != null,
+ )
+ BottomGlyph(
+ icon = Icons.Rounded.Devices,
+ contentDescription = stringResource(R.string.immersive_player_devices),
+ onClick = { showDevices = true },
+ highlighted = state.deviceName != null,
+ )
+ BottomGlyph(
+ icon = Icons.AutoMirrored.Rounded.QueueMusic,
+ contentDescription = stringResource(R.string.immersive_player_queue),
+ onClick = { showQueue = true },
+ )
+ }
+ Spacer(Modifier.height(18.dp))
+ }
+
+ BoxWithConstraints(Modifier.fillMaxSize().background(Color.Black)) {
+ // Wider than tall (a phone on its side, a tablet): the cover beside the controls.
+ val landscape = maxWidth > maxHeight
MeshGradientBackground(palette = palette, trackKey = state.coverUrl)
CompositionLocalProvider(LocalPlayerTint provides tint) {
- Column(Modifier.fillMaxSize().statusBarsPadding().navigationBarsPadding()) {
+ if (landscape) Column(Modifier.fillMaxSize().statusBarsPadding().navigationBarsPadding()) {
+ // The handle: always hands its drags to the sheet.
+ Box(
+ Modifier.fillMaxWidth().height(DISMISS_STRIP_HEIGHT).dragToClose()
+ .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) { actions.close() },
+ contentAlignment = Alignment.Center,
+ ) {
+ Box(Modifier.width(36.dp).height(5.dp).clip(CircleShape).background(tint.copy(alpha = 0.35f)))
+ }
+ Row(
+ Modifier.weight(1f).fillMaxWidth().padding(start = PLAYER_GUTTER, end = PLAYER_GUTTER, bottom = 8.dp),
+ horizontalArrangement = Arrangement.spacedBy(PLAYER_GUTTER),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ BoxWithConstraints(Modifier.weight(1f).fillMaxHeight(), contentAlignment = Alignment.Center) {
+ coverArt(minOf(maxWidth, maxHeight))
+ }
+ // Scrolls if a small window cannot hold the right-hand side: no control is out of reach.
+ Box(Modifier.weight(1f).fillMaxHeight(), contentAlignment = Alignment.Center) {
+ Column(Modifier.widthIn(max = PLAYER_MAX_WIDTH).verticalScroll(rememberScrollState())) {
+ // Where the episode plays from: a tap opens the show.
+ Column(
+ horizontalAlignment = Alignment.CenterHorizontally,
+ modifier = Modifier
+ .fillMaxWidth()
+ .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) { openShow() },
+ ) {
+ Text(stringResource(R.string.podcast_playing_from), style = Immersive.Caption, color = tint.copy(alpha = 0.55f), maxLines = 1, overflow = TextOverflow.Ellipsis)
+ Text(
+ showName,
+ style = Immersive.BodyStrong.copy(fontSize = 14.sp, lineHeight = 18.sp),
+ textAlign = TextAlign.Center,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ )
+ }
+ Row(Modifier.fillMaxWidth().height(TITLE_HEIGHT), verticalAlignment = Alignment.CenterVertically) { credits() }
+ Spacer(Modifier.height(8.dp))
+ controls()
+ }
+ }
+ }
+ } else Column(Modifier.fillMaxSize().statusBarsPadding().navigationBarsPadding()) {
// The handle: always hands its drags to the sheet.
Box(
Modifier.fillMaxWidth().height(DISMISS_STRIP_HEIGHT).dragToClose()
@@ -190,88 +359,14 @@ fun ImmersivePodcastPlayer(navController: NavController) {
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
- Box(
- Modifier
- .size(art)
- .graphicsLayer {
- // The pause step back, as on the music player.
- val scale = if (reduce) 1f else pauseScale.value
- scaleX = scale
- scaleY = scale
- shadowElevation = 10.dp.toPx()
- shape = ArtCorner
- clip = true
- }
- .background(Color.Black.copy(alpha = 0.18f))
- .dragToClose(),
- ) {
- GlideImage(
- model = state.coverUrl.takeIf { it.isNotBlank() },
- contentDescription = null,
- contentScale = ContentScale.Crop,
- transition = CrossFade,
- loading = placeholder(R.drawable.placeholder),
- failure = placeholder(R.drawable.placeholder),
- modifier = Modifier.fillMaxSize(),
- requestBuilderTransform = { it.override(COVER_DECODE_PX) },
- )
- }
+ coverArt(art)
Spacer(Modifier.height(ART_TITLE_GAP))
// The episode and its show, the star of the saved episodes and the episode's menu.
Row(
modifier = Modifier.width(contentWidth).height(TITLE_HEIGHT).dragToClose(),
verticalAlignment = Alignment.CenterVertically,
) {
- val sourceLabel = playingSourceLabel()
- Column(Modifier.weight(1f)) {
- Text(
- text = title,
- style = Immersive.Title.copy(fontSize = 20.sp, lineHeight = if (sourceLabel.isNotBlank()) 22.sp else 24.sp),
- maxLines = 1,
- overflow = TextOverflow.Ellipsis,
- modifier = Modifier
- .then(if (reduce) Modifier else Modifier.basicMarquee(iterations = Int.MAX_VALUE))
- .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) {
- navController.navigate(episodeRoute(episodeId, title))
- },
- )
- Text(
- text = showName,
- style = Immersive.Title.copy(
- fontSize = 20.sp,
- lineHeight = if (sourceLabel.isNotBlank()) 22.sp else 24.sp,
- fontWeight = FontWeight.W500,
- ),
- color = tint.copy(alpha = 0.55f),
- maxLines = 1,
- overflow = TextOverflow.Ellipsis,
- modifier = Modifier
- .then(if (reduce) Modifier else Modifier.basicMarquee(iterations = Int.MAX_VALUE))
- .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) { openShow() },
- )
- // What the sound is when Myspoti's own player plays it; a tap opens its quality.
- if (sourceLabel.isNotBlank()) Text(
- text = sourceLabel,
- style = Immersive.Caption.copy(lineHeight = 14.sp),
- color = tint.copy(alpha = 0.45f),
- maxLines = 1,
- overflow = TextOverflow.Ellipsis,
- modifier = Modifier.clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) { showQuality = true },
- )
- }
- Spacer(Modifier.width(10.dp))
- CircleGlyph(
- icon = if (saved) Icons.Rounded.Star else Icons.Rounded.StarBorder,
- contentDescription = stringResource(if (saved) R.string.immersive_player_unlike else R.string.immersive_player_like),
- onClick = { SongPlayer.setSaved(uri, !saved) },
- active = saved,
- )
- Spacer(Modifier.width(8.dp))
- CircleGlyph(
- icon = Icons.Rounded.MoreHoriz,
- contentDescription = stringResource(R.string.episode_options),
- onClick = { showMenu = true },
- )
+ credits()
}
}
}
@@ -284,41 +379,7 @@ fun ImmersivePodcastPlayer(navController: NavController) {
.padding(horizontal = PLAYER_GUTTER)
.align(Alignment.CenterHorizontally),
) {
- PlayerScrubber(state = state, onSeek = actions.seekTo)
- Spacer(Modifier.height(8.dp))
- PodcastTransportRow(
- isPlaying = state.playing,
- isLoading = state.buffering,
- onBack = { SongPlayer.skipBy(-SKIP_MS) },
- onPlayPause = actions.playPause,
- onForward = { SongPlayer.skipBy(SKIP_MS) },
- )
- Spacer(Modifier.height(12.dp))
- Row(
- modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp),
- horizontalArrangement = Arrangement.SpaceBetween,
- verticalAlignment = Alignment.CenterVertically,
- ) {
- SpeedChip(label = stringResource(R.string.player_speed_chip, speedLabel(SongPlayer.speed.value)), onClick = { showSpeed = true })
- BottomGlyph(
- icon = Icons.Rounded.Timer,
- contentDescription = stringResource(R.string.player_sleep_timer),
- onClick = { showSleep = true },
- highlighted = SongPlayer.sleepEndsAt.value != null,
- )
- BottomGlyph(
- icon = Icons.Rounded.Devices,
- contentDescription = stringResource(R.string.immersive_player_devices),
- onClick = { showDevices = true },
- highlighted = state.deviceName != null,
- )
- BottomGlyph(
- icon = Icons.AutoMirrored.Rounded.QueueMusic,
- contentDescription = stringResource(R.string.immersive_player_queue),
- onClick = { showQueue = true },
- )
- }
- Spacer(Modifier.height(18.dp))
+ controls()
}
}
}
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 ad8c3ecf..e9391a20 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
@@ -12,10 +12,8 @@
*/
package com.music.spotui.ui.immersive.player
-import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.Crossfade
-import androidx.compose.animation.SizeTransform
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.Spring
@@ -24,7 +22,6 @@ import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
-import androidx.compose.animation.togetherWith
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
@@ -348,7 +345,8 @@ internal fun VolumeRow(volume: PlayerVolume) {
}
private val BOTTOM_ACTION_SIZE = 44.dp
-private val PILL_SEGMENT_WIDTH = 64.dp
+// Three segments (shuffle, repeat, devices) have to fit between the glyphs on a 320dp screen.
+private val PILL_SEGMENT_WIDTH = 56.dp
private val PILL_ICON_SIZE = 24.dp
/** How long the capsule takes to cross from the middle of the row to the lyrics glyph's place as the queue opens, and back. */
@@ -457,10 +455,9 @@ private fun BottomGlyph(
/**
* Lyrics, the capsule, and the queue: the row the player ends on.
*
- * The capsule swaps: the devices button normally, shuffle and repeat while the queue is up,
- * since that is when they are what you are about to reach for. With the queue up the lyrics
- * glyph steps aside and the capsule slides over into its place, leaving the queue glyph, lit,
- * as the way back.
+ * The capsule always holds shuffle, repeat and devices, so the playback modes are in reach
+ * whatever is up. With the queue up the lyrics glyph steps aside and the capsule slides over
+ * into its place, leaving the queue glyph, lit, as the way back.
*/
@Composable
internal fun PlayerActionRow(
@@ -477,9 +474,7 @@ internal fun PlayerActionRow(
onOpenDevices: () -> Unit,
) {
BoxWithConstraints(Modifier.fillMaxWidth()) {
- // Sized for the wider of the two capsules in both states, so the lyrics and queue glyphs
- // do not slide as they swap.
- val widestRow = BOTTOM_ACTION_SIZE * 2 + pillWidth(2)
+ val widestRow = BOTTOM_ACTION_SIZE * 2 + pillWidth(3)
val edgeInset = ((maxWidth - widestRow) / 4).coerceAtLeast(0.dp)
// 0 with the capsule centred between lyrics and queue, 1 with it moved over to where the
// lyrics glyph sits. Read only while placing, so the slide relays out the row and recomposes nothing.
@@ -492,7 +487,7 @@ internal fun PlayerActionRow(
modifier = Modifier.fillMaxWidth().padding(horizontal = edgeInset),
contentAlignment = Alignment.CenterStart,
) {
- // Gone while the queue is up: the playback modes take its place.
+ // Gone while the queue is up: the capsule slides over into its place.
AnimatedVisibility(
visible = !queueOpen,
enter = fadeIn(tween(180, delayMillis = 120)),
@@ -508,60 +503,48 @@ internal fun PlayerActionRow(
highlighted = lyricsOpen,
)
}
- AnimatedContent(
- // Laid out across the whole row and placed by hand: centred at 0, flush with the
- // lyrics glyph's left edge at 1.
- modifier = Modifier.layout { measurable, constraints ->
+ // Laid out across the whole row and placed by hand: centred at 0, flush with the
+ // lyrics glyph's left edge at 1.
+ Box(
+ Modifier.layout { measurable, constraints ->
val placeable = measurable.measure(constraints.copy(minWidth = 0))
layout(constraints.maxWidth, placeable.height) {
val centred = (constraints.maxWidth - placeable.width) / 2f
placeable.place((centred * (1f - toStart.value)).roundToInt(), 0)
}
},
- targetState = queueOpen,
- transitionSpec = {
- (fadeIn(tween(180, delayMillis = 140)) togetherWith fadeOut(tween(140)))
- // Unclipped: the capsule's rounded ends are what the eye follows through the width change.
- .using(SizeTransform(clip = false) { _, _ -> tween(220) })
- },
- label = "playerBottomPill",
- ) { showQueueModes ->
- if (showQueueModes) {
- Pill {
- PillSegment(
- icon = if (smartEnabled) Icons.Rounded.AutoAwesome else Icons.Rounded.Shuffle,
- contentDescription = stringResource(
- when {
- smartEnabled -> R.string.smart_shuffle_title
- shuffleEnabled -> R.string.immersive_player_shuffle_on
- else -> R.string.immersive_player_shuffle_off
- },
- ),
- onClick = onToggleShuffle,
- highlighted = shuffleEnabled,
- )
- PillDivider()
- PillSegment(
- icon = if (repeatMode == ImmersiveRepeat.ONE) Icons.Rounded.RepeatOne else Icons.Rounded.Repeat,
- contentDescription = when (repeatMode) {
- ImmersiveRepeat.ONE -> stringResource(R.string.immersive_player_repeat_one)
- ImmersiveRepeat.ALL -> stringResource(R.string.immersive_player_repeat_all)
- else -> stringResource(R.string.immersive_player_repeat_off)
+ ) {
+ Pill {
+ PillSegment(
+ icon = if (smartEnabled) Icons.Rounded.AutoAwesome else Icons.Rounded.Shuffle,
+ contentDescription = stringResource(
+ when {
+ smartEnabled -> R.string.smart_shuffle_title
+ shuffleEnabled -> R.string.immersive_player_shuffle_on
+ else -> R.string.immersive_player_shuffle_off
},
- onClick = onCycleRepeat,
- highlighted = repeatMode != ImmersiveRepeat.OFF,
- )
- }
- } else {
- Pill {
- PillSegment(
- icon = Icons.Rounded.Devices,
- contentDescription = stringResource(R.string.immersive_player_devices),
- onClick = onOpenDevices,
- highlighted = deviceActive,
- width = pillWidth(2),
- )
- }
+ ),
+ onClick = onToggleShuffle,
+ highlighted = shuffleEnabled,
+ )
+ PillDivider()
+ PillSegment(
+ icon = if (repeatMode == ImmersiveRepeat.ONE) Icons.Rounded.RepeatOne else Icons.Rounded.Repeat,
+ contentDescription = when (repeatMode) {
+ ImmersiveRepeat.ONE -> stringResource(R.string.immersive_player_repeat_one)
+ ImmersiveRepeat.ALL -> stringResource(R.string.immersive_player_repeat_all)
+ else -> stringResource(R.string.immersive_player_repeat_off)
+ },
+ onClick = onCycleRepeat,
+ highlighted = repeatMode != ImmersiveRepeat.OFF,
+ )
+ PillDivider()
+ PillSegment(
+ icon = Icons.Rounded.Devices,
+ contentDescription = stringResource(R.string.immersive_player_devices),
+ onClick = onOpenDevices,
+ highlighted = deviceActive,
+ )
}
}
Box(Modifier.align(Alignment.CenterEnd)) {