Keep the play bar's buttons on screen
In Russian, or at the large text size, Play, Shuffle and a page's heart and download buttons are wider than a phone: on a Galaxy S20 the download button went past the edge. When the row doesn't fit, Shuffle now drops its label and shows as a round icon button with the same outline; English on a roomy screen looks as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8b5cedd991
commit
329686ab02
1 file changed
+45
-4
@@ -15,17 +15,21 @@ import androidx.compose.foundation.layout.width
|
|||||||
import androidx.compose.foundation.lazy.LazyListScope
|
import androidx.compose.foundation.lazy.LazyListScope
|
||||||
import androidx.compose.foundation.lazy.itemsIndexed
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.OutlinedButton
|
import androidx.compose.material3.OutlinedButton
|
||||||
|
import androidx.compose.material3.OutlinedIconButton
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.layout.SubcomposeLayout
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.semantics.contentDescription
|
import androidx.compose.ui.semantics.contentDescription
|
||||||
import androidx.compose.ui.semantics.semantics
|
import androidx.compose.ui.semantics.semantics
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
|
import androidx.compose.ui.unit.Constraints
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import it.panov.musyx.api.PlaylistId
|
import it.panov.musyx.api.PlaylistId
|
||||||
import it.panov.musyx.api.Track
|
import it.panov.musyx.api.Track
|
||||||
@@ -166,23 +170,60 @@ fun ShiftMarker(shift: Int) {
|
|||||||
Text(glyph, style = MusyxTheme.type.small, color = colour, modifier = Modifier.width(14.dp), textAlign = TextAlign.Center)
|
Text(glyph, style = MusyxTheme.type.small, color = colour, modifier = Modifier.width(14.dp), textAlign = TextAlign.Center)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Play and Shuffle, then any page actions (the heart), then a summary. */
|
/**
|
||||||
|
* Play and Shuffle, then any page actions (the heart, download), then a summary. Where the
|
||||||
|
* row would run off the screen (Russian labels, large text), Shuffle drops its label.
|
||||||
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun PlayBar(state: AppState, tracks: List<Track>, summary: String = "", actions: @Composable () -> Unit = {}) {
|
fun PlayBar(state: AppState, tracks: List<Track>, summary: String = "", actions: @Composable () -> Unit = {}) {
|
||||||
val space = MusyxTheme.space
|
val space = MusyxTheme.space
|
||||||
Column(Modifier.fillMaxWidth().padding(horizontal = space.gutter), verticalArrangement = Arrangement.spacedBy(space.s)) {
|
Column(Modifier.fillMaxWidth().padding(horizontal = space.gutter), verticalArrangement = Arrangement.spacedBy(space.s)) {
|
||||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(space.s)) {
|
FitRow(
|
||||||
|
wide = { PlayRow(state, tracks, shuffleLabel = true, actions) },
|
||||||
|
narrow = { PlayRow(state, tracks, shuffleLabel = false, actions) },
|
||||||
|
)
|
||||||
|
if (summary.isNotEmpty()) Text(summary, style = MusyxTheme.type.meta, color = MusyxTheme.colors.muted)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun PlayRow(state: AppState, tracks: List<Track>, shuffleLabel: Boolean, actions: @Composable () -> Unit) {
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(MusyxTheme.space.s)) {
|
||||||
Button(onClick = { state.playTracks(tracks, 0) }, enabled = tracks.isNotEmpty()) {
|
Button(onClick = { state.playTracks(tracks, 0) }, enabled = tracks.isNotEmpty()) {
|
||||||
MusyxIcon(R.drawable.ic_play_fill, tint = MusyxTheme.colors.accentInk, size = 18.dp)
|
MusyxIcon(R.drawable.ic_play_fill, tint = MusyxTheme.colors.accentInk, size = 18.dp)
|
||||||
Text(stringResource(R.string.action_play), modifier = Modifier.padding(start = 8.dp))
|
Text(stringResource(R.string.action_play), modifier = Modifier.padding(start = 8.dp))
|
||||||
}
|
}
|
||||||
OutlinedButton(onClick = { state.playTracks(tracks, 0, shuffle = true) }, enabled = tracks.isNotEmpty()) {
|
val shuffle = { state.playTracks(tracks, 0, shuffle = true) }
|
||||||
|
if (shuffleLabel) {
|
||||||
|
OutlinedButton(onClick = shuffle, enabled = tracks.isNotEmpty()) {
|
||||||
MusyxIcon(R.drawable.ic_shuffle, size = 18.dp)
|
MusyxIcon(R.drawable.ic_shuffle, size = 18.dp)
|
||||||
Text(stringResource(R.string.action_shuffle), modifier = Modifier.padding(start = 8.dp))
|
Text(stringResource(R.string.action_shuffle), modifier = Modifier.padding(start = 8.dp))
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
val label = stringResource(R.string.action_shuffle)
|
||||||
|
OutlinedIconButton(
|
||||||
|
onClick = shuffle,
|
||||||
|
enabled = tracks.isNotEmpty(),
|
||||||
|
// The same outline as the labelled button it stands in for.
|
||||||
|
border = ButtonDefaults.outlinedButtonBorder(tracks.isNotEmpty()),
|
||||||
|
modifier = Modifier.semantics { contentDescription = label },
|
||||||
|
) { MusyxIcon(R.drawable.ic_shuffle, size = 18.dp) }
|
||||||
|
}
|
||||||
actions()
|
actions()
|
||||||
}
|
}
|
||||||
if (summary.isNotEmpty()) Text(summary, style = MusyxTheme.type.meta, color = MusyxTheme.colors.muted)
|
}
|
||||||
|
|
||||||
|
/** Lays out `wide` when it fits the width it's given, else `narrow`. */
|
||||||
|
@Composable
|
||||||
|
private fun FitRow(wide: @Composable () -> Unit, narrow: @Composable () -> Unit) {
|
||||||
|
SubcomposeLayout { constraints ->
|
||||||
|
val free = Constraints(maxHeight = constraints.maxHeight)
|
||||||
|
val tried = subcompose(true, wide).map { it.measure(free) }
|
||||||
|
val row = if (tried.maxOf { it.width } <= constraints.maxWidth) tried
|
||||||
|
else subcompose(false, narrow).map { it.measure(constraints.copy(minWidth = 0)) }
|
||||||
|
layout(row.maxOf { it.width }.coerceAtMost(constraints.maxWidth), row.maxOf { it.height }) {
|
||||||
|
row.forEach { it.place(0, 0) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user