Modern Apps git

← Modern-Apps.git

library: add tv design system for D-pad apps

Commit
d1b6a61999e69414684aa1404e696a04905ca666
Author
vayun-mathur <[email protected]>
When
2026-10-25 21:35 UTC (1 month ago)
Parents
3524d0c

Diff

library/tv/build.gradle.kts
diff --git a/library/tv/build.gradle.kts b/library/tv/build.gradle.ktsnew file mode 100644index 0000000000..83b5150cbf--- /dev/null+++ b/library/tv/build.gradle.kts@@ -0,0 +1,11 @@+plugins {+    id("common-conventions-library")+}+dependencies {+    implementation(project(":library"))+    // Icons come from :library:ui; deliberately no :library:image so the offline cast receiver+    // does not inherit INTERNET. Image-bearing components take a slot instead of a URL.+    implementation(project(":library:ui"))+    api(libs.androidx.tv.material)+    implementation(libs.androidx.compose.foundation)+}
library/tv/src/main/java/com/vayunmathur/library/tv/TvAppFrame.kt
diff --git a/library/tv/src/main/java/com/vayunmathur/library/tv/TvAppFrame.kt b/library/tv/src/main/java/com/vayunmathur/library/tv/TvAppFrame.ktnew file mode 100644index 0000000000..e501cdb80a--- /dev/null+++ b/library/tv/src/main/java/com/vayunmathur/library/tv/TvAppFrame.kt@@ -0,0 +1,182 @@+package com.vayunmathur.library.tv++import androidx.activity.compose.BackHandler+import androidx.compose.animation.core.animateDpAsState+import androidx.compose.animation.core.animateFloatAsState+import androidx.compose.foundation.background+import androidx.compose.foundation.focusGroup+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxHeight+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.width+import androidx.compose.foundation.layout.wrapContentWidth+import androidx.compose.foundation.shape.CircleShape+import androidx.compose.runtime.Composable+import androidx.compose.runtime.CompositionLocalProvider+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clipToBounds+import androidx.compose.ui.focus.FocusDirection+import androidx.compose.ui.focus.FocusRequester+import androidx.compose.ui.focus.focusRequester+import androidx.compose.ui.focus.focusRestorer+import androidx.compose.ui.focus.onFocusChanged+import androidx.compose.ui.graphics.Brush+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.graphicsLayer+import androidx.compose.ui.platform.LocalFocusManager+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.dp+import androidx.tv.material3.MaterialTheme+import androidx.tv.material3.SelectableSurfaceDefaults+import androidx.tv.material3.Surface+import androidx.tv.material3.Text++/** One top-level destination in the rail. [icon] is an `IconXxx()` from `:library:ui`. */+class TvDestination(val label: String, val icon: @Composable () -> Unit)++/**+ * The TV app shell: a collapsed icon rail on the left that expands over the content with a+ * scrim while it holds focus. Moving focus onto an item selects it (the Google TV pattern),+ * CENTER jumps into the content, and BACK from the content returns to the rail so the next+ * BACK exits instead of the app vanishing mid-browse.+ *+ * @param backReturnsToRail pass `false` when this frame is not the top of the back stack.+ */+@Composable+fun TvAppFrame(+    destinations: List<TvDestination>,+    selected: Int,+    onSelect: (Int) -> Unit,+    modifier: Modifier = Modifier,+    brand: (@Composable () -> Unit)? = null,+    backReturnsToRail: Boolean = true,+    content: @Composable () -> Unit,+) {+    var railFocused by remember { mutableStateOf(false) }+    val requesters = remember(destinations.size) { List(destinations.size) { FocusRequester() } }+    val selectedRequester = requesters.getOrElse(selected) { FocusRequester.Default }+    val focusManager = LocalFocusManager.current+    val railWidth by animateDpAsState(if (railFocused) TvDimens.RailExpanded else TvDimens.RailCollapsed)+    val scrimAlpha by animateFloatAsState(if (railFocused) 1f else 0f)+    val background = MaterialTheme.colorScheme.background++    // Registered before content so screen-level BackHandlers (closing a panel, clearing search) win.+    BackHandler(enabled = backReturnsToRail && !railFocused) {+        runCatching { selectedRequester.requestFocus() }+    }+    Box(modifier.fillMaxSize().background(background)) {+        Box(Modifier.fillMaxSize().padding(start = TvDimens.RailCollapsed)) {+            CompositionLocalProvider(LocalTvContentStart provides TvDimens.InsideFrameStart) {+                content()+            }+        }+        Box(+            Modifier+                .fillMaxHeight()+                .width(TvDimens.RailExpanded + 360.dp)+                .graphicsLayer { alpha = scrimAlpha }+                .background(+                    Brush.horizontalGradient(+                        0f to background,+                        0.45f to background.copy(alpha = 0.92f),+                        1f to Color.Transparent,+                    ),+                ),+        )+        Column(+            Modifier+                .fillMaxHeight()+                .width(railWidth)+                .onFocusChanged { railFocused = it.hasFocus }+                .focusRestorer(selectedRequester)+                .focusGroup()+                .padding(horizontal = 16.dp, vertical = TvDimens.SafeVertical),+            verticalArrangement = Arrangement.spacedBy(6.dp),+        ) {+            Box(Modifier.height(56.dp).fillMaxWidth().clipToBounds(), contentAlignment = Alignment.CenterStart) {+                if (brand != null) {+                    Box(Modifier.wrapContentWidth(Alignment.Start, unbounded = true)) { brand() }+                }+            }+            Spacer(Modifier.weight(1f))+            destinations.forEachIndexed { index, destination ->+                RailItem(+                    destination = destination,+                    selected = index == selected,+                    expanded = railFocused,+                    onFocused = { if (index != selected) onSelect(index) },+                    onClick = {+                        onSelect(index)+                        focusManager.moveFocus(FocusDirection.Right)+                    },+                    modifier = Modifier.focusRequester(requesters[index]),+                )+            }+            Spacer(Modifier.weight(1.4f))+        }+    }+}++@Composable+private fun RailItem(+    destination: TvDestination,+    selected: Boolean,+    expanded: Boolean,+    onFocused: () -> Unit,+    onClick: () -> Unit,+    modifier: Modifier = Modifier,+) {+    val scheme = MaterialTheme.colorScheme+    Surface(+        selected = selected,+        onClick = onClick,+        modifier = modifier+            .fillMaxWidth()+            .height(52.dp)+            .onFocusChanged { if (it.isFocused) onFocused() },+        shape = SelectableSurfaceDefaults.shape(CircleShape),+        scale = SelectableSurfaceDefaults.scale(focusedScale = 1.04f),+        colors = SelectableSurfaceDefaults.colors(+            containerColor = Color.Transparent,+            contentColor = scheme.onSurfaceVariant,+            selectedContainerColor = scheme.primary.copy(alpha = 0.16f),+            selectedContentColor = scheme.primary,+            focusedContainerColor = scheme.inverseSurface,+            focusedContentColor = scheme.inverseOnSurface,+            focusedSelectedContainerColor = scheme.inverseSurface,+            focusedSelectedContentColor = scheme.inverseOnSurface,+        ),+    ) {+        Row(+            Modifier.fillMaxSize().padding(horizontal = 16.dp),+            verticalAlignment = Alignment.CenterVertically,+        ) {+            Box(Modifier.size(24.dp), contentAlignment = Alignment.Center) {+                TvIcon(destination.icon)+            }+            if (expanded) {+                Text(+                    text = destination.label,+                    style = MaterialTheme.typography.titleMedium,+                    maxLines = 1,+                    softWrap = false,+                    overflow = TextOverflow.Clip,+                    modifier = Modifier.padding(start = 16.dp),+                )+            }+        }+    }+}
library/tv/src/main/java/com/vayunmathur/library/tv/TvCards.kt
diff --git a/library/tv/src/main/java/com/vayunmathur/library/tv/TvCards.kt b/library/tv/src/main/java/com/vayunmathur/library/tv/TvCards.ktnew file mode 100644index 0000000000..3196bc37e1--- /dev/null+++ b/library/tv/src/main/java/com/vayunmathur/library/tv/TvCards.kt@@ -0,0 +1,224 @@+package com.vayunmathur.library.tv++import androidx.compose.foundation.BorderStroke+import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.BoxScope+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.aspectRatio+import androidx.compose.foundation.layout.fillMaxHeight+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.width+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.focus.onFocusChanged+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp+import androidx.tv.material3.Border+import androidx.tv.material3.Card+import androidx.tv.material3.CardDefaults+import androidx.tv.material3.ClickableSurfaceDefaults+import androidx.tv.material3.Glow+import androidx.tv.material3.LocalContentColor+import androidx.tv.material3.MaterialTheme+import androidx.tv.material3.StandardCardContainer+import androidx.tv.material3.Surface+import androidx.tv.material3.Text++object TvAspect {+    const val Landscape = 16f / 9f+    const val Poster = 2f / 3f+    const val Square = 1f+}++/**+ * The one card for media and catalog rows: image on top that scales and gets a white ring on+ * focus, title/subtitle underneath (outside the image, so text never sits on artwork).+ *+ * @param image fills the card; use `ContentScale.Crop`. Draw nothing for a tinted placeholder.+ * @param progress 0..1 resume bar along the image bottom, `null` hides it.+ * @param badge short overlay text in the bottom-end corner (duration, "Installed", episode).+ */+@Composable+fun TvMediaCard(+    onClick: () -> Unit,+    image: @Composable BoxScope.() -> Unit,+    modifier: Modifier = Modifier,+    width: Dp = 280.dp,+    aspectRatio: Float = TvAspect.Landscape,+    title: String? = null,+    subtitle: String? = null,+    progress: Float? = null,+    badge: String? = null,+    onLongClick: (() -> Unit)? = null,+    onFocus: (() -> Unit)? = null,+) {+    val scheme = MaterialTheme.colorScheme+    val shape = MaterialTheme.shapes.medium+    StandardCardContainer(+        modifier = modifier.width(width).onFocusChanged { if (it.hasFocus) onFocus?.invoke() },+        imageCard = { interactionSource ->+            Card(+                onClick = onClick,+                onLongClick = onLongClick,+                interactionSource = interactionSource,+                shape = CardDefaults.shape(shape),+                scale = CardDefaults.scale(focusedScale = 1.06f),+                colors = CardDefaults.colors(containerColor = scheme.surfaceVariant),+                border = CardDefaults.border(+                    focusedBorder = Border(BorderStroke(3.dp, scheme.inverseSurface), shape = shape),+                ),+                glow = CardDefaults.glow(focusedGlow = Glow(scheme.primary.copy(alpha = 0.45f), 20.dp)),+            ) {+                Box(Modifier.fillMaxWidth().aspectRatio(aspectRatio)) {+                    image()+                    if (badge != null) {+                        TvBadge(+                            text = badge,+                            modifier = Modifier.align(Alignment.BottomEnd).padding(8.dp),+                            container = Color.Black.copy(alpha = 0.72f),+                            content = Color.White,+                        )+                    }+                    if (progress != null && progress > 0f) {+                        TvProgressStrip(progress, Modifier.align(Alignment.BottomCenter))+                    }+                }+            }+        },+        title = {+            if (title != null) {+                Text(+                    text = title,+                    style = MaterialTheme.typography.titleSmall,+                    maxLines = 2,+                    overflow = TextOverflow.Ellipsis,+                    modifier = Modifier.padding(top = 10.dp),+                )+            }+        },+        subtitle = {+            if (subtitle != null) {+                Text(+                    text = subtitle,+                    style = MaterialTheme.typography.bodySmall,+                    color = scheme.onSurfaceVariant,+                    maxLines = 1,+                    overflow = TextOverflow.Ellipsis,+                    modifier = Modifier.padding(top = 2.dp),+                )+            }+        },+    )+}++/**+ * A horizontal tile: leading art, two lines of text, optional trailing slot. For app listings,+ * channels, playlists, downloads - anything that reads better as a row than as artwork.+ */+@Composable+fun TvRowCard(+    title: String,+    onClick: () -> Unit,+    modifier: Modifier = Modifier,+    width: Dp = 380.dp,+    subtitle: String? = null,+    supporting: String? = null,+    leading: (@Composable BoxScope.() -> Unit)? = null,+    leadingSize: Dp = 72.dp,+    trailing: (@Composable () -> Unit)? = null,+    onLongClick: (() -> Unit)? = null,+    onFocus: (() -> Unit)? = null,+) {+    val scheme = MaterialTheme.colorScheme+    Surface(+        onClick = onClick,+        onLongClick = onLongClick,+        modifier = modifier.width(width).onFocusChanged { if (it.hasFocus) onFocus?.invoke() },+        shape = ClickableSurfaceDefaults.shape(MaterialTheme.shapes.medium),+        scale = ClickableSurfaceDefaults.scale(focusedScale = 1.04f),+        colors = ClickableSurfaceDefaults.colors(+            containerColor = scheme.surface,+            contentColor = scheme.onSurface,+            focusedContainerColor = scheme.inverseSurface,+            focusedContentColor = scheme.inverseOnSurface,+        ),+    ) {+        Row(Modifier.padding(14.dp), verticalAlignment = Alignment.CenterVertically) {+            if (leading != null) {+                Box(+                    Modifier.size(leadingSize).background(scheme.surfaceVariant, MaterialTheme.shapes.small),+                    contentAlignment = Alignment.Center,+                    content = leading,+                )+            }+            Column(+                Modifier.weight(1f).padding(start = if (leading != null) 16.dp else 4.dp),+                verticalArrangement = Arrangement.spacedBy(2.dp),+            ) {+                Text(title, style = MaterialTheme.typography.titleMedium, maxLines = 1, overflow = TextOverflow.Ellipsis)+                if (subtitle != null) {+                    Text(+                        subtitle,+                        style = MaterialTheme.typography.bodyMedium,+                        color = LocalContentColor.current.copy(alpha = 0.78f),+                        maxLines = 1,+                        overflow = TextOverflow.Ellipsis,+                    )+                }+                if (supporting != null) {+                    Text(+                        supporting,+                        style = MaterialTheme.typography.bodySmall,+                        color = LocalContentColor.current.copy(alpha = 0.62f),+                        maxLines = 1,+                        overflow = TextOverflow.Ellipsis,+                    )+                }+            }+            if (trailing != null) {+                Box(Modifier.padding(start = 12.dp)) { TvIcon(trailing) }+            }+        }+    }+}++/** A thin accent progress bar, used along image bottoms and in download rows. */+@Composable+fun TvProgressStrip(progress: Float, modifier: Modifier = Modifier, height: Dp = 4.dp) {+    Box(modifier.fillMaxWidth().height(height).background(Color.White.copy(alpha = 0.25f))) {+        Box(+            Modifier+                .fillMaxHeight()+                .fillMaxWidth(progress.coerceIn(0f, 1f))+                .background(MaterialTheme.colorScheme.primary),+        )+    }+}++/** Small pill label. Defaults to the accent container; pass colours for overlays/warnings. */+@Composable+fun TvBadge(+    text: String,+    modifier: Modifier = Modifier,+    container: Color = MaterialTheme.colorScheme.primaryContainer,+    content: Color = MaterialTheme.colorScheme.onPrimaryContainer,+) {+    Text(+        text = text,+        style = MaterialTheme.typography.labelMedium,+        color = content,+        maxLines = 1,+        modifier = modifier+            .background(container, MaterialTheme.shapes.extraSmall)+            .padding(horizontal = 8.dp, vertical = 3.dp),+    )+}
library/tv/src/main/java/com/vayunmathur/library/tv/TvControls.kt
diff --git a/library/tv/src/main/java/com/vayunmathur/library/tv/TvControls.kt b/library/tv/src/main/java/com/vayunmathur/library/tv/TvControls.ktnew file mode 100644index 0000000000..56941ea216--- /dev/null+++ b/library/tv/src/main/java/com/vayunmathur/library/tv/TvControls.kt@@ -0,0 +1,193 @@+package com.vayunmathur.library.tv++import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.width+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp+import androidx.tv.material3.Button+import androidx.tv.material3.ButtonDefaults+import androidx.tv.material3.ExperimentalTvMaterial3Api+import androidx.tv.material3.FilterChip+import androidx.tv.material3.FilterChipDefaults+import androidx.tv.material3.IconButton+import androidx.tv.material3.IconButtonDefaults+import androidx.tv.material3.ListItem+import androidx.tv.material3.ListItemDefaults+import androidx.tv.material3.MaterialTheme+import androidx.tv.material3.Switch+import androidx.tv.material3.SwitchDefaults+import androidx.tv.material3.Text++/**+ * The action button. [primary] fills with the app accent (one per screen: Play, Install);+ * secondary actions sit on a neutral tonal fill. Both go white on focus.+ */+@Composable+fun TvButton(+    text: String,+    onClick: () -> Unit,+    modifier: Modifier = Modifier,+    icon: (@Composable () -> Unit)? = null,+    primary: Boolean = false,+    enabled: Boolean = true,+) {+    val scheme = MaterialTheme.colorScheme+    Button(+        onClick = onClick,+        modifier = modifier,+        enabled = enabled,+        colors = ButtonDefaults.colors(+            containerColor = if (primary) scheme.primary else scheme.surfaceVariant,+            contentColor = if (primary) scheme.onPrimary else scheme.onSurface,+            focusedContainerColor = scheme.inverseSurface,+            focusedContentColor = scheme.inverseOnSurface,+            disabledContainerColor = scheme.surfaceVariant.copy(alpha = 0.5f),+            disabledContentColor = scheme.onSurfaceVariant.copy(alpha = 0.6f),+        ),+    ) {+        if (icon != null) {+            Box(Modifier.size(ButtonDefaults.IconSize), contentAlignment = Alignment.Center) { TvIcon(icon) }+            Spacer(Modifier.width(ButtonDefaults.IconSpacing))+        }+        Text(text, style = MaterialTheme.typography.titleSmall, maxLines = 1, overflow = TextOverflow.Ellipsis)+    }+}++/** Round icon-only button for transport controls and compact toolbars. */+@Composable+fun TvIconButton(+    onClick: () -> Unit,+    icon: @Composable () -> Unit,+    modifier: Modifier = Modifier,+    size: Dp = 52.dp,+    enabled: Boolean = true,+) {+    val scheme = MaterialTheme.colorScheme+    IconButton(+        onClick = onClick,+        modifier = modifier.size(size),+        enabled = enabled,+        colors = IconButtonDefaults.colors(+            containerColor = scheme.surfaceVariant.copy(alpha = 0.7f),+            contentColor = scheme.onSurface,+            focusedContainerColor = scheme.inverseSurface,+            focusedContentColor = scheme.inverseOnSurface,+        ),+    ) {+        TvIcon(icon)+    }+}++/** Filter/selection chip (categories, sources, seasons). */+@OptIn(ExperimentalTvMaterial3Api::class)+@Composable+fun TvChip(+    label: String,+    selected: Boolean,+    onClick: () -> Unit,+    modifier: Modifier = Modifier,+    icon: (@Composable () -> Unit)? = null,+) {+    val scheme = MaterialTheme.colorScheme+    FilterChip(+        selected = selected,+        onClick = onClick,+        modifier = modifier,+        leadingIcon = icon?.let { { TvIcon(it) } },+        colors = FilterChipDefaults.colors(+            containerColor = scheme.surfaceVariant.copy(alpha = 0.6f),+            contentColor = scheme.onSurface,+            selectedContainerColor = scheme.primary,+            selectedContentColor = scheme.onPrimary,+            focusedContainerColor = scheme.inverseSurface,+            focusedContentColor = scheme.inverseOnSurface,+            focusedSelectedContainerColor = scheme.inverseSurface,+            focusedSelectedContentColor = scheme.inverseOnSurface,+        ),+    ) {+        Text(label, maxLines = 1)+    }+}++/** A full-width list/settings row. Leading/trailing slots get the icon colour bridge. */+@Composable+fun TvListRow(+    headline: String,+    onClick: () -> Unit,+    modifier: Modifier = Modifier,+    supporting: String? = null,+    overline: String? = null,+    leading: (@Composable () -> Unit)? = null,+    trailing: (@Composable () -> Unit)? = null,+    selected: Boolean = false,+    enabled: Boolean = true,+    onLongClick: (() -> Unit)? = null,+) {+    val scheme = MaterialTheme.colorScheme+    ListItem(+        selected = selected,+        onClick = onClick,+        onLongClick = onLongClick,+        enabled = enabled,+        modifier = modifier.fillMaxWidth(),+        headlineContent = {+            Text(headline, style = MaterialTheme.typography.titleMedium, maxLines = 2, overflow = TextOverflow.Ellipsis)+        },+        overlineContent = overline?.let { { Text(it, maxLines = 1) } },+        supportingContent = supporting?.let {+            { Text(it, style = MaterialTheme.typography.bodyMedium, maxLines = 3, overflow = TextOverflow.Ellipsis) }+        },+        leadingContent = leading?.let { slot -> { TvIcon(slot) } },+        trailingContent = trailing?.let { slot -> { TvIcon(slot) } },+        scale = ListItemDefaults.scale(focusedScale = 1.02f),+        colors = ListItemDefaults.colors(+            containerColor = scheme.surface.copy(alpha = 0.6f),+            contentColor = scheme.onSurface,+            selectedContainerColor = scheme.primary.copy(alpha = 0.18f),+            selectedContentColor = scheme.onSurface,+            focusedContainerColor = scheme.inverseSurface,+            focusedContentColor = scheme.inverseOnSurface,+            focusedSelectedContainerColor = scheme.inverseSurface,+            focusedSelectedContentColor = scheme.inverseOnSurface,+        ),+    )+}++/** A list row whose whole surface toggles, so the D-pad never has to land on a switch thumb. */+@Composable+fun TvSwitchRow(+    headline: String,+    checked: Boolean,+    onCheckedChange: (Boolean) -> Unit,+    modifier: Modifier = Modifier,+    supporting: String? = null,+    leading: (@Composable () -> Unit)? = null,+    enabled: Boolean = true,+) {+    val scheme = MaterialTheme.colorScheme+    TvListRow(+        headline = headline,+        onClick = { onCheckedChange(!checked) },+        modifier = modifier,+        supporting = supporting,+        leading = leading,+        enabled = enabled,+        trailing = {+            Switch(+                checked = checked,+                onCheckedChange = null,+                colors = SwitchDefaults.colors(+                    checkedThumbColor = scheme.onPrimary,+                    checkedTrackColor = scheme.primary,+                ),+            )+        },+    )+}
library/tv/src/main/java/com/vayunmathur/library/tv/TvHero.kt
diff --git a/library/tv/src/main/java/com/vayunmathur/library/tv/TvHero.kt b/library/tv/src/main/java/com/vayunmathur/library/tv/TvHero.ktnew file mode 100644index 0000000000..c617842d90--- /dev/null+++ b/library/tv/src/main/java/com/vayunmathur/library/tv/TvHero.kt@@ -0,0 +1,138 @@+package com.vayunmathur.library.tv++import androidx.compose.animation.Crossfade+import androidx.compose.animation.core.tween+import androidx.compose.foundation.background+import androidx.compose.foundation.horizontalScroll+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.BoxScope+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.RowScope+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Brush+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.dp+import androidx.tv.material3.MaterialTheme+import androidx.tv.material3.Text++/**+ * Full-bleed artwork behind a screen, cross-fading when [key] changes (e.g. the focused card),+ * with scrims that fade it into the background on the start edge and bottom so text over it+ * stays legible. [image] draws for a given key; draw nothing to show only the background.+ */+@Composable+fun <K> TvBackdrop(+    key: K,+    modifier: Modifier = Modifier,+    image: @Composable BoxScope.(K) -> Unit,+) {+    val background = MaterialTheme.colorScheme.background+    Box(modifier.fillMaxSize()) {+        Crossfade(targetState = key, animationSpec = tween(BACKDROP_FADE_MS), label = "tv-backdrop") { k ->+            Box(Modifier.fillMaxSize()) { image(k) }+        }+        Box(+            Modifier.fillMaxSize().background(+                Brush.horizontalGradient(+                    0f to background,+                    0.35f to background.copy(alpha = 0.85f),+                    0.7f to Color.Transparent,+                ),+            ),+        )+        Box(+            Modifier.fillMaxSize().background(+                Brush.verticalGradient(+                    0f to Color.Transparent,+                    0.55f to background.copy(alpha = 0.35f),+                    1f to background,+                ),+            ),+        )+    }+}++/**+ * Hero text block for a featured item or a detail page: eyebrow, big title, a meta line,+ * a few lines of description and an action row. The text is sized to the left ~half of the+ * screen so the backdrop art stays visible; the action row spans the full width and scrolls.+ */+@Composable+fun TvHeroText(+    title: String,+    modifier: Modifier = Modifier,+    eyebrow: String? = null,+    meta: List<String> = emptyList(),+    description: String? = null,+    descriptionLines: Int = 3,+    chips: (@Composable RowScope.() -> Unit)? = null,+    actions: (@Composable RowScope.() -> Unit)? = null,+) {+    val scheme = MaterialTheme.colorScheme+    Column(modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(10.dp)) {+        Column(Modifier.fillMaxWidth(0.52f), verticalArrangement = Arrangement.spacedBy(10.dp)) {+            if (eyebrow != null) {+                Text(+                    text = eyebrow.uppercase(),+                    style = MaterialTheme.typography.labelLarge,+                    color = scheme.primary,+                    maxLines = 1,+                )+            }+            Text(+                text = title,+                style = MaterialTheme.typography.displaySmall,+                color = scheme.onSurface,+                maxLines = 2,+                overflow = TextOverflow.Ellipsis,+            )+            if (meta.isNotEmpty()) {+                Text(+                    text = meta.filter { it.isNotBlank() }.joinToString("  •  "),+                    style = MaterialTheme.typography.titleSmall,+                    color = scheme.onSurfaceVariant,+                    maxLines = 1,+                    overflow = TextOverflow.Ellipsis,+                )+            }+            if (chips != null) {+                Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) {+                    chips()+                }+            }+            if (!description.isNullOrBlank()) {+                Text(+                    text = description,+                    style = MaterialTheme.typography.bodyLarge,+                    color = scheme.onSurface.copy(alpha = 0.85f),+                    maxLines = descriptionLines,+                    overflow = TextOverflow.Ellipsis,+                )+            }+        }+        if (actions != null) {+            // Full width and scrollable, not confined to the text column: detail pages carry many+            // actions and a squeezed button is one the D-pad can't reach.+            Row(+                horizontalArrangement = Arrangement.spacedBy(12.dp),+                verticalAlignment = Alignment.CenterVertically,+                modifier = Modifier+                    .fillMaxWidth()+                    .horizontalScroll(rememberScrollState())+                    .padding(top = 6.dp, bottom = 6.dp, end = TvDimens.SafeHorizontal),+                content = actions,+            )+        }+    }+}++private const val BACKDROP_FADE_MS = 450
library/tv/src/main/java/com/vayunmathur/library/tv/TvInput.kt
diff --git a/library/tv/src/main/java/com/vayunmathur/library/tv/TvInput.kt b/library/tv/src/main/java/com/vayunmathur/library/tv/TvInput.ktnew file mode 100644index 0000000000..704b465500--- /dev/null+++ b/library/tv/src/main/java/com/vayunmathur/library/tv/TvInput.kt@@ -0,0 +1,149 @@+package com.vayunmathur.library.tv++import androidx.activity.compose.BackHandler+import androidx.compose.foundation.BorderStroke+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.widthIn+import androidx.compose.foundation.shape.CircleShape+import androidx.compose.foundation.text.BasicTextField+import androidx.compose.foundation.text.KeyboardActions+import androidx.compose.foundation.text.KeyboardOptions+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.focus.FocusRequester+import androidx.compose.ui.focus.focusProperties+import androidx.compose.ui.focus.focusRequester+import androidx.compose.ui.focus.onFocusChanged+import androidx.compose.ui.graphics.SolidColor+import androidx.compose.ui.text.input.ImeAction+import androidx.compose.ui.text.input.KeyboardType+import androidx.compose.ui.unit.dp+import androidx.compose.ui.window.Dialog+import androidx.tv.material3.Border+import androidx.tv.material3.ClickableSurfaceDefaults+import androidx.tv.material3.LocalContentColor+import androidx.tv.material3.MaterialTheme+import androidx.tv.material3.Surface+import androidx.tv.material3.SurfaceDefaults+import androidx.tv.material3.Text++/**+ * A D-pad text field. Focus lands on the pill without opening the keyboard; CENTER starts+ * editing and raises the IME; IME action or BACK ends editing and returns focus to the pill.+ * So the on-screen keyboard only ever appears on an explicit press.+ *+ * @param focusRequester targets the pill (not the inner field), for initial focus.+ * @param startEditing open the keyboard as soon as the field is first composed.+ */+@Composable+fun TvTextField(+    value: String,+    onValueChange: (String) -> Unit,+    placeholder: String,+    modifier: Modifier = Modifier,+    leading: (@Composable () -> Unit)? = null,+    onSubmit: () -> Unit = {},+    imeAction: ImeAction = ImeAction.Done,+    keyboardType: KeyboardType = KeyboardType.Text,+    focusRequester: FocusRequester = remember { FocusRequester() },+    startEditing: Boolean = false,+) {+    var editing by remember { mutableStateOf(startEditing) }+    val fieldFocus = remember { FocusRequester() }+    val scheme = MaterialTheme.colorScheme+    fun finish() {+        editing = false+        runCatching { focusRequester.requestFocus() }+    }+    LaunchedEffect(editing) { if (editing) runCatching { fieldFocus.requestFocus() } }+    BackHandler(enabled = editing) { finish() }+    Surface(+        onClick = { editing = true },+        modifier = modifier.focusRequester(focusRequester),+        shape = ClickableSurfaceDefaults.shape(CircleShape),+        scale = ClickableSurfaceDefaults.scale(focusedScale = 1.02f),+        colors = ClickableSurfaceDefaults.colors(+            containerColor = scheme.surfaceVariant,+            contentColor = scheme.onSurface,+            focusedContainerColor = scheme.inverseSurface,+            focusedContentColor = scheme.inverseOnSurface,+        ),+        border = ClickableSurfaceDefaults.border(+            border = if (editing) Border(BorderStroke(2.dp, scheme.primary), shape = CircleShape) else Border.None,+        ),+    ) {+        Row(+            Modifier.padding(horizontal = 24.dp, vertical = 14.dp),+            verticalAlignment = Alignment.CenterVertically,+        ) {+            if (leading != null) {+                Box(Modifier.size(24.dp), contentAlignment = Alignment.Center) { TvIcon(leading) }+            }+            Box(Modifier.weight(1f).padding(start = if (leading != null) 16.dp else 0.dp)) {+                if (value.isEmpty()) {+                    Text(placeholder, style = MaterialTheme.typography.titleMedium, color = LocalContentColor.current.copy(alpha = 0.6f))+                }+                BasicTextField(+                    value = value,+                    onValueChange = onValueChange,+                    singleLine = true,+                    textStyle = MaterialTheme.typography.titleMedium.copy(color = LocalContentColor.current),+                    cursorBrush = SolidColor(scheme.primary),+                    keyboardOptions = KeyboardOptions(imeAction = imeAction, keyboardType = keyboardType),+                    keyboardActions = KeyboardActions(onAny = {+                        onSubmit()+                        finish()+                    }),+                    modifier = Modifier+                        .fillMaxWidth()+                        .focusRequester(fieldFocus)+                        .focusProperties { canFocus = editing }+                        .onFocusChanged { if (!it.isFocused && editing) editing = false },+                )+            }+        }+    }+}++/** A centered modal panel: title, body slot, and a row of [TvButton]s. */+@Composable+fun TvDialog(+    title: String,+    onDismissRequest: () -> Unit,+    modifier: Modifier = Modifier,+    body: String? = null,+    content: (@Composable () -> Unit)? = null,+    buttons: @Composable () -> Unit,+) {+    Dialog(onDismissRequest = onDismissRequest) {+        Surface(+            modifier = modifier.widthIn(min = 420.dp, max = 640.dp),+            shape = MaterialTheme.shapes.large,+            colors = SurfaceDefaults.colors(containerColor = MaterialTheme.colorScheme.surface),+        ) {+            Column(Modifier.padding(32.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {+                Text(title, style = MaterialTheme.typography.headlineSmall, color = MaterialTheme.colorScheme.onSurface)+                if (body != null) {+                    Text(body, style = MaterialTheme.typography.bodyLarge, color = MaterialTheme.colorScheme.onSurfaceVariant)+                }+                content?.invoke()+                Row(+                    Modifier.fillMaxWidth().padding(top = 8.dp),+                    horizontalArrangement = Arrangement.spacedBy(12.dp, Alignment.End),+                ) { buttons() }+            }+        }+    }+}
library/tv/src/main/java/com/vayunmathur/library/tv/TvLayout.kt
diff --git a/library/tv/src/main/java/com/vayunmathur/library/tv/TvLayout.kt b/library/tv/src/main/java/com/vayunmathur/library/tv/TvLayout.ktnew file mode 100644index 0000000000..72d455092d--- /dev/null+++ b/library/tv/src/main/java/com/vayunmathur/library/tv/TvLayout.kt@@ -0,0 +1,135 @@+package com.vayunmathur.library.tv++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.PaddingValues+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.RowScope+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.lazy.LazyListScope+import androidx.compose.foundation.lazy.LazyListState+import androidx.compose.foundation.lazy.LazyRow+import androidx.compose.foundation.lazy.rememberLazyListState+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.focus.focusRestorer+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp+import androidx.tv.material3.MaterialTheme+import androidx.tv.material3.Text++/** Start inset for content on the current screen (smaller inside [TvAppFrame]). */+@Composable+fun tvContentStart(): Dp = LocalTvContentStart.current++/**+ * Padding for a screen-level lazy list or grid: aligned with [TvScreenHeader] on the start,+ * overscan-safe on the end, and room at the bottom so a scaled-up focused card is not clipped.+ */+@Composable+fun tvContentPadding(top: Dp = 0.dp, bottom: Dp = TvDimens.SafeVertical + 16.dp): PaddingValues =+    PaddingValues(start = tvContentStart(), end = TvDimens.SafeHorizontal, top = top, bottom = bottom)++/**+ * Screen title row. Large type, no app bar: on a TV the content is the chrome. [actions] sit at+ * the end of the row (buttons, chips) and are reachable with UP from the content.+ */+@Composable+fun TvScreenHeader(+    title: String,+    modifier: Modifier = Modifier,+    subtitle: String? = null,+    actions: (@Composable RowScope.() -> Unit)? = null,+) {+    Row(+        modifier+            .fillMaxWidth()+            .padding(start = tvContentStart(), end = TvDimens.SafeHorizontal, top = TvDimens.SafeVertical, bottom = 16.dp),+        verticalAlignment = Alignment.CenterVertically,+    ) {+        Column(Modifier.weight(1f)) {+            Text(+                text = title,+                style = MaterialTheme.typography.headlineLarge,+                color = MaterialTheme.colorScheme.onSurface,+                maxLines = 1,+                overflow = TextOverflow.Ellipsis,+            )+            if (subtitle != null) {+                Text(+                    text = subtitle,+                    style = MaterialTheme.typography.bodyLarge,+                    color = MaterialTheme.colorScheme.onSurfaceVariant,+                    maxLines = 2,+                    overflow = TextOverflow.Ellipsis,+                    modifier = Modifier.padding(top = 4.dp),+                )+            }+        }+        if (actions != null) {+            Spacer(Modifier.padding(start = 24.dp))+            Row(horizontalArrangement = Arrangement.spacedBy(12.dp), verticalAlignment = Alignment.CenterVertically) {+                actions()+            }+        }+    }+}++/** A section label aligned with the screen's content start. */+@Composable+fun TvSectionTitle(text: String, modifier: Modifier = Modifier, trailing: String? = null) {+    Row(+        modifier.fillMaxWidth().padding(start = tvContentStart(), end = TvDimens.SafeHorizontal),+        verticalAlignment = Alignment.Bottom,+    ) {+        Text(+            text = text,+            style = MaterialTheme.typography.titleLarge,+            color = MaterialTheme.colorScheme.onSurface,+            modifier = Modifier.weight(1f, fill = false),+            maxLines = 1,+            overflow = TextOverflow.Ellipsis,+        )+        if (trailing != null) {+            Text(+                text = trailing,+                style = MaterialTheme.typography.bodyMedium,+                color = MaterialTheme.colorScheme.onSurfaceVariant,+                modifier = Modifier.padding(start = 12.dp),+            )+        }+    }+}++/**+ * A titled horizontal row of cards. Entering the row restores focus to the card last focused+ * in it, so UP/DOWN through a stack of shelves keeps each shelf's position.+ */+@Composable+fun TvShelf(+    title: String?,+    modifier: Modifier = Modifier,+    trailing: String? = null,+    state: LazyListState = rememberLazyListState(),+    content: LazyListScope.() -> Unit,+) {+    Column(modifier.fillMaxWidth()) {+        if (title != null) TvSectionTitle(title, trailing = trailing)+        LazyRow(+            state = state,+            modifier = Modifier.fillMaxWidth().focusRestorer(),+            contentPadding = PaddingValues(+                start = tvContentStart(),+                end = TvDimens.SafeHorizontal,+                top = 14.dp,+                bottom = 14.dp,+            ),+            horizontalArrangement = Arrangement.spacedBy(TvDimens.ItemGap),+            content = content,+        )+    }+}
library/tv/src/main/java/com/vayunmathur/library/tv/TvStates.kt
diff --git a/library/tv/src/main/java/com/vayunmathur/library/tv/TvStates.kt b/library/tv/src/main/java/com/vayunmathur/library/tv/TvStates.ktnew file mode 100644index 0000000000..d35f602001--- /dev/null+++ b/library/tv/src/main/java/com/vayunmathur/library/tv/TvStates.kt@@ -0,0 +1,105 @@+package com.vayunmathur.library.tv++import androidx.compose.foundation.focusable+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.widthIn+import androidx.compose.material3.CircularProgressIndicator+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.focus.FocusRequester+import androidx.compose.ui.text.style.TextAlign+import androidx.compose.ui.unit.dp+import androidx.tv.material3.MaterialTheme+import androidx.tv.material3.Text+import kotlinx.coroutines.delay++/**+ * Request focus once composed, so the D-pad always has somewhere to start. Re-runs when [key]+ * changes (e.g. content arriving after a load).+ */+@Composable+fun TvInitialFocus(requester: FocusRequester, key: Any? = Unit) {+    LaunchedEffect(requester, key) {+        // One frame late: requesting during the first layout races the focus system and drops.+        delay(FRAME_MS)+        runCatching { requester.requestFocus() }+    }+}++/** Centered empty/error state. [action] is usually one [TvButton] so the D-pad has a target. */+@Composable+fun TvEmptyState(+    title: String,+    modifier: Modifier = Modifier,+    body: String? = null,+    icon: (@Composable () -> Unit)? = null,+    isError: Boolean = false,+    action: (@Composable () -> Unit)? = null,+) {+    Box(modifier.fillMaxSize().padding(TvDimens.SafeHorizontal), contentAlignment = Alignment.Center) {+        Column(+            Modifier.widthIn(max = 640.dp),+            horizontalAlignment = Alignment.CenterHorizontally,+            verticalArrangement = Arrangement.spacedBy(12.dp),+        ) {+            if (icon != null) {+                Box(Modifier.size(56.dp), contentAlignment = Alignment.Center) {+                    TvIcon(icon)+                }+            }+            Text(+                text = title,+                style = MaterialTheme.typography.headlineSmall,+                color = if (isError) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.onSurface,+                textAlign = TextAlign.Center,+            )+            if (body != null) {+                Text(+                    text = body,+                    style = MaterialTheme.typography.bodyLarge,+                    color = MaterialTheme.colorScheme.onSurfaceVariant,+                    textAlign = TextAlign.Center,+                )+            }+            if (action != null) {+                Box(Modifier.padding(top = 12.dp)) { action() }+            }+        }+    }+}++/**+ * Centered spinner. Focusable so the D-pad is not left dead while content loads; pass a+ * [focusRequester] via [modifier] if the screen should start here.+ */+@Composable+fun TvLoading(modifier: Modifier = Modifier, label: String? = null) {+    Box(modifier.fillMaxSize().focusable(), contentAlignment = Alignment.Center) {+        Column(+            horizontalAlignment = Alignment.CenterHorizontally,+            verticalArrangement = Arrangement.spacedBy(16.dp),+        ) {+            CircularProgressIndicator(+                color = MaterialTheme.colorScheme.primary,+                trackColor = MaterialTheme.colorScheme.surfaceVariant,+                modifier = Modifier.size(48.dp),+            )+            if (label != null) {+                Text(+                    text = label,+                    style = MaterialTheme.typography.titleMedium,+                    color = MaterialTheme.colorScheme.onSurfaceVariant,+                )+            }+        }+    }+}++private const val FRAME_MS = 16L
library/tv/src/main/java/com/vayunmathur/library/tv/TvTheme.kt
diff --git a/library/tv/src/main/java/com/vayunmathur/library/tv/TvTheme.kt b/library/tv/src/main/java/com/vayunmathur/library/tv/TvTheme.ktnew file mode 100644index 0000000000..4947a216a1--- /dev/null+++ b/library/tv/src/main/java/com/vayunmathur/library/tv/TvTheme.kt@@ -0,0 +1,99 @@+package com.vayunmathur.library.tv++import androidx.compose.runtime.Composable+import androidx.compose.runtime.CompositionLocalProvider+import androidx.compose.runtime.compositionLocalOf+import androidx.compose.runtime.remember+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.lerp+import androidx.compose.ui.graphics.luminance+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp+import androidx.tv.material3.ColorScheme+import androidx.tv.material3.LocalContentColor+import androidx.tv.material3.MaterialTheme+import androidx.tv.material3.darkColorScheme+import androidx.compose.material3.LocalContentColor as M3LocalContentColor++/** One accent per app, so each TV app is recognisable at a glance from across the room. */+object TvAccent {+    val Red = Color(0xFFFF5B52)+    val Teal = Color(0xFF41D6A8)+    val Amber = Color(0xFFFFB84D)+    val Blue = Color(0xFF7DB4FF)+}++/** Ten-foot spacing. Horizontal/vertical safe values keep content inside TV overscan. */+object TvDimens {+    val SafeHorizontal: Dp = 48.dp+    val SafeVertical: Dp = 28.dp+    val RailCollapsed: Dp = 88.dp+    val RailExpanded: Dp = 264.dp+    val ItemGap: Dp = 20.dp+    val ShelfGap: Dp = 32.dp+    val InsideFrameStart: Dp = 24.dp+}++/** Start inset for screen content: smaller inside [TvAppFrame] because the rail already insets it. */+internal val LocalTvContentStart = compositionLocalOf { TvDimens.SafeHorizontal }++/**+ * Always-dark TV theme keyed off one accent. Focused surfaces flip to near-white with dark+ * content (the Google TV convention), so focus is legible on any backdrop.+ */+@Composable+fun MaTvTheme(accent: Color, content: @Composable () -> Unit) {+    val scheme = remember(accent) { tvColorScheme(accent) }+    MaterialTheme(colorScheme = scheme) {+        CompositionLocalProvider(+            LocalContentColor provides scheme.onSurface,+            M3LocalContentColor provides scheme.onSurface,+            content = content,+        )+    }+}++/**+ * Bridges tv-material's content colour into Material 3's, which `:library:ui` icons read.+ * Without this an `IconXxx()` inside a focused tv surface keeps the unfocused colour.+ */+@Composable+fun TvIcon(content: @Composable () -> Unit) {+    CompositionLocalProvider(M3LocalContentColor provides LocalContentColor.current, content = content)+}++private val Background = Color(0xFF0B0C10)+private val Surface = Color(0xFF16181D)+private val SurfaceVariant = Color(0xFF23262D)+private val OnSurface = Color(0xFFECEDF0)+private val OnSurfaceVariant = Color(0xFFA6AAB3)++private fun tvColorScheme(accent: Color): ColorScheme {+    val onAccent = if (accent.luminance() > 0.4f) Background else Color.White+    return darkColorScheme(+        primary = accent,+        onPrimary = onAccent,+        primaryContainer = lerp(accent, Background, 0.7f),+        onPrimaryContainer = lerp(accent, Color.White, 0.6f),+        secondary = lerp(accent, Color.White, 0.35f),+        onSecondary = Background,+        secondaryContainer = lerp(accent, SurfaceVariant, 0.8f),+        onSecondaryContainer = OnSurface,+        tertiary = lerp(accent, Color.White, 0.5f),+        background = Background,+        onBackground = OnSurface,+        surface = Surface,+        onSurface = OnSurface,+        surfaceVariant = SurfaceVariant,+        onSurfaceVariant = OnSurfaceVariant,+        inverseSurface = OnSurface,+        inverseOnSurface = Background,+        border = lerp(accent, Color.White, 0.25f),+        borderVariant = SurfaceVariant,+        error = Color(0xFFFF8A80),+        onError = Background,+        errorContainer = Color(0xFF5C1F1B),+        onErrorContainer = Color(0xFFFFDAD6),+        scrim = Color.Black,+    )+}
library/tv/src/main/java/com/vayunmathur/library/tv/TvTransport.kt
diff --git a/library/tv/src/main/java/com/vayunmathur/library/tv/TvTransport.kt b/library/tv/src/main/java/com/vayunmathur/library/tv/TvTransport.ktnew file mode 100644index 0000000000..553ef2504e--- /dev/null+++ b/library/tv/src/main/java/com/vayunmathur/library/tv/TvTransport.kt@@ -0,0 +1,82 @@+package com.vayunmathur.library.tv++import androidx.compose.animation.core.animateDpAsState+import androidx.compose.foundation.Canvas+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.geometry.CornerRadius+import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.geometry.Size+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.unit.dp+import androidx.tv.material3.MaterialTheme+import androidx.tv.material3.Text++/**+ * Player seek bar. Draw-only - the caller owns LEFT/RIGHT scrubbing - but it thickens and+ * shows a thumb while [active] (focused or scrubbing), the visual cue that the arrows seek.+ *+ * @param markers chapter/segment boundaries as 0..1 fractions, drawn as gaps in the track.+ */+@Composable+fun TvSeekBar(+    progress: Float,+    modifier: Modifier = Modifier,+    buffered: Float = 0f,+    active: Boolean = false,+    markers: List<Float> = emptyList(),+) {+    val track by animateDpAsState(if (active) 8.dp else 4.dp, label = "tv-seek-track")+    val primary = MaterialTheme.colorScheme.primary+    val thumbColor = MaterialTheme.colorScheme.inverseSurface+    val gapColor = Color.Black.copy(alpha = 0.6f)+    Canvas(modifier.fillMaxWidth().height(24.dp)) {+        val h = track.toPx()+        val top = (size.height - h) / 2+        val radius = CornerRadius(h / 2, h / 2)+        drawRoundRect(Color.White.copy(alpha = 0.22f), Offset(0f, top), Size(size.width, h), radius)+        drawRoundRect(+            Color.White.copy(alpha = 0.38f),+            Offset(0f, top),+            Size(size.width * buffered.coerceIn(0f, 1f), h),+            radius,+        )+        val x = size.width * progress.coerceIn(0f, 1f)+        drawRoundRect(primary, Offset(0f, top), Size(x, h), radius)+        markers.forEach { m ->+            val mx = size.width * m.coerceIn(0f, 1f)+            drawRect(gapColor, Offset(mx - 1.5f, top), Size(3f, h))+        }+        if (active) drawCircle(thumbColor, radius = h * 1.1f, center = Offset(x, size.height / 2))+    }+}++/** Elapsed / total labels either side of a [TvSeekBar]. */+@Composable+fun TvSeekRow(+    elapsed: String,+    total: String,+    progress: Float,+    modifier: Modifier = Modifier,+    buffered: Float = 0f,+    active: Boolean = false,+    markers: List<Float> = emptyList(),+) {+    Row(modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {+        Text(elapsed, style = MaterialTheme.typography.titleSmall, color = MaterialTheme.colorScheme.onSurface)+        TvSeekBar(+            progress = progress,+            buffered = buffered,+            active = active,+            markers = markers,+            modifier = Modifier.weight(1f).padding(horizontal = 16.dp),+        )+        Text(total, style = MaterialTheme.typography.titleSmall, color = MaterialTheme.colorScheme.onSurfaceVariant)+    }+}
library/ui/src/main/java/com/vayunmathur/library/ui/Icons.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/Icons.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/Icons.ktindex bf6747c11d..8dcd436036 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/Icons.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/Icons.kt@@ -142,6 +142,7 @@ import androidx.compose.material.icons.filled.Cast import androidx.compose.material.icons.filled.CastConnected import androidx.compose.material.icons.filled.ScreenShare import androidx.compose.material.icons.filled.Speaker+import androidx.compose.material.icons.filled.Movie import androidx.compose.material.icons.filled.Tv import androidx.compose.material.icons.filled.Close import androidx.compose.material.icons.filled.Cloud@@ -235,6 +236,7 @@ import androidx.compose.material.icons.filled.SkipPrevious import androidx.compose.material.icons.filled.Sms import androidx.compose.material.icons.filled.Star import androidx.compose.material.icons.filled.StarBorder+import androidx.compose.material.icons.filled.Store import androidx.compose.material.icons.filled.Stop import androidx.compose.material.icons.filled.Subscriptions import androidx.compose.material.icons.filled.ThumbDown@@ -1769,3 +1771,11 @@ fun IconWifiFull(modifier: Modifier = Modifier, tint: Color = LocalContentColor. @Composable fun IconWifiOff(modifier: Modifier = Modifier, tint: Color = LocalContentColor.current) =     AppIcon(Icons.Filled.WifiOff, "Offline", modifier, tint)++@Composable+fun IconMovie(modifier: Modifier = Modifier, tint: Color = LocalContentColor.current) =+    AppIcon(Icons.Filled.Movie, "Movies", modifier, tint)++@Composable+fun IconStore(modifier: Modifier = Modifier, tint: Color = LocalContentColor.current) =+    AppIcon(Icons.Filled.Store, "Store", modifier, tint)
settings.gradle.kts
diff --git a/settings.gradle.kts b/settings.gradle.ktsindex d2000c4a61..68c9c39b2f 100644--- a/settings.gradle.kts+++ b/settings.gradle.kts@@ -103,6 +103,7 @@ include(":web") include(":appstore") include(":library:locationprovider") include(":library:aosp-stubs")+include(":library:tv") include(":networklocation") include(":fooddelivery") include(":measure")