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 channel key

David Nashash3c9d254d56ff
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 3b4bf9e4..b238559d 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
@@ -52,6 +52,7 @@ 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.currentLiveGuideNow
+import com.streamvault.feature.live.presentation.epg.liveEpgChannelKey
import com.streamvault.core.ui.image.ChannelLogoBadge
import com.streamvault.core.ui.interaction.TvButton
import com.streamvault.core.ui.interaction.TvClickableSurface
@@ -152,7 +153,7 @@ internal fun EpgGrid(
) {
itemsIndexed(
items = channels,
- key = { index, channel -> epgChannelKey(channel, index) },
+ key = { index, channel -> liveEpgChannelKey(channel, index) },
contentType = { _, _ -> "epg_channel" }
) { index, channel ->
if (index >= channels.size - 15) {
@@ -499,7 +500,6 @@ fun EpgRow(
}
}
}
-
@Composable
fun ProgramItem(
program: Program,
@@ -645,8 +645,3 @@ internal fun formatWindowDuration(durationMs: Long): String {
"${hours}h ${minutes}m"
}
}
-
-internal fun epgChannelKey(channel: Channel, index: Int): String {
- val epgId = channel.guideLookupKey().orEmpty()
- return "channel:${channel.id}:${channel.streamId}:${epgId}:${channel.name.trim()}:$index"
-}
diff --git a/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md b/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
index 57f13270..b86ec40a 100644
--- a/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
+++ b/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
@@ -149,6 +149,7 @@ 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, and hero badge are independent of app code;
+toolbar, guide message state, hero badge, and stable EPG channel-key helper 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 69075ffd..1cd20215 100644
--- a/docs/superpowers/plans/2026-08-28-live-feature-extraction.md
+++ b/docs/superpowers/plans/2026-08-28-live-feature-extraction.md
@@ -710,7 +710,8 @@ supplies category text and navigation callbacks.
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.
+callers supply the text and optional accent. Stable EPG channel-key generation
+is feature-owned and covered by focused identity tests.
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/LiveEpgKeys.kt b/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveEpgKeys.kt
new file mode 100644
index 00000000..8dd1a73b
--- /dev/null
+++ b/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveEpgKeys.kt
@@ -0,0 +1,9 @@
+package com.streamvault.feature.live.presentation.epg
+
+import com.streamvault.domain.model.Channel
+import com.streamvault.feature.live.presentation.model.guideLookupKey
+
+fun liveEpgChannelKey(channel: Channel, index: Int): String {
+ val epgId = channel.guideLookupKey().orEmpty()
+ return "channel:${channel.id}:${channel.streamId}:$epgId:${channel.name.trim()}:$index"
+}
diff --git a/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveEpgKeysTest.kt b/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveEpgKeysTest.kt
new file mode 100644
index 00000000..467470c9
--- /dev/null
+++ b/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveEpgKeysTest.kt
@@ -0,0 +1,28 @@
+package com.streamvault.feature.live.presentation.epg
+
+import com.google.common.truth.Truth.assertThat
+import com.streamvault.domain.model.Channel
+import org.junit.Test
+
+class LiveEpgKeysTest {
+ @Test
+ fun `channel key includes stable channel and guide identity`() {
+ val channel = Channel(
+ id = 42L,
+ name = " News ",
+ epgChannelId = "xmltv.news",
+ streamId = 7L
+ )
+
+ assertThat(liveEpgChannelKey(channel, index = 3))
+ .isEqualTo("channel:42:7:xmltv.news:News:3")
+ }
+
+ @Test
+ fun `channel key falls back to stream id when guide id is absent`() {
+ val channel = Channel(id = 9L, name = "Sports", streamId = 11L)
+
+ assertThat(liveEpgChannelKey(channel, index = 0))
+ .isEqualTo("channel:9:11:11:Sports:0")
+ }
+}