refactor(android): one transport button pair, and Previous/Next grey out at the ends of the queue (DRY A2)
The mini player and Now Playing each drew their own play/pause button with its UPnP loading spinner, and their own Previous/Next. They share TransportControls.kt now (PlayPauseButton, SkipButton). PlayerUiState gains hasPrevious/hasNext from Media3's hasPrevious/NextMediaItem, and both screens disable the skip buttons when there is nowhere to go, as the web does. The cover's shared-element hero modifier, also written twice, is one nowPlayingCoverHero(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -663,6 +663,8 @@ class PlayerController @Inject constructor(
|
|||||||
},
|
},
|
||||||
isUpnpLoading = isUpnpLoading,
|
isUpnpLoading = isUpnpLoading,
|
||||||
listenSeq = listenSeq,
|
listenSeq = listenSeq,
|
||||||
|
hasPrevious = player.hasPreviousMediaItem(),
|
||||||
|
hasNext = player.hasNextMediaItem(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -35,4 +35,11 @@ data class PlayerUiState(
|
|||||||
* on repeat-one, or the same song twice in a row, is a play per listen.
|
* on repeat-one, or the same song twice in a row, is a play per listen.
|
||||||
*/
|
*/
|
||||||
val listenSeq: Long = 0,
|
val listenSeq: Long = 0,
|
||||||
|
/**
|
||||||
|
* Whether Previous and Next lead anywhere, as Media3 reckons it from the
|
||||||
|
* queue, shuffle and repeat. At the ends of a queue with repeat off or
|
||||||
|
* repeat one they don't, and the buttons grey out rather than do nothing.
|
||||||
|
*/
|
||||||
|
val hasPrevious: Boolean = false,
|
||||||
|
val hasNext: Boolean = false,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.fabledsword.minstrel.player.ui
|
package com.fabledsword.minstrel.player.ui
|
||||||
|
|
||||||
import androidx.compose.animation.Crossfade
|
import androidx.compose.animation.Crossfade
|
||||||
import androidx.compose.animation.ExperimentalSharedTransitionApi
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.gestures.Orientation
|
import androidx.compose.foundation.gestures.Orientation
|
||||||
@@ -17,9 +16,7 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.foundation.layout.fillMaxHeight
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
@@ -36,14 +33,9 @@ import androidx.hilt.navigation.compose.hiltViewModel
|
|||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.composables.icons.lucide.Lucide
|
import com.composables.icons.lucide.Lucide
|
||||||
import com.composables.icons.lucide.Music
|
import com.composables.icons.lucide.Music
|
||||||
import com.composables.icons.lucide.Pause
|
|
||||||
import com.composables.icons.lucide.Play
|
|
||||||
import com.composables.icons.lucide.SkipBack
|
import com.composables.icons.lucide.SkipBack
|
||||||
import com.composables.icons.lucide.SkipForward
|
import com.composables.icons.lucide.SkipForward
|
||||||
import com.fabledsword.minstrel.models.TrackRef
|
import com.fabledsword.minstrel.models.TrackRef
|
||||||
import com.fabledsword.minstrel.nav.HERO_KEY_NOW_PLAYING_COVER
|
|
||||||
import com.fabledsword.minstrel.nav.LocalAnimatedContentScope
|
|
||||||
import com.fabledsword.minstrel.nav.LocalSharedTransitionScope
|
|
||||||
import com.fabledsword.minstrel.shared.widgets.LikeButton
|
import com.fabledsword.minstrel.shared.widgets.LikeButton
|
||||||
import com.fabledsword.minstrel.shared.widgets.ServerImage
|
import com.fabledsword.minstrel.shared.widgets.ServerImage
|
||||||
import com.fabledsword.minstrel.shared.widgets.trackactions.TrackActionsViewModel
|
import com.fabledsword.minstrel.shared.widgets.trackactions.TrackActionsViewModel
|
||||||
@@ -59,25 +51,10 @@ private const val SCRUBBER_ROW_HEIGHT_DP = 4
|
|||||||
// same across screens.
|
// same across screens.
|
||||||
private const val SWIPE_UP_VELOCITY_DP = 200
|
private const val SWIPE_UP_VELOCITY_DP = 200
|
||||||
|
|
||||||
@OptIn(ExperimentalSharedTransitionApi::class)
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun MiniCover(coverUrl: String, contentDescription: String) {
|
private fun MiniCover(coverUrl: String, contentDescription: String) {
|
||||||
val sharedScope = LocalSharedTransitionScope.current
|
|
||||||
val animatedScope = LocalAnimatedContentScope.current
|
|
||||||
val heroModifier = if (sharedScope != null && animatedScope != null) {
|
|
||||||
with(sharedScope) {
|
|
||||||
Modifier.sharedElement(
|
|
||||||
sharedContentState = rememberSharedContentState(
|
|
||||||
key = HERO_KEY_NOW_PLAYING_COVER,
|
|
||||||
),
|
|
||||||
animatedVisibilityScope = animatedScope,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Modifier
|
|
||||||
}
|
|
||||||
Box(
|
Box(
|
||||||
modifier = heroModifier
|
modifier = nowPlayingCoverHero()
|
||||||
.size(COVER_SIZE_DP.dp)
|
.size(COVER_SIZE_DP.dp)
|
||||||
.clip(RoundedCornerShape(FabledSwordFlatTokens.radiusSm))
|
.clip(RoundedCornerShape(FabledSwordFlatTokens.radiusSm))
|
||||||
.background(MaterialTheme.colorScheme.surfaceVariant),
|
.background(MaterialTheme.colorScheme.surfaceVariant),
|
||||||
@@ -176,6 +153,8 @@ fun MiniPlayer(
|
|||||||
isPlaying = state.isPlaying,
|
isPlaying = state.isPlaying,
|
||||||
isUpnpLoading = state.isUpnpLoading,
|
isUpnpLoading = state.isUpnpLoading,
|
||||||
isLiked = isLiked,
|
isLiked = isLiked,
|
||||||
|
hasPrevious = state.hasPrevious,
|
||||||
|
hasNext = state.hasNext,
|
||||||
onExpandClick = onExpandClick,
|
onExpandClick = onExpandClick,
|
||||||
onPlayPause = { if (state.isPlaying) viewModel.pause() else viewModel.play() },
|
onPlayPause = { if (state.isPlaying) viewModel.pause() else viewModel.play() },
|
||||||
onPrev = viewModel::skipToPrevious,
|
onPrev = viewModel::skipToPrevious,
|
||||||
@@ -218,6 +197,8 @@ private fun MiniRow(
|
|||||||
isPlaying: Boolean,
|
isPlaying: Boolean,
|
||||||
isUpnpLoading: Boolean,
|
isUpnpLoading: Boolean,
|
||||||
isLiked: Boolean,
|
isLiked: Boolean,
|
||||||
|
hasPrevious: Boolean,
|
||||||
|
hasNext: Boolean,
|
||||||
onExpandClick: () -> Unit,
|
onExpandClick: () -> Unit,
|
||||||
onPlayPause: () -> Unit,
|
onPlayPause: () -> Unit,
|
||||||
onPrev: () -> Unit,
|
onPrev: () -> Unit,
|
||||||
@@ -260,51 +241,34 @@ private fun MiniRow(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
LikeButton(liked = isLiked, onToggle = onToggleLike)
|
LikeButton(liked = isLiked, onToggle = onToggleLike)
|
||||||
TransportButton(icon = Lucide.SkipBack, description = "Previous", onClick = onPrev)
|
val tint = MaterialTheme.colorScheme.onSurface
|
||||||
MiniPlayPauseButton(
|
SkipButton(
|
||||||
|
icon = Lucide.SkipBack,
|
||||||
|
description = "Previous",
|
||||||
|
enabled = hasPrevious,
|
||||||
|
tint = tint,
|
||||||
|
iconSize = MINI_TRANSPORT_ICON_DP.dp,
|
||||||
|
onClick = onPrev,
|
||||||
|
)
|
||||||
|
PlayPauseButton(
|
||||||
isPlaying = isPlaying,
|
isPlaying = isPlaying,
|
||||||
isUpnpLoading = isUpnpLoading,
|
isUpnpLoading = isUpnpLoading,
|
||||||
|
tint = tint,
|
||||||
|
iconSize = MINI_TRANSPORT_ICON_DP.dp,
|
||||||
|
spinnerStroke = 2.dp,
|
||||||
onClick = onPlayPause,
|
onClick = onPlayPause,
|
||||||
)
|
)
|
||||||
TransportButton(icon = Lucide.SkipForward, description = "Next", onClick = onNext)
|
SkipButton(
|
||||||
}
|
icon = Lucide.SkipForward,
|
||||||
}
|
description = "Next",
|
||||||
|
enabled = hasNext,
|
||||||
@Composable
|
tint = tint,
|
||||||
private fun MiniPlayPauseButton(
|
iconSize = MINI_TRANSPORT_ICON_DP.dp,
|
||||||
isPlaying: Boolean,
|
onClick = onNext,
|
||||||
isUpnpLoading: Boolean,
|
|
||||||
onClick: () -> Unit,
|
|
||||||
) {
|
|
||||||
IconButton(onClick = onClick, enabled = !isUpnpLoading) {
|
|
||||||
if (isUpnpLoading) {
|
|
||||||
CircularProgressIndicator(
|
|
||||||
modifier = Modifier.size(MINI_PLAY_PAUSE_SPINNER_DP.dp),
|
|
||||||
strokeWidth = 2.dp,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Icon(
|
|
||||||
imageVector = if (isPlaying) Lucide.Pause else Lucide.Play,
|
|
||||||
contentDescription = if (isPlaying) "Pause" else "Play",
|
|
||||||
tint = MaterialTheme.colorScheme.onSurface,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private const val MINI_PLAY_PAUSE_SPINNER_DP = 24
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun TransportButton(
|
|
||||||
icon: androidx.compose.ui.graphics.vector.ImageVector,
|
|
||||||
description: String,
|
|
||||||
onClick: () -> Unit,
|
|
||||||
) {
|
|
||||||
IconButton(onClick = onClick) {
|
|
||||||
Icon(
|
|
||||||
imageVector = icon,
|
|
||||||
contentDescription = description,
|
|
||||||
tint = MaterialTheme.colorScheme.onSurface,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The mini player's transport icons, at Material's standard icon size. */
|
||||||
|
private const val MINI_TRANSPORT_ICON_DP = 24
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.fabledsword.minstrel.player.ui
|
||||||
|
|
||||||
|
import androidx.compose.animation.ExperimentalSharedTransitionApi
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import com.fabledsword.minstrel.nav.HERO_KEY_NOW_PLAYING_COVER
|
||||||
|
import com.fabledsword.minstrel.nav.LocalAnimatedContentScope
|
||||||
|
import com.fabledsword.minstrel.nav.LocalSharedTransitionScope
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The shared-element modifier that carries the playing song's cover
|
||||||
|
* between the mini player and Now Playing, so opening Now Playing grows
|
||||||
|
* the small cover into the large one. Outside a shared transition (a
|
||||||
|
* preview, a test) it is a plain Modifier.
|
||||||
|
*/
|
||||||
|
@OptIn(ExperimentalSharedTransitionApi::class)
|
||||||
|
@Composable
|
||||||
|
internal fun nowPlayingCoverHero(): Modifier {
|
||||||
|
val sharedScope = LocalSharedTransitionScope.current
|
||||||
|
val animatedScope = LocalAnimatedContentScope.current
|
||||||
|
if (sharedScope == null || animatedScope == null) return Modifier
|
||||||
|
return with(sharedScope) {
|
||||||
|
Modifier.sharedElement(
|
||||||
|
sharedContentState = rememberSharedContentState(key = HERO_KEY_NOW_PLAYING_COVER),
|
||||||
|
animatedVisibilityScope = animatedScope,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,6 @@ import android.Manifest
|
|||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.animation.ExperimentalSharedTransitionApi
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.focusable
|
import androidx.compose.foundation.focusable
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
@@ -26,7 +25,6 @@ import androidx.compose.foundation.layout.size
|
|||||||
import androidx.compose.foundation.layout.widthIn
|
import androidx.compose.foundation.layout.widthIn
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
@@ -77,8 +75,6 @@ import com.composables.icons.lucide.ChevronDown
|
|||||||
import com.composables.icons.lucide.ListMusic
|
import com.composables.icons.lucide.ListMusic
|
||||||
import com.composables.icons.lucide.Lucide
|
import com.composables.icons.lucide.Lucide
|
||||||
import com.composables.icons.lucide.Music
|
import com.composables.icons.lucide.Music
|
||||||
import com.composables.icons.lucide.Pause
|
|
||||||
import com.composables.icons.lucide.Play
|
|
||||||
import com.composables.icons.lucide.Repeat
|
import com.composables.icons.lucide.Repeat
|
||||||
import com.composables.icons.lucide.Repeat1
|
import com.composables.icons.lucide.Repeat1
|
||||||
import com.composables.icons.lucide.Shuffle
|
import com.composables.icons.lucide.Shuffle
|
||||||
@@ -94,9 +90,6 @@ import com.fabledsword.minstrel.player.output.RouteSnapshot
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import com.fabledsword.minstrel.nav.AlbumDetail
|
import com.fabledsword.minstrel.nav.AlbumDetail
|
||||||
import com.fabledsword.minstrel.nav.ArtistDetail
|
import com.fabledsword.minstrel.nav.ArtistDetail
|
||||||
import com.fabledsword.minstrel.nav.HERO_KEY_NOW_PLAYING_COVER
|
|
||||||
import com.fabledsword.minstrel.nav.LocalAnimatedContentScope
|
|
||||||
import com.fabledsword.minstrel.nav.LocalSharedTransitionScope
|
|
||||||
import com.fabledsword.minstrel.nav.NowPlaying
|
import com.fabledsword.minstrel.nav.NowPlaying
|
||||||
import com.fabledsword.minstrel.nav.Queue
|
import com.fabledsword.minstrel.nav.Queue
|
||||||
import com.fabledsword.minstrel.shared.formatDuration
|
import com.fabledsword.minstrel.shared.formatDuration
|
||||||
@@ -423,6 +416,8 @@ private fun PlaybackControlsBlock(
|
|||||||
TransportRow(
|
TransportRow(
|
||||||
isPlaying = state.isPlaying,
|
isPlaying = state.isPlaying,
|
||||||
isUpnpLoading = state.isUpnpLoading,
|
isUpnpLoading = state.isUpnpLoading,
|
||||||
|
hasPrevious = state.hasPrevious,
|
||||||
|
hasNext = state.hasNext,
|
||||||
onPrev = viewModel::skipToPrevious,
|
onPrev = viewModel::skipToPrevious,
|
||||||
onPlayPause = { if (state.isPlaying) viewModel.pause() else viewModel.play() },
|
onPlayPause = { if (state.isPlaying) viewModel.pause() else viewModel.play() },
|
||||||
onNext = viewModel::skipToNext,
|
onNext = viewModel::skipToNext,
|
||||||
@@ -537,25 +532,10 @@ private fun ViewQueueButton(onClick: () -> Unit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalSharedTransitionApi::class)
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun NowPlayingCover(coverUrl: String, contentDescription: String) {
|
private fun NowPlayingCover(coverUrl: String, contentDescription: String) {
|
||||||
val sharedScope = LocalSharedTransitionScope.current
|
|
||||||
val animatedScope = LocalAnimatedContentScope.current
|
|
||||||
val heroModifier = if (sharedScope != null && animatedScope != null) {
|
|
||||||
with(sharedScope) {
|
|
||||||
Modifier.sharedElement(
|
|
||||||
sharedContentState = rememberSharedContentState(
|
|
||||||
key = HERO_KEY_NOW_PLAYING_COVER,
|
|
||||||
),
|
|
||||||
animatedVisibilityScope = animatedScope,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Modifier
|
|
||||||
}
|
|
||||||
Box(
|
Box(
|
||||||
modifier = heroModifier
|
modifier = nowPlayingCoverHero()
|
||||||
.widthIn(max = COVER_MAX_WIDTH_DP.dp)
|
.widthIn(max = COVER_MAX_WIDTH_DP.dp)
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.aspectRatio(1f)
|
.aspectRatio(1f)
|
||||||
@@ -700,52 +680,49 @@ private fun ScrubTrack(fraction: Float, accent: Color) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("LongParameterList") // Compose row wiring — transport state + callbacks, not logic.
|
||||||
@Composable
|
@Composable
|
||||||
private fun TransportRow(
|
private fun TransportRow(
|
||||||
isPlaying: Boolean,
|
isPlaying: Boolean,
|
||||||
isUpnpLoading: Boolean,
|
isUpnpLoading: Boolean,
|
||||||
|
hasPrevious: Boolean,
|
||||||
|
hasNext: Boolean,
|
||||||
onPrev: () -> Unit,
|
onPrev: () -> Unit,
|
||||||
onPlayPause: () -> Unit,
|
onPlayPause: () -> Unit,
|
||||||
onNext: () -> Unit,
|
onNext: () -> Unit,
|
||||||
) {
|
) {
|
||||||
val actionColors = LocalActionColors.current
|
val actionColors = LocalActionColors.current
|
||||||
|
val skipTint = MaterialTheme.colorScheme.onBackground
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.SpaceEvenly,
|
horizontalArrangement = Arrangement.SpaceEvenly,
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
IconButton(onClick = onPrev) {
|
SkipButton(
|
||||||
Icon(
|
icon = Lucide.SkipBack,
|
||||||
imageVector = Lucide.SkipBack,
|
description = "Previous",
|
||||||
contentDescription = "Previous",
|
enabled = hasPrevious,
|
||||||
tint = MaterialTheme.colorScheme.onBackground,
|
tint = skipTint,
|
||||||
modifier = Modifier.size(TRANSPORT_ICON_DP.dp),
|
iconSize = TRANSPORT_ICON_DP.dp,
|
||||||
|
onClick = onPrev,
|
||||||
)
|
)
|
||||||
}
|
PlayPauseButton(
|
||||||
IconButton(onClick = onPlayPause, enabled = !isUpnpLoading) {
|
isPlaying = isPlaying,
|
||||||
if (isUpnpLoading) {
|
isUpnpLoading = isUpnpLoading,
|
||||||
CircularProgressIndicator(
|
|
||||||
modifier = Modifier.size(PLAY_PAUSE_ICON_DP.dp),
|
|
||||||
strokeWidth = 3.dp,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Icon(
|
|
||||||
imageVector = if (isPlaying) Lucide.Pause else Lucide.Play,
|
|
||||||
contentDescription = if (isPlaying) "Pause" else "Play",
|
|
||||||
tint = actionColors.primary,
|
tint = actionColors.primary,
|
||||||
modifier = Modifier.size(PLAY_PAUSE_ICON_DP.dp),
|
iconSize = PLAY_PAUSE_ICON_DP.dp,
|
||||||
|
spinnerStroke = 3.dp,
|
||||||
|
onClick = onPlayPause,
|
||||||
)
|
)
|
||||||
}
|
SkipButton(
|
||||||
}
|
icon = Lucide.SkipForward,
|
||||||
IconButton(onClick = onNext) {
|
description = "Next",
|
||||||
Icon(
|
enabled = hasNext,
|
||||||
imageVector = Lucide.SkipForward,
|
tint = skipTint,
|
||||||
contentDescription = "Next",
|
iconSize = TRANSPORT_ICON_DP.dp,
|
||||||
tint = MaterialTheme.colorScheme.onBackground,
|
onClick = onNext,
|
||||||
modifier = Modifier.size(TRANSPORT_ICON_DP.dp),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.fabledsword.minstrel.player.ui
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
|
import com.composables.icons.lucide.Lucide
|
||||||
|
import com.composables.icons.lucide.Pause
|
||||||
|
import com.composables.icons.lucide.Play
|
||||||
|
|
||||||
|
/** Material's alpha for disabled content. */
|
||||||
|
private const val DISABLED_ALPHA = 0.38f
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Previous or Next button, shared by the mini player and Now Playing.
|
||||||
|
* It greys out when [enabled] is false: at the ends of the queue (repeat
|
||||||
|
* off or repeat one) there is nowhere to go, and a button that does
|
||||||
|
* nothing should look it.
|
||||||
|
*/
|
||||||
|
@Suppress("LongParameterList") // Compose button wiring — look + state + click, not logic.
|
||||||
|
@Composable
|
||||||
|
internal fun SkipButton(
|
||||||
|
icon: ImageVector,
|
||||||
|
description: String,
|
||||||
|
enabled: Boolean,
|
||||||
|
tint: Color,
|
||||||
|
iconSize: Dp,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
) {
|
||||||
|
IconButton(onClick = onClick, enabled = enabled) {
|
||||||
|
Icon(
|
||||||
|
imageVector = icon,
|
||||||
|
contentDescription = description,
|
||||||
|
tint = if (enabled) tint else tint.copy(alpha = DISABLED_ALPHA),
|
||||||
|
modifier = Modifier.size(iconSize),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The play/pause button, shared by the mini player and Now Playing. While
|
||||||
|
* a speaker (Sonos or another UPnP renderer) is still taking the queue, a
|
||||||
|
* spinner stands in for the icon and the button is disabled, since a tap
|
||||||
|
* then would reach a player that isn't ready.
|
||||||
|
*/
|
||||||
|
@Suppress("LongParameterList") // Compose button wiring — look + state + click, not logic.
|
||||||
|
@Composable
|
||||||
|
internal fun PlayPauseButton(
|
||||||
|
isPlaying: Boolean,
|
||||||
|
isUpnpLoading: Boolean,
|
||||||
|
tint: Color,
|
||||||
|
iconSize: Dp,
|
||||||
|
spinnerStroke: Dp,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
) {
|
||||||
|
IconButton(onClick = onClick, enabled = !isUpnpLoading) {
|
||||||
|
if (isUpnpLoading) {
|
||||||
|
CircularProgressIndicator(
|
||||||
|
modifier = Modifier.size(iconSize),
|
||||||
|
strokeWidth = spinnerStroke,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Icon(
|
||||||
|
imageVector = if (isPlaying) Lucide.Pause else Lucide.Play,
|
||||||
|
contentDescription = if (isPlaying) "Pause" else "Play",
|
||||||
|
tint = tint,
|
||||||
|
modifier = Modifier.size(iconSize),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user