mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-11-30 23:30:32 +01:00
On a short car screen, the media screen fits its tabs to the height: controls beside the cover, a grid to browse, and slimmer queue rows
On a SOOEMAKA's 369 dp screen the Now playing tab had no room for the cover, the browse list showed three rows, and Up next showed under three. On a short screen (see LocalShortScreen), every tab now takes the screen's width rather than its height: - Now playing: the title, seek bar and buttons on the left, with the transport and like, shuffle and repeat in one row, and the cover as tall as the page on the right. - Browse: every entry is a button with a small cover, as many across as fit, under the app's headings. In a folder, the way back up and the folder's name sit in the screen's header instead of a row of their own. - Up next: slimmer rows, so four or five show. Taller screens keep their layouts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
56dafa8fc3
commit
49f5db59a7
2 files changed
+145
-29
No files matched your search
@@ -85,20 +85,9 @@ internal fun BrowsePanel(browse: app.seb3thehacker.gearslip.media.BrowseState, m
|
|||||||
// At the library root there's no trail and nowhere to go up to, so there's nothing this
|
// At the library root there's no trail and nowhere to go up to, so there's nothing this
|
||||||
// row could say that the app's name in the top-left corner hasn't already - showing it
|
// row could say that the app's name in the top-left corner hasn't already - showing it
|
||||||
// again here (as "Browse", or as the app's own name) was just the same label twice.
|
// again here (as "Browse", or as the app's own name) was just the same label twice.
|
||||||
if (media.canGoUp || browse.trail.isNotEmpty()) {
|
// A short screen has it in the media screen's own header instead.
|
||||||
Row(Modifier.padding(bottom = 12.dp), verticalAlignment = Alignment.CenterVertically) {
|
if (!LocalShortScreen.current && (media.canGoUp || browse.trail.isNotEmpty())) {
|
||||||
if (media.canGoUp) {
|
BrowseUp(browse, media, Modifier.padding(bottom = 12.dp))
|
||||||
GsIconButton(Icons.Filled.ArrowBack, stringResource(R.string.media_up), media::up, size = 44.dp, shape = CircleShape)
|
|
||||||
Spacer(Modifier.width(14.dp))
|
|
||||||
}
|
|
||||||
browse.trail.lastOrNull()?.let {
|
|
||||||
Text(
|
|
||||||
it,
|
|
||||||
style = MaterialTheme.typography.titleLarge, fontWeight = FontWeight.Bold,
|
|
||||||
maxLines = 1, overflow = TextOverflow.Ellipsis,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
when {
|
when {
|
||||||
browse.loading -> Notice(stringResource(R.string.media_loading), null)
|
browse.loading -> Notice(stringResource(R.string.media_loading), null)
|
||||||
@@ -113,6 +102,24 @@ internal fun BrowsePanel(browse: app.seb3thehacker.gearslip.media.BrowseState, m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The way back up out of a folder, and the folder's name. */
|
||||||
|
@Composable
|
||||||
|
internal fun BrowseUp(browse: app.seb3thehacker.gearslip.media.BrowseState, media: CarMedia, modifier: Modifier = Modifier) {
|
||||||
|
Row(modifier, verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
if (media.canGoUp) {
|
||||||
|
GsIconButton(Icons.Filled.ArrowBack, stringResource(R.string.media_up), media::up, size = 44.dp, shape = CircleShape)
|
||||||
|
Spacer(Modifier.width(14.dp))
|
||||||
|
}
|
||||||
|
browse.trail.lastOrNull()?.let {
|
||||||
|
Text(
|
||||||
|
it,
|
||||||
|
style = MaterialTheme.typography.titleLarge, fontWeight = FontWeight.Bold,
|
||||||
|
maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list laid out the way the app asked: under its section headings, covers where it asked for a
|
* A list laid out the way the app asked: under its section headings, covers where it asked for a
|
||||||
* grid and rows everywhere else. A grid section among others is a shelf that scrolls sideways; a
|
* grid and rows everywhere else. A grid section among others is a shelf that scrolls sideways; a
|
||||||
@@ -123,6 +130,10 @@ private fun BrowseList(entries: List<MediaEntry>, media: CarMedia) {
|
|||||||
// A list's keys must be unique, and some apps list the same item twice (Music Assistant's
|
// A list's keys must be unique, and some apps list the same item twice (Music Assistant's
|
||||||
// playlists, issue #90): the repeat would do the same thing anyway, so it's dropped.
|
// playlists, issue #90): the repeat would do the same thing anyway, so it's dropped.
|
||||||
val sections = remember(entries) { browseSections(entries.distinctBy { it.id }) }
|
val sections = remember(entries) { browseSections(entries.distinctBy { it.id }) }
|
||||||
|
if (LocalShortScreen.current) {
|
||||||
|
BrowseGrid(sections, media)
|
||||||
|
return
|
||||||
|
}
|
||||||
BoxWithConstraints(Modifier.fillMaxSize()) {
|
BoxWithConstraints(Modifier.fillMaxSize()) {
|
||||||
val onlyGrid = sections.size == 1 && sections[0].grid && sections[0].heading == null
|
val onlyGrid = sections.size == 1 && sections[0].grid && sections[0].heading == null
|
||||||
val columns = ((maxWidth + SHELF_GAP) / (SHELF_COVER + SHELF_GAP)).toInt().coerceAtLeast(2)
|
val columns = ((maxWidth + SHELF_GAP) / (SHELF_COVER + SHELF_GAP)).toInt().coerceAtLeast(2)
|
||||||
@@ -162,6 +173,67 @@ private fun BrowseList(entries: List<MediaEntry>, media: CarMedia) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The browse list for a short screen, where a list showed three rows and a shelf of covers one:
|
||||||
|
* every entry is a button with a small cover, as many across as fit, under the app's headings.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
private fun BrowseGrid(sections: List<BrowseSection>, media: CarMedia) {
|
||||||
|
androidx.compose.foundation.lazy.grid.LazyVerticalGrid(
|
||||||
|
columns = androidx.compose.foundation.lazy.grid.GridCells.Adaptive(GRID_BUTTON_WIDTH),
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
contentPadding = PaddingValues(bottom = 8.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
) {
|
||||||
|
sections.forEachIndexed { i, section ->
|
||||||
|
val heading = section.heading
|
||||||
|
if (heading != null && sections.getOrNull(i - 1)?.heading != heading) {
|
||||||
|
item(key = "heading $i", span = { androidx.compose.foundation.lazy.grid.GridItemSpan(maxLineSpan) }) {
|
||||||
|
Text(
|
||||||
|
heading,
|
||||||
|
style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold,
|
||||||
|
maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||||
|
modifier = Modifier.padding(top = if (i == 0) 0.dp else 4.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
items(section.entries.size, key = { section.entries[it].id }) { EntryButton(section.entries[it], media) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One entry as a button in [BrowseGrid]: its cover, its name, and play for a folder that plays. */
|
||||||
|
@Composable
|
||||||
|
private fun EntryButton(entry: MediaEntry, media: CarMedia) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val icon by produceState(entry.iconBitmap, entry.iconUri) {
|
||||||
|
value = entry.iconBitmap ?: MediaArt.load(context, entry.iconUri)
|
||||||
|
}
|
||||||
|
Surface(
|
||||||
|
onClick = { media.select(entry) },
|
||||||
|
shape = MaterialTheme.shapes.large,
|
||||||
|
color = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
) {
|
||||||
|
Row(Modifier.padding(6.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
RowArt(icon, if (entry.browsable) MediaIcons.Folder else MediaIcons.MusicNote, size = 44.dp)
|
||||||
|
Column(Modifier.weight(1f).padding(horizontal = 10.dp)) {
|
||||||
|
Text(entry.title, style = MaterialTheme.typography.titleSmall, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||||
|
if (entry.subtitle.isNotEmpty()) {
|
||||||
|
Text(entry.subtitle, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (entry.browsable && entry.playable) {
|
||||||
|
GsIconButton(Icons.Filled.PlayArrow, stringResource(R.string.media_play), { media.playAll(entry) }, size = 40.dp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The narrowest a button in [BrowseGrid] gets before it gives up a column. */
|
||||||
|
private val GRID_BUTTON_WIDTH = 220.dp
|
||||||
|
|
||||||
private val SHELF_COVER = 132.dp
|
private val SHELF_COVER = 132.dp
|
||||||
private val SHELF_GAP = 14.dp
|
private val SHELF_GAP = 14.dp
|
||||||
|
|
||||||
@@ -243,7 +315,7 @@ internal fun QueuePanel(queue: List<QueueTrack>, now: NowPlaying, media: CarMedi
|
|||||||
LazyColumn(
|
LazyColumn(
|
||||||
Modifier.fillMaxSize(),
|
Modifier.fillMaxSize(),
|
||||||
contentPadding = PaddingValues(bottom = 8.dp),
|
contentPadding = PaddingValues(bottom = 8.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
verticalArrangement = Arrangement.spacedBy(if (LocalShortScreen.current) 4.dp else 8.dp),
|
||||||
) {
|
) {
|
||||||
items(upNext.distinctBy { it.queueId }, key = { it.queueId }) { track -> QueueRow(track, media) }
|
items(upNext.distinctBy { it.queueId }, key = { it.queueId }) { track -> QueueRow(track, media) }
|
||||||
}
|
}
|
||||||
@@ -257,18 +329,20 @@ private fun QueueRow(track: QueueTrack, media: CarMedia) {
|
|||||||
val icon by produceState(track.iconBitmap, track.iconUri) {
|
val icon by produceState(track.iconBitmap, track.iconUri) {
|
||||||
value = track.iconBitmap ?: MediaArt.load(context, track.iconUri)
|
value = track.iconBitmap ?: MediaArt.load(context, track.iconUri)
|
||||||
}
|
}
|
||||||
|
// A short screen showed two and a half rows; slimmer ones show four or five.
|
||||||
|
val short = LocalShortScreen.current
|
||||||
Surface(
|
Surface(
|
||||||
onClick = { media.playQueueItem(track) },
|
onClick = { media.playQueueItem(track) },
|
||||||
shape = MaterialTheme.shapes.large,
|
shape = MaterialTheme.shapes.large,
|
||||||
color = MaterialTheme.colorScheme.surfaceContainer,
|
color = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
) {
|
) {
|
||||||
Row(Modifier.padding(8.dp), verticalAlignment = Alignment.CenterVertically) {
|
Row(Modifier.padding(if (short) 4.dp else 8.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||||
RowArt(icon, MediaIcons.MusicNote)
|
RowArt(icon, MediaIcons.MusicNote, size = if (short) 40.dp else 56.dp)
|
||||||
Column(Modifier.weight(1f).padding(horizontal = 14.dp)) {
|
Column(Modifier.weight(1f).padding(horizontal = if (short) 10.dp else 14.dp)) {
|
||||||
Text(track.title, style = MaterialTheme.typography.titleMedium, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
Text(track.title, style = if (short) MaterialTheme.typography.titleSmall else MaterialTheme.typography.titleMedium, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||||
if (track.subtitle.isNotEmpty()) {
|
if (track.subtitle.isNotEmpty()) {
|
||||||
Text(track.subtitle, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
Text(track.subtitle, style = if (short) MaterialTheme.typography.bodySmall else MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Icon(Icons.Filled.PlayArrow, stringResource(R.string.media_play), tint = MaterialTheme.colorScheme.onSurfaceVariant)
|
Icon(Icons.Filled.PlayArrow, stringResource(R.string.media_play), tint = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||||
@@ -306,13 +380,13 @@ internal fun EntryRow(entry: MediaEntry, media: CarMedia, onClick: () -> Unit =
|
|||||||
|
|
||||||
/** A row's artwork, or a folder or note in its place when the app sends none. */
|
/** A row's artwork, or a folder or note in its place when the app sends none. */
|
||||||
@Composable
|
@Composable
|
||||||
private fun RowArt(icon: android.graphics.Bitmap?, fallback: ImageVector) {
|
private fun RowArt(icon: android.graphics.Bitmap?, fallback: ImageVector, size: androidx.compose.ui.unit.Dp = 56.dp) {
|
||||||
Box(
|
Box(
|
||||||
Modifier.size(56.dp).clip(RoundedCornerShape(12.dp)).background(MaterialTheme.colorScheme.surfaceContainerHigh),
|
Modifier.size(size).clip(RoundedCornerShape(size * 12 / 56)).background(MaterialTheme.colorScheme.surfaceContainerHigh),
|
||||||
contentAlignment = Alignment.Center,
|
contentAlignment = Alignment.Center,
|
||||||
) {
|
) {
|
||||||
if (icon != null) Image(icon.asImageBitmap(), null, Modifier.fillMaxSize(), contentScale = ContentScale.Crop)
|
if (icon != null) Image(icon.asImageBitmap(), null, Modifier.fillMaxSize(), contentScale = ContentScale.Crop)
|
||||||
else Icon(fallback, null, tint = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.size(30.dp))
|
else Icon(fallback, null, tint = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.size(size * 30 / 56))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -199,17 +199,23 @@ fun MediaScreen(app: MediaApp, onExit: () -> Unit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BoxWithConstraints(Modifier.fillMaxSize().padding(start = 16.dp, end = 16.dp, top = 10.dp)) {
|
BoxWithConstraints(Modifier.fillMaxSize().padding(start = 16.dp, end = 16.dp, top = 10.dp)) {
|
||||||
// A small screen, or a big one at Extra large size, has no room for two columns: the
|
// A small or short screen, or a big one at Extra large size, has no room for two
|
||||||
// app and the tabs share one bar, and a list takes the whole width. The nav bar keeps
|
// columns: the app and the tabs share one bar, and a list takes the whole width. The
|
||||||
// the controls, so nothing is lost.
|
// nav bar keeps the controls, so nothing is lost.
|
||||||
if (maxWidth < NARROW_WIDTH || maxHeight - barInset < NARROW_HEIGHT) {
|
if (LocalShortScreen.current || maxWidth < NARROW_WIDTH || maxHeight - barInset < NARROW_HEIGHT) {
|
||||||
Column(Modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
Column(Modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
Row(
|
Row(
|
||||||
Modifier.fillMaxWidth(),
|
Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
AppIdentity(app, onExit, Modifier.widthIn(max = 180.dp))
|
// On a short screen, a folder's way back up takes the app's place here
|
||||||
|
// rather than a row of its own over the list.
|
||||||
|
if (LocalShortScreen.current && tab == Tab.BROWSE && (media.canGoUp || browse.trail.isNotEmpty())) {
|
||||||
|
BrowseUp(browse, media, Modifier.widthIn(max = 280.dp))
|
||||||
|
} else {
|
||||||
|
AppIdentity(app, onExit, Modifier.widthIn(max = 180.dp))
|
||||||
|
}
|
||||||
Row(
|
Row(
|
||||||
Modifier.weight(1f).horizontalScroll(rememberScrollState()),
|
Modifier.weight(1f).horizontalScroll(rememberScrollState()),
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End),
|
horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End),
|
||||||
@@ -644,7 +650,14 @@ internal fun Notice(title: String, detail: String?, action: Pair<String, () -> U
|
|||||||
internal fun NowPlayingPage(now: NowPlaying, media: CarMedia, modifier: Modifier, padded: Boolean = true) {
|
internal fun NowPlayingPage(now: NowPlaying, media: CarMedia, modifier: Modifier, padded: Boolean = true) {
|
||||||
BoxWithConstraints(if (padded) modifier.padding(horizontal = 24.dp, vertical = 8.dp) else modifier) {
|
BoxWithConstraints(if (padded) modifier.padding(horizontal = 24.dp, vertical = 8.dp) else modifier) {
|
||||||
val art = rememberArt(now)
|
val art = rememberArt(now)
|
||||||
if (maxWidth >= 520.dp && maxHeight >= 260.dp) {
|
if (LocalShortScreen.current) {
|
||||||
|
// A short screen: the controls on the driver's side, the cover as tall as the page beside them.
|
||||||
|
val cover = minOf(maxHeight, maxWidth * 0.4f)
|
||||||
|
Row(Modifier.fillMaxSize(), horizontalArrangement = Arrangement.spacedBy(20.dp)) {
|
||||||
|
ShortControls(now, media, Modifier.weight(1f).fillMaxHeight())
|
||||||
|
CoverArt(art, Modifier.width(cover).fillMaxHeight())
|
||||||
|
}
|
||||||
|
} else if (maxWidth >= 520.dp && maxHeight >= 260.dp) {
|
||||||
val artWidth = minOf(maxHeight, (maxWidth - 24.dp) * 0.4f)
|
val artWidth = minOf(maxHeight, (maxWidth - 24.dp) * 0.4f)
|
||||||
Row(Modifier.fillMaxSize(), horizontalArrangement = Arrangement.spacedBy(24.dp)) {
|
Row(Modifier.fillMaxSize(), horizontalArrangement = Arrangement.spacedBy(24.dp)) {
|
||||||
CoverArt(art, Modifier.width(artWidth).fillMaxHeight())
|
CoverArt(art, Modifier.width(artWidth).fillMaxHeight())
|
||||||
@@ -777,6 +790,35 @@ private fun NowPlayingControls(now: NowPlaying, media: CarMedia, modifier: Modif
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [NowPlayingControls] for a short screen, which has width to spare but little height: the title
|
||||||
|
* and seek bar, then the transport and like, shuffle and repeat side by side in one row.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
private fun ShortControls(now: NowPlaying, media: CarMedia, modifier: Modifier) {
|
||||||
|
Column(modifier, verticalArrangement = Arrangement.spacedBy(6.dp, Alignment.CenterVertically)) {
|
||||||
|
// The title gives up its height first and scrolls, so the controls never leave the screen.
|
||||||
|
Column(Modifier.weight(1f, fill = false).verticalScroll(rememberScrollState())) {
|
||||||
|
Text(
|
||||||
|
now.title.ifEmpty { stringResource(R.string.media_nothing_playing) },
|
||||||
|
style = MaterialTheme.typography.headlineSmall, fontWeight = FontWeight.Bold,
|
||||||
|
maxLines = 2, overflow = TextOverflow.Ellipsis,
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
listOf(now.artist, now.album).filter { it.isNotEmpty() }.joinToString(" · "),
|
||||||
|
style = MaterialTheme.typography.titleMedium, color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||||
|
)
|
||||||
|
now.error?.let { Text(it, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.error, maxLines = 2) }
|
||||||
|
}
|
||||||
|
PlayerProgress(now, media, Modifier.fillMaxWidth(), timeStyle = MaterialTheme.typography.titleMedium)
|
||||||
|
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
TransportRow(now, media, skip = 48.dp, modifier = Modifier.weight(1f))
|
||||||
|
PlayModeRow(now, media, size = 44.dp, modifier = Modifier.weight(1f), maxOther = 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Below these, the media app drops to one column: see [MediaScreen]. */
|
/** Below these, the media app drops to one column: see [MediaScreen]. */
|
||||||
private val NARROW_WIDTH = 600.dp
|
private val NARROW_WIDTH = 600.dp
|
||||||
private val NARROW_HEIGHT = 300.dp
|
private val NARROW_HEIGHT = 300.dp
|
||||||
|
|||||||
Reference in new issue
Block a user