diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarHomeScreen.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarHomeScreen.kt index b60ee0d..899ba57 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarHomeScreen.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarHomeScreen.kt @@ -132,7 +132,11 @@ fun CarHome() { top = 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 * player goes back to the nav bar meanwhile and names the song there. Its note button swaps the diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarUi.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarUi.kt index aeb9f80..c599301 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarUi.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarUi.kt @@ -262,7 +262,8 @@ fun CarUi() { val homeInset = if (barShown) NAV_BAR_HEIGHT else 0.dp // Only the screen that asked: going Home or anywhere else ends it. 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()) { if (!safetyWarningSeen) { CarSafetyWizard(onDone = CarSettings::markSafetyWarningSeen) @@ -389,6 +390,7 @@ fun CarUi() { AppMenu(navigator, rememberRunningApps()) if (safetyWarningSeen) CarWhatsNew() } + } } } } @@ -397,6 +399,16 @@ fun CarUi() { 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, * zero while it's hidden or when it has a row of its own.