mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-12-01 07:40:31 +01:00
Merge Short-screen layouts for the media screens (#149)
This commit is contained in:
commit
6e81391bdc
4 files changed
+233
-31
No files matched your search
@@ -132,7 +132,11 @@ fun CarHome() {
|
|||||||
top = CARD_GAP,
|
top = CARD_GAP,
|
||||||
bottom = LocalNavBarInset.current + CARD_GAP,
|
bottom = LocalNavBarInset.current + CARD_GAP,
|
||||||
)
|
)
|
||||||
if (shown.value == SidePanel.LYRICS) SideLyrics(now, card) else DockedPlayer(now, card)
|
when {
|
||||||
|
shown.value == SidePanel.LYRICS -> SideLyrics(now, card)
|
||||||
|
LocalShortScreen.current -> CoverPlayer(now, card)
|
||||||
|
else -> DockedPlayer(now, card)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -291,6 +295,76 @@ private fun DockedPlayer(now: NowPlaying, modifier: Modifier) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The player beside the map on a short screen, where a cover above the controls had room for only
|
||||||
|
* a sliver: the cover fills the card, darkened toward the bottom, with the title, seek bar and
|
||||||
|
* transport over it. Tapping the cover opens the full media screen, as on the tall player.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
private fun CoverPlayer(now: NowPlaying, modifier: Modifier, shape: androidx.compose.ui.graphics.Shape = CARD_SHAPE) {
|
||||||
|
val navigator = LocalCarNavigator.current
|
||||||
|
val media = CarServices.media
|
||||||
|
val art = rememberArt(now)
|
||||||
|
val scheme = MaterialTheme.colorScheme
|
||||||
|
// Light text and buttons over the darkened cover, whatever the theme; the theme's own without one.
|
||||||
|
val over = when {
|
||||||
|
art == null || scheme.surface.luminance() < 0.5f -> scheme
|
||||||
|
else -> androidx.compose.material3.dynamicDarkColorScheme(LocalContext.current)
|
||||||
|
}
|
||||||
|
Surface(modifier = modifier.gsPanelShadow(shape), shape = shape, color = scheme.surfaceContainer) {
|
||||||
|
Box(Modifier.fillMaxSize().clickable { navigator.media() }) {
|
||||||
|
// A new song's cover fades in over the old one instead of cutting to it.
|
||||||
|
androidx.compose.animation.Crossfade(art, animationSpec = tween(350), label = "cover") { shown ->
|
||||||
|
if (shown != null) {
|
||||||
|
Box(Modifier.fillMaxSize()) {
|
||||||
|
Image(shown.asImageBitmap(), null, Modifier.fillMaxSize(), contentScale = ContentScale.Crop)
|
||||||
|
Box(
|
||||||
|
Modifier.fillMaxSize().background(
|
||||||
|
androidx.compose.ui.graphics.Brush.verticalGradient(
|
||||||
|
0f to Color.Black.copy(alpha = 0.2f),
|
||||||
|
0.4f to Color.Black.copy(alpha = 0.45f),
|
||||||
|
1f to Color.Black.copy(alpha = 0.78f),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
AlbumGlow(null, Modifier.fillMaxSize())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MaterialTheme(colorScheme = over) {
|
||||||
|
Column(
|
||||||
|
Modifier.fillMaxSize().padding(12.dp),
|
||||||
|
verticalArrangement = Arrangement.Bottom,
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
now.title, style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold,
|
||||||
|
color = over.onSurface, maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
now.artist, style = MaterialTheme.typography.bodyMedium, color = over.onSurfaceVariant,
|
||||||
|
maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||||
|
)
|
||||||
|
if (now.durationMs > 0) {
|
||||||
|
PlayerProgress(
|
||||||
|
now, media, Modifier.fillMaxWidth().padding(vertical = 2.dp),
|
||||||
|
timeStyle = MaterialTheme.typography.labelLarge,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Spacer(Modifier.height(10.dp))
|
||||||
|
}
|
||||||
|
BoxWithConstraints(Modifier.fillMaxWidth()) {
|
||||||
|
// As on the tall player: two skips, play at 1.25 times a skip, and two gaps.
|
||||||
|
val skip = ((maxWidth - 40.dp) / 3.25f).coerceIn(36.dp, 48.dp)
|
||||||
|
TransportRow(now, media, skip = skip, modifier = Modifier.fillMaxWidth())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lyrics alone beside the map, big enough to read at a glance. The header is slim, since the
|
* Lyrics alone beside the map, big enough to read at a glance. The header is slim, since the
|
||||||
* player goes back to the nav bar meanwhile and names the song there. Its note button swaps the
|
* player goes back to the nav bar meanwhile and names the song there. Its note button swaps the
|
||||||
|
|||||||
@@ -277,7 +277,8 @@ fun CarUi() {
|
|||||||
val homeInset = if (barShown) NAV_BAR_HEIGHT else 0.dp
|
val homeInset = if (barShown) NAV_BAR_HEIGHT else 0.dp
|
||||||
// Only the screen that asked: going Home or anywhere else ends it.
|
// Only the screen that asked: going Home or anywhere else ends it.
|
||||||
val fullscreen = CarFullscreen.active && screen != CarScreen.Home
|
val fullscreen = CarFullscreen.active && screen != CarScreen.Home
|
||||||
Box(Modifier.fillMaxSize().padding(pad)) {
|
BoxWithConstraints(Modifier.fillMaxSize().padding(pad)) {
|
||||||
|
CompositionLocalProvider(LocalShortScreen provides (maxHeight < SHORT_SCREEN_HEIGHT)) {
|
||||||
Column(Modifier.fillMaxSize()) {
|
Column(Modifier.fillMaxSize()) {
|
||||||
if (!safetyWarningSeen) {
|
if (!safetyWarningSeen) {
|
||||||
CarSafetyWizard(onDone = CarSettings::markSafetyWarningSeen)
|
CarSafetyWizard(onDone = CarSettings::markSafetyWarningSeen)
|
||||||
@@ -404,6 +405,7 @@ fun CarUi() {
|
|||||||
AppMenu(navigator, rememberRunningApps())
|
AppMenu(navigator, rememberRunningApps())
|
||||||
if (safetyWarningSeen) CarWhatsNew()
|
if (safetyWarningSeen) CarWhatsNew()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -412,6 +414,16 @@ fun CarUi() {
|
|||||||
|
|
||||||
internal val NAV_BAR_HEIGHT = 56.dp
|
internal val NAV_BAR_HEIGHT = 56.dp
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the car's screen is short: under [SHORT_SCREEN_HEIGHT] tall inside the car's margins, as a
|
||||||
|
* single-DIN unit's is. Screens laid out for the usual height switch to a compact layout of their
|
||||||
|
* own on it; on any taller screen nothing changes.
|
||||||
|
*/
|
||||||
|
internal val LocalShortScreen = androidx.compose.runtime.compositionLocalOf { false }
|
||||||
|
|
||||||
|
/** A SOOEMAKA single-DIN unit's screen is 369 dp tall; most head units' are 480 dp or more. */
|
||||||
|
internal val SHORT_SCREEN_HEIGHT = 420.dp
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How much of the bottom of Home the floating nav bar covers right now: its height while it shows,
|
* How much of the bottom of Home the floating nav bar covers right now: its height while it shows,
|
||||||
* zero while it's hidden or when it has a row of its own.
|
* zero while it's hidden or when it has a row of its own.
|
||||||
|
|||||||
@@ -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