Skip to content

StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.

refactor(live): extract home layout metrics

David Nashash979cf11c7373
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt
index aaee7340..185e63ec 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt
@@ -55,6 +55,7 @@ import com.streamvault.core.ui.components.dialogs.PremiumDialogActionButton
import com.streamvault.core.ui.components.dialogs.PremiumDialogFooterButton
import com.streamvault.app.ui.components.dialogs.RenameGroupDialog
import com.streamvault.feature.live.presentation.components.LiveReorderTopBar
+import com.streamvault.feature.live.presentation.home.liveHomeLayoutMetrics
import com.streamvault.app.ui.components.shell.AppNavigationChrome
import com.streamvault.app.ui.components.shell.AppScreenScaffold
import com.streamvault.core.ui.design.FocusRestoreHost
@@ -119,36 +120,16 @@ fun HomeScreen(
val isReorderMode = uiState.isChannelReorderMode
val isProMode = uiState.liveTvChannelMode == LiveTvChannelMode.PRO
val isDenseMode = uiState.liveTvChannelMode != LiveTvChannelMode.COMFORTABLE
- val screenWidth = LocalConfiguration.current.screenWidthDp.dp
val isTelevisionDevice = rememberIsTelevisionDevice()
- val sidebarWidth = if (screenWidth < 900.dp) {
- (screenWidth * 0.36f).coerceIn(188.dp, 220.dp)
- } else if (!isTelevisionDevice && screenWidth < 1280.dp) {
- (screenWidth * 0.28f).coerceIn(220.dp, 252.dp)
- } else {
- 272.dp
- }
- val channelSearchWidth = if (screenWidth < 900.dp) {
- (screenWidth * 0.34f).coerceIn(170.dp, 220.dp)
- } else if (!isTelevisionDevice && screenWidth < 1280.dp) {
- (screenWidth * 0.28f).coerceIn(220.dp, 280.dp)
- } else if (isProMode) {
- 320.dp
- } else if (isDenseMode) {
- 300.dp
- } else {
- 340.dp
- }
- val channelRowHeight = when (uiState.liveTvChannelMode) {
- LiveTvChannelMode.COMFORTABLE -> 92.dp
- LiveTvChannelMode.COMPACT -> 54.dp
- LiveTvChannelMode.PRO -> 52.dp
- }
- val channelListSpacing = when (uiState.liveTvChannelMode) {
- LiveTvChannelMode.COMFORTABLE -> 8.dp
- LiveTvChannelMode.COMPACT -> 2.dp
- LiveTvChannelMode.PRO -> 2.dp
- }
+ val layoutMetrics = liveHomeLayoutMetrics(
+ screenWidthDp = LocalConfiguration.current.screenWidthDp,
+ isTelevisionDevice = isTelevisionDevice,
+ channelMode = uiState.liveTvChannelMode
+ )
+ val sidebarWidth = layoutMetrics.sidebarWidth
+ val channelSearchWidth = layoutMetrics.channelSearchWidth
+ val channelRowHeight = layoutMetrics.channelRowHeight
+ val channelListSpacing = layoutMetrics.channelListSpacing
val snackbarHostState = remember { SnackbarHostState() }
// Split screen state
diff --git a/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md b/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
index f696da3a..d27c1a03 100644
--- a/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
+++ b/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
@@ -138,8 +138,9 @@ quick-filter add dialog, delete-group dialog, rename-group dialog, M3U category
organizer dialog, M3U series-assignment dialogs, EPG search overlay, guide
category picker, compact guide-program dialog, guide control rows, EPG preview
pane, guide toolbar, guide message state, hero badge, timeline header, grid
-rows/cells, grid host, EPG content host, and focus reconciliation are now
-feature-owned, with the options overlay and EPG-match dialog also feature-owned
+rows/cells, grid host, EPG content host, focus reconciliation, and Home layout
+metrics are now feature-owned, with the options overlay and EPG-match dialog
+also feature-owned
while the Home and EPG
screen/dialog composition remains in `:app` for the remaining app-specific
dialogs.
@@ -153,7 +154,7 @@ series-assignment dialogs, the EPG search overlay, guide category picker, and
compact guide-program dialog, guide control rows, EPG preview pane, guide
toolbar, guide message state, hero badge, stable EPG channel-key helper,
timeline header, grid rows/cells, grid host, EPG content host, focus
-reconciliation, options overlay, and EPG-match dialog are independent of app
-code;
+reconciliation, Home layout metrics, options overlay, and EPG-match dialog are
+independent of app code;
screen/resource moves, golden/runtime/performance gates, and legacy app cleanup
remain open, so no live slice acceptance gate is claimed yet.
diff --git a/docs/superpowers/plans/2026-08-28-live-feature-extraction.md b/docs/superpowers/plans/2026-08-28-live-feature-extraction.md
index 9efc4294..82ac5952 100644
--- a/docs/superpowers/plans/2026-08-28-live-feature-extraction.md
+++ b/docs/superpowers/plans/2026-08-28-live-feature-extraction.md
@@ -28,8 +28,9 @@ quick-filter add dialog, delete-group dialog, rename-group dialog, M3U category
organizer dialog, M3U series-assignment dialogs, EPG search overlay, guide
category picker, compact guide-program dialog, guide control rows, EPG preview
pane, guide toolbar, guide message state, hero badge, timeline header, grid
-rows/cells, grid host, EPG content host, and focus reconciliation are now
-feature-owned, with the options overlay and EPG-match dialog also feature-owned
+rows/cells, grid host, EPG content host, focus reconciliation, and Home layout
+metrics are now feature-owned, with the options overlay and EPG-match dialog
+also feature-owned
and their feature checks are green. Home screen/dialog composition, the
remaining live cards/rows, complete locale resource migration, and acceptance
gates remain open.
@@ -725,6 +726,9 @@ toolbar, refresh, and grid composition while the app supplies the localized
label bundles, content message, state, and action callbacks. The options
overlay and EPG-match dialog likewise own their presentation and focus behavior
while the app supplies localized labels and state/action callbacks.
+Home layout metrics now preserve the existing device/mode breakpoints behind a
+feature-owned pure contract while `HomeScreen` supplies the configuration and
+device inputs.
quick-filter key/selection rules are covered by `LiveQuickFiltersTest`. The
remaining app-owned live cards and shell/dialog composition still require
compatibility seams before the full Home move.
diff --git a/feature/live/src/main/java/com/streamvault/feature/live/presentation/home/LiveHomeLayout.kt b/feature/live/src/main/java/com/streamvault/feature/live/presentation/home/LiveHomeLayout.kt
new file mode 100644
index 00000000..18db5d2e
--- /dev/null
+++ b/feature/live/src/main/java/com/streamvault/feature/live/presentation/home/LiveHomeLayout.kt
@@ -0,0 +1,54 @@
+package com.streamvault.feature.live.presentation.home
+
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.dp
+import com.streamvault.domain.model.LiveTvChannelMode
+
+data class LiveHomeLayoutMetrics(
+ val sidebarWidth: Dp,
+ val channelSearchWidth: Dp,
+ val channelRowHeight: Dp,
+ val channelListSpacing: Dp
+)
+
+fun liveHomeLayoutMetrics(
+ screenWidthDp: Int,
+ isTelevisionDevice: Boolean,
+ channelMode: LiveTvChannelMode
+): LiveHomeLayoutMetrics {
+ val screenWidth = screenWidthDp.dp
+ val sidebarWidth = if (screenWidth < 900.dp) {
+ (screenWidth * 0.36f).coerceIn(188.dp, 220.dp)
+ } else if (!isTelevisionDevice && screenWidth < 1280.dp) {
+ (screenWidth * 0.28f).coerceIn(220.dp, 252.dp)
+ } else {
+ 272.dp
+ }
+ val channelSearchWidth = if (screenWidth < 900.dp) {
+ (screenWidth * 0.34f).coerceIn(170.dp, 220.dp)
+ } else if (!isTelevisionDevice && screenWidth < 1280.dp) {
+ (screenWidth * 0.28f).coerceIn(220.dp, 280.dp)
+ } else if (channelMode == LiveTvChannelMode.PRO) {
+ 320.dp
+ } else if (channelMode != LiveTvChannelMode.COMFORTABLE) {
+ 300.dp
+ } else {
+ 340.dp
+ }
+ val channelRowHeight = when (channelMode) {
+ LiveTvChannelMode.COMFORTABLE -> 92.dp
+ LiveTvChannelMode.COMPACT -> 54.dp
+ LiveTvChannelMode.PRO -> 52.dp
+ }
+ val channelListSpacing = when (channelMode) {
+ LiveTvChannelMode.COMFORTABLE -> 8.dp
+ LiveTvChannelMode.COMPACT -> 2.dp
+ LiveTvChannelMode.PRO -> 2.dp
+ }
+ return LiveHomeLayoutMetrics(
+ sidebarWidth = sidebarWidth,
+ channelSearchWidth = channelSearchWidth,
+ channelRowHeight = channelRowHeight,
+ channelListSpacing = channelListSpacing
+ )
+}
diff --git a/feature/live/src/test/java/com/streamvault/feature/live/presentation/home/LiveHomeLayoutTest.kt b/feature/live/src/test/java/com/streamvault/feature/live/presentation/home/LiveHomeLayoutTest.kt
new file mode 100644
index 00000000..e1bb6d6a
--- /dev/null
+++ b/feature/live/src/test/java/com/streamvault/feature/live/presentation/home/LiveHomeLayoutTest.kt
@@ -0,0 +1,50 @@
+package com.streamvault.feature.live.presentation.home
+
+import com.google.common.truth.Truth.assertThat
+import com.streamvault.domain.model.LiveTvChannelMode
+import androidx.compose.ui.unit.dp
+import org.junit.Test
+
+class LiveHomeLayoutTest {
+ @Test
+ fun `compact handset metrics respect minimum widths`() {
+ val metrics = liveHomeLayoutMetrics(
+ screenWidthDp = 600,
+ isTelevisionDevice = false,
+ channelMode = LiveTvChannelMode.COMPACT
+ )
+
+ assertThat(metrics.sidebarWidth.value).isWithin(0.01f).of(216f)
+ assertThat(metrics.channelSearchWidth.value).isWithin(0.01f).of(204f)
+ assertThat(metrics.channelRowHeight).isEqualTo(54.dp)
+ assertThat(metrics.channelListSpacing).isEqualTo(2.dp)
+ }
+
+ @Test
+ fun `non television tablet metrics use proportional widths`() {
+ val metrics = liveHomeLayoutMetrics(
+ screenWidthDp = 1000,
+ isTelevisionDevice = false,
+ channelMode = LiveTvChannelMode.COMFORTABLE
+ )
+
+ assertThat(metrics.sidebarWidth).isEqualTo(252.dp)
+ assertThat(metrics.channelSearchWidth).isEqualTo(280.dp)
+ assertThat(metrics.channelRowHeight).isEqualTo(92.dp)
+ assertThat(metrics.channelListSpacing).isEqualTo(8.dp)
+ }
+
+ @Test
+ fun `television pro metrics use the fixed desktop layout`() {
+ val metrics = liveHomeLayoutMetrics(
+ screenWidthDp = 1920,
+ isTelevisionDevice = true,
+ channelMode = LiveTvChannelMode.PRO
+ )
+
+ assertThat(metrics.sidebarWidth).isEqualTo(272.dp)
+ assertThat(metrics.channelSearchWidth).isEqualTo(320.dp)
+ assertThat(metrics.channelRowHeight).isEqualTo(52.dp)
+ assertThat(metrics.channelListSpacing).isEqualTo(2.dp)
+ }
+}