StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.
Kotlin iptv-player
refactor(live): extract epg focus reconciliation
David Nashash20f5f6206f4c
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgScreen.ktindex 0cd93dd6..8ffb45d6 100644--- a/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgScreen.kt+++ b/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgScreen.kt@@ -4,7 +4,7 @@ import android.view.inputmethod.InputMethodManagerimport com.streamvault.domain.playback.ArchiveReplayMechanismimport com.streamvault.domain.playback.archivePlaybackCapabilityimport com.streamvault.domain.playback.isArchivePlayable-import com.streamvault.feature.live.presentation.model.guideLookupKey+import com.streamvault.feature.live.presentation.epg.resolveLiveGuideFocusimport com.streamvault.feature.live.presentation.epg.LiveGuideNowProviderimport com.streamvault.feature.live.presentation.epg.currentLiveGuideNowimport com.streamvault.feature.live.presentation.epg.LiveGuideSearchOverlay@@ -336,29 +336,15 @@ fun FullEpgScreen(}LaunchedEffect(uiState.channels, uiState.programsByChannel) {- if (uiState.channels.isEmpty()) {- focusedChannel = null- focusedProgram = null- return@LaunchedEffect- }- val resolvedChannel = focusedChannel?.let { current ->- uiState.channels.firstOrNull { it.id == current.id }- } ?: uiState.channels.firstOrNull()- focusedChannel = resolvedChannel- val resolvedPrograms = resolvedChannel?.let { channel ->- channel.guideLookupKey()?.let { lookupKey ->- uiState.programsByChannel[lookupKey].orEmpty()- }.orEmpty()- }.orEmpty()- focusedProgram = focusedProgram?.let { focused ->- resolvedPrograms.firstOrNull {- it.startTime == focused.startTime &&- it.endTime == focused.endTime &&- it.title == focused.title- }- } ?: resolvedPrograms.firstOrNull {- System.currentTimeMillis() in it.startTime until it.endTime- }+ val resolvedFocus = resolveLiveGuideFocus(+ channels = uiState.channels,+ programsByChannel = uiState.programsByChannel,+ focusedChannel = focusedChannel,+ focusedProgram = focusedProgram,+ now = System.currentTimeMillis()+ )+ focusedChannel = resolvedFocus.channel+ focusedProgram = resolvedFocus.program}val contentMessage = when {diff --git a/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md b/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.mdindex 5d6dee20..f696da3a 100644--- a/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md+++ b/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md@@ -138,8 +138,8 @@ quick-filter add dialog, delete-group dialog, rename-group dialog, M3U categoryorganizer dialog, M3U series-assignment dialogs, EPG search overlay, guidecategory picker, compact guide-program dialog, guide control rows, EPG previewpane, guide toolbar, guide message state, hero badge, timeline header, grid-rows/cells, grid host, and the EPG content host are now feature-owned, with-the options overlay and EPG-match dialog also feature-owned+rows/cells, grid host, EPG content host, and focus reconciliation are now+feature-owned, with the options overlay and EPG-match dialog also feature-ownedwhile the Home and EPGscreen/dialog composition remains in `:app` for the remaining app-specificdialogs.@@ -152,7 +152,8 @@ and the rename-group dialog, M3U category organizer dialog, and M3Useries-assignment dialogs, the EPG search overlay, guide category picker, andcompact guide-program dialog, guide control rows, EPG preview pane, guidetoolbar, guide message state, hero badge, stable EPG channel-key helper,-timeline header, grid rows/cells, grid host, EPG content host, options overlay,-and EPG-match dialog are independent of app code;+timeline header, grid rows/cells, grid host, EPG content host, focus+reconciliation, options overlay, and EPG-match dialog are independent of app+code;screen/resource moves, golden/runtime/performance gates, and legacy app cleanupremain 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.mdindex d270466f..9efc4294 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,8 @@ quick-filter add dialog, delete-group dialog, rename-group dialog, M3U categoryorganizer dialog, M3U series-assignment dialogs, EPG search overlay, guidecategory picker, compact guide-program dialog, guide control rows, EPG previewpane, guide toolbar, guide message state, hero badge, timeline header, grid-rows/cells, grid host, and the EPG content host are now feature-owned, with-the options overlay and EPG-match dialog also feature-owned+rows/cells, grid host, EPG content host, and focus reconciliation are now+feature-owned, with the options overlay and EPG-match dialog also feature-ownedand their feature checks are green. Home screen/dialog composition, theremaining live cards/rows, complete locale resource migration, and acceptancegates remain open.@@ -718,7 +718,9 @@ identity/timeline tests. The timeline header owns marker rendering andlive-time presentation while the app supplies sizing and scroll state. Gridrows/cells and the grid host own guide row composition, sizing, scrolling, andfocus behavior while the app supplies localized labels, guide data, and-state/action callbacks. The EPG content host now owns loading, message, preview,+state/action callbacks. Focus reconciliation now resolves stale channel/program+selection and current-program fallback behind a feature-owned pure contract.+The EPG content host now owns loading, message, preview,toolbar, refresh, and grid composition while the app supplies the localizedlabel bundles, content message, state, and action callbacks. The optionsoverlay and EPG-match dialog likewise own their presentation and focus behaviordiff --git a/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveGuideFocus.kt b/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveGuideFocus.ktnew file mode 100644index 00000000..f17f5856--- /dev/null+++ b/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveGuideFocus.kt@@ -0,0 +1,45 @@+package com.streamvault.feature.live.presentation.epg++import com.streamvault.domain.model.Channel+import com.streamvault.domain.model.Program+import com.streamvault.feature.live.presentation.model.guideLookupKey++data class LiveGuideFocusSelection(+ val channel: Channel?,+ val program: Program?+)++fun resolveLiveGuideFocus(+ channels: List<Channel>,+ programsByChannel: Map<String, List<Program>>,+ focusedChannel: Channel?,+ focusedProgram: Program?,+ now: Long+): LiveGuideFocusSelection {+ if (channels.isEmpty()) {+ return LiveGuideFocusSelection(channel = null, program = null)+ }++ val resolvedChannel = focusedChannel?.let { current ->+ channels.firstOrNull { it.id == current.id }+ } ?: channels.firstOrNull()+ val resolvedPrograms = resolvedChannel?.let { channel ->+ channel.guideLookupKey()?.let { lookupKey ->+ programsByChannel[lookupKey].orEmpty()+ }.orEmpty()+ }.orEmpty()+ val resolvedProgram = focusedProgram?.let { focused ->+ resolvedPrograms.firstOrNull {+ it.startTime == focused.startTime &&+ it.endTime == focused.endTime &&+ it.title == focused.title+ }+ } ?: resolvedPrograms.firstOrNull {+ now in it.startTime until it.endTime+ }++ return LiveGuideFocusSelection(+ channel = resolvedChannel,+ program = resolvedProgram+ )+}diff --git a/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideFocusTest.kt b/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideFocusTest.ktnew file mode 100644index 00000000..e7cb8827--- /dev/null+++ b/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideFocusTest.kt@@ -0,0 +1,71 @@+package com.streamvault.feature.live.presentation.epg++import com.google.common.truth.Truth.assertThat+import com.streamvault.domain.model.Channel+import com.streamvault.domain.model.Program+import org.junit.Test++class LiveGuideFocusTest {+ @Test+ fun `focus resolution preserves the selected channel and matching program`() {+ val channel = Channel(id = 10L, name = "News", streamId = 10L)+ val program = Program(+ channelId = "10",+ title = "Headlines",+ startTime = 1_000L,+ endTime = 2_000L+ )++ val result = resolveLiveGuideFocus(+ channels = listOf(channel),+ programsByChannel = mapOf("10" to listOf(program)),+ focusedChannel = channel,+ focusedProgram = program,+ now = 1_500L+ )++ assertThat(result.channel).isEqualTo(channel)+ assertThat(result.program).isEqualTo(program)+ }++ @Test+ fun `focus resolution falls back to the first channel and current program`() {+ val channel = Channel(id = 10L, name = "News", streamId = 10L)+ val program = Program(+ channelId = "10",+ title = "Headlines",+ startTime = 1_000L,+ endTime = 2_000L+ )++ val result = resolveLiveGuideFocus(+ channels = listOf(channel),+ programsByChannel = mapOf("10" to listOf(program)),+ focusedChannel = null,+ focusedProgram = null,+ now = 1_500L+ )++ assertThat(result.channel).isEqualTo(channel)+ assertThat(result.program).isEqualTo(program)+ }++ @Test+ fun `focus resolution clears both values when channels are empty`() {+ val result = resolveLiveGuideFocus(+ channels = emptyList(),+ programsByChannel = emptyMap(),+ focusedChannel = Channel(id = 10L, name = "News"),+ focusedProgram = Program(+ channelId = "10",+ title = "Headlines",+ startTime = 1_000L,+ endTime = 2_000L+ ),+ now = 1_500L+ )++ assertThat(result.channel).isNull()+ assertThat(result.program).isNull()+ }+}