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 epg timeline header

David Nashash19b95766a5a4
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgGridComponents.kt b/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgGridComponents.kt
index b238559d..b6865f4e 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgGridComponents.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgGridComponents.kt
@@ -51,6 +51,8 @@ import androidx.tv.material3.SurfaceDefaults
import androidx.tv.material3.Text
import com.streamvault.app.R
import com.streamvault.feature.live.presentation.epg.GuideDensity
+import com.streamvault.feature.live.presentation.epg.LIVE_GUIDE_MARKER_STEP_MS
+import com.streamvault.feature.live.presentation.epg.LiveGuideTimelineHeader
import com.streamvault.feature.live.presentation.epg.currentLiveGuideNow
import com.streamvault.feature.live.presentation.epg.liveEpgChannelKey
import com.streamvault.core.ui.image.ChannelLogoBadge
@@ -132,10 +134,10 @@ internal fun EpgGrid(
} else {
timelineViewportWidth
}
- val markerStepMs = EpgViewModel.HALF_HOUR_SHIFT_MS
+ val markerStepMs = LIVE_GUIDE_MARKER_STEP_MS
Column(modifier = Modifier.fillMaxSize()) {
- GuideTimelineHeader(
+ LiveGuideTimelineHeader(
windowStart = guideWindowStart,
windowEnd = guideWindowEnd,
channelRailWidth = channelRailWidth,
@@ -191,102 +193,6 @@ internal fun EpgGrid(
}
}
@Composable
-private fun GuideTimelineHeader(
- windowStart: Long,
- windowEnd: Long,
- channelRailWidth: Dp,
- timelineGap: Dp,
- timelineViewportWidth: Dp,
- totalTimelineWidth: Dp,
- markerStepMs: Long,
- scrollState: androidx.compose.foundation.ScrollState
-) {
- val now = currentLiveGuideNow()
- val appTimeFormat = LocalLiveTimeFormat.current
- val hourFormat = remember(appTimeFormat) { appTimeFormat.createLiveTimeFormatter() }
- val zone = remember { ZoneId.systemDefault() }
- val totalDuration = (windowEnd - windowStart).coerceAtLeast(1L)
- val clampedNow = now.coerceIn(windowStart, windowEnd)
- val elapsedRatio = ((clampedNow - windowStart).toFloat() / totalDuration.toFloat()).coerceIn(0f, 1f)
- val markerLabel = if (now in windowStart..windowEnd) {
- stringResource(R.string.epg_now_marker, hourFormat.format(Instant.ofEpochMilli(now).atZone(zone)))
- } else {
- stringResource(R.string.epg_outside_window)
- }
- val hourMarkers = buildList {
- val firstMarker = windowStart - (windowStart % markerStepMs)
- var marker = firstMarker
- while (marker <= windowEnd) {
- add(marker)
- marker += markerStepMs
- }
- if (lastOrNull() != windowEnd) {
- add(windowEnd)
- }
- }
-
- Row(
- modifier = Modifier
- .fillMaxWidth()
- .padding(bottom = 2.dp),
- verticalAlignment = Alignment.Bottom
- ) {
- Spacer(modifier = Modifier.width(channelRailWidth + timelineGap))
- Column(
- modifier = Modifier.width(timelineViewportWidth),
- verticalArrangement = Arrangement.spacedBy(2.dp)
- ) {
- Box(
- modifier = Modifier
- .width(timelineViewportWidth)
- .height(20.dp)
- ) {
- Row(
- modifier = Modifier
- .width(totalTimelineWidth)
- .horizontalScroll(scrollState)
- ) {
- Box(
- modifier = Modifier
- .width(totalTimelineWidth)
- .height(20.dp)
- ) {
- hourMarkers.forEach { marker ->
- val markerRatio = ((marker - windowStart).toFloat() / totalDuration.toFloat()).coerceIn(0f, 1f)
- val markerOffset = totalTimelineWidth * markerRatio
- Column(
- modifier = Modifier.padding(start = markerOffset),
- verticalArrangement = Arrangement.spacedBy(2.dp)
- ) {
- Text(
- text = hourFormat.format(Instant.ofEpochMilli(marker).atZone(zone)),
- style = MaterialTheme.typography.labelSmall,
- color = OnSurfaceDim
- )
- Box(
- modifier = Modifier
- .width(1.dp)
- .height(8.dp)
- .background(Color.White.copy(alpha = 0.16f))
- )
- }
- }
- if (now in windowStart..windowEnd) {
- Box(
- modifier = Modifier
- .padding(start = totalTimelineWidth * elapsedRatio)
- .width(2.dp)
- .fillMaxHeight()
- .background(Primary)
- )
- }
- }
- }
- }
- }
- }
-}
-@Composable
fun EpgRow(
channel: Channel,
isFavorite: Boolean,
diff --git a/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md b/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
index b86ec40a..7e0edf1c 100644
--- a/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
+++ b/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
@@ -149,7 +149,8 @@ category options dialog, the quick-filter add dialog, the delete-group dialog,
and the rename-group dialog, M3U category organizer dialog, and M3U
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, and stable EPG channel-key helper are
+toolbar, guide message state, hero badge, stable EPG channel-key helper, and
+timeline header 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 1cd20215..e5c326fa 100644
--- a/docs/superpowers/plans/2026-08-28-live-feature-extraction.md
+++ b/docs/superpowers/plans/2026-08-28-live-feature-extraction.md
@@ -27,7 +27,7 @@ and hidden category/channel dialogs, the category options dialog, the
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, and hero badge are now feature-owned
+pane, guide toolbar, guide message state, hero badge, and timeline header are now 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.
@@ -711,7 +711,9 @@ The guide message state owns centered empty/loading/error presentation and the
optional action affordance while callers supply state-specific copy and action.
The hero badge owns rounded highlight styling and text overflow presentation;
callers supply the text and optional accent. Stable EPG channel-key generation
-is feature-owned and covered by focused identity tests.
+and timeline marker calculation are feature-owned and covered by focused
+identity/timeline tests. The timeline header owns marker rendering and
+live-time presentation while the app supplies sizing and scroll state.
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/epg/LiveGuideTimelineHeader.kt b/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveGuideTimelineHeader.kt
new file mode 100644
index 00000000..f1391b17
--- /dev/null
+++ b/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveGuideTimelineHeader.kt
@@ -0,0 +1,133 @@
+package com.streamvault.feature.live.presentation.epg
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.horizontalScroll
+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.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.width
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.remember
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.dp
+import androidx.tv.material3.MaterialTheme
+import androidx.tv.material3.Text
+import com.streamvault.core.ui.theme.OnSurfaceDim
+import com.streamvault.core.ui.theme.Primary
+import com.streamvault.feature.live.presentation.time.LocalLiveTimeFormat
+import com.streamvault.feature.live.presentation.time.createLiveTimeFormatter
+import java.time.Instant
+import java.time.ZoneId
+
+const val LIVE_GUIDE_MARKER_STEP_MS = 30 * 60 * 1000L
+
+fun liveGuideTimelineMarkers(
+ windowStart: Long,
+ windowEnd: Long,
+ markerStepMs: Long = LIVE_GUIDE_MARKER_STEP_MS
+): List<Long> {
+ val firstMarker = windowStart - (windowStart % markerStepMs)
+ return buildList {
+ var marker = firstMarker
+ while (marker <= windowEnd) {
+ add(marker)
+ marker += markerStepMs
+ }
+ if (lastOrNull() != windowEnd) {
+ add(windowEnd)
+ }
+ }
+}
+
+@Composable
+fun LiveGuideTimelineHeader(
+ windowStart: Long,
+ windowEnd: Long,
+ channelRailWidth: Dp,
+ timelineGap: Dp,
+ timelineViewportWidth: Dp,
+ totalTimelineWidth: Dp,
+ markerStepMs: Long = LIVE_GUIDE_MARKER_STEP_MS,
+ scrollState: androidx.compose.foundation.ScrollState
+) {
+ val now = currentLiveGuideNow()
+ val appTimeFormat = LocalLiveTimeFormat.current
+ val hourFormat = remember(appTimeFormat) { appTimeFormat.createLiveTimeFormatter() }
+ val zone = remember { ZoneId.systemDefault() }
+ val totalDuration = (windowEnd - windowStart).coerceAtLeast(1L)
+ val clampedNow = now.coerceIn(windowStart, windowEnd)
+ val elapsedRatio = ((clampedNow - windowStart).toFloat() / totalDuration.toFloat()).coerceIn(0f, 1f)
+ val hourMarkers = remember(windowStart, windowEnd, markerStepMs) {
+ liveGuideTimelineMarkers(windowStart, windowEnd, markerStepMs)
+ }
+
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(bottom = 2.dp),
+ verticalAlignment = Alignment.Bottom
+ ) {
+ Spacer(modifier = Modifier.width(channelRailWidth + timelineGap))
+ Column(
+ modifier = Modifier.width(timelineViewportWidth),
+ verticalArrangement = Arrangement.spacedBy(2.dp)
+ ) {
+ Box(
+ modifier = Modifier
+ .width(timelineViewportWidth)
+ .height(20.dp)
+ ) {
+ Row(
+ modifier = Modifier
+ .width(totalTimelineWidth)
+ .horizontalScroll(scrollState)
+ ) {
+ Box(
+ modifier = Modifier
+ .width(totalTimelineWidth)
+ .height(20.dp)
+ ) {
+ hourMarkers.forEach { marker ->
+ val markerRatio = ((marker - windowStart).toFloat() / totalDuration.toFloat()).coerceIn(0f, 1f)
+ val markerOffset = totalTimelineWidth * markerRatio
+ Column(
+ modifier = Modifier.padding(start = markerOffset),
+ verticalArrangement = Arrangement.spacedBy(2.dp)
+ ) {
+ Text(
+ text = hourFormat.format(Instant.ofEpochMilli(marker).atZone(zone)),
+ style = MaterialTheme.typography.labelSmall,
+ color = OnSurfaceDim
+ )
+ Box(
+ modifier = Modifier
+ .width(1.dp)
+ .height(8.dp)
+ .background(Color.White.copy(alpha = 0.16f))
+ )
+ }
+ }
+ if (now in windowStart..windowEnd) {
+ Box(
+ modifier = Modifier
+ .padding(start = totalTimelineWidth * elapsedRatio)
+ .width(2.dp)
+ .fillMaxHeight()
+ .background(Primary)
+ )
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideTimelineTest.kt b/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideTimelineTest.kt
new file mode 100644
index 00000000..b4004ee8
--- /dev/null
+++ b/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideTimelineTest.kt
@@ -0,0 +1,25 @@
+package com.streamvault.feature.live.presentation.epg
+
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+
+class LiveGuideTimelineTest {
+ @Test
+ fun `timeline markers include aligned markers and window end`() {
+ assertThat(liveGuideTimelineMarkers(10 * MINUTE_MS, 80 * MINUTE_MS, HALF_HOUR_MS))
+ .containsExactly(0L, 30 * MINUTE_MS, 60 * MINUTE_MS, 80 * MINUTE_MS)
+ .inOrder()
+ }
+
+ @Test
+ fun `timeline markers do not duplicate an aligned window end`() {
+ assertThat(liveGuideTimelineMarkers(0L, 60 * MINUTE_MS, HALF_HOUR_MS))
+ .containsExactly(0L, 30 * MINUTE_MS, 60 * MINUTE_MS)
+ .inOrder()
+ }
+
+ private companion object {
+ const val MINUTE_MS = 60_000L
+ const val HALF_HOUR_MS = 30 * MINUTE_MS
+ }
+}