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 schedule metrics

David Nashashabc052722a0f
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgViewModel.kt b/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgViewModel.kt
index b6d2d911..24502b87 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgViewModel.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgViewModel.kt
@@ -80,6 +80,9 @@ import com.streamvault.feature.live.presentation.epg.programReminderDeliveryIssu
import com.streamvault.feature.live.presentation.epg.isLiveGuideCategoryAccessible
import com.streamvault.feature.live.presentation.epg.matchesLiveGuideMetadataSearch
import com.streamvault.feature.live.presentation.epg.resolveLiveGuideCategorySelection
+import com.streamvault.feature.live.presentation.epg.countMissingLiveGuideEntries
+import com.streamvault.feature.live.presentation.epg.countLiveGuideChannelsWithSchedule
+import com.streamvault.feature.live.presentation.epg.hasUpcomingLiveGuideData
import javax.inject.Provider as InjectProvider
data class RecordingConflictInfo(
@@ -1702,7 +1705,7 @@ class EpgViewModel @Inject constructor(
val programsByChannel = resolvedPrograms + legacyPrograms
return GuideProgramsResult(
programsByChannel = programsByChannel,
- failedCount = countMissingGuideEntries(channels, programsByChannel)
+ failedCount = countMissingLiveGuideEntries(channels, programsByChannel)
)
}
@@ -1733,7 +1736,7 @@ class EpgViewModel @Inject constructor(
val guideKeys = channels.mapNotNull(Channel::guideLookupKey).distinct()
return GuideProgramsResult(
programsByChannel = mergedProgramsByChannel,
- failedCount = countMissingGuideEntries(channels, mergedProgramsByChannel)
+ failedCount = countMissingLiveGuideEntries(channels, mergedProgramsByChannel)
)
}
@@ -1773,12 +1776,12 @@ class EpgViewModel @Inject constructor(
val mergedProgramsByChannel = currentSnapshot.baseProgramsByChannel + fallbackProgramsByChannel
val visibleChannels = currentSnapshot.visibleChannels
- val channelsWithSchedule = countChannelsWithSchedule(visibleChannels, mergedProgramsByChannel)
- val hasUpcomingData = hasUpcomingGuideData(mergedProgramsByChannel, currentSnapshot.guideWindowStart)
+ val channelsWithSchedule = countLiveGuideChannelsWithSchedule(visibleChannels, mergedProgramsByChannel)
+ val hasUpcomingData = hasUpcomingLiveGuideData(mergedProgramsByChannel, currentSnapshot.guideWindowStart)
currentSnapshot.copy(
baseProgramsByChannel = mergedProgramsByChannel,
- failedScheduleCount = countMissingGuideEntries(visibleChannels, mergedProgramsByChannel),
+ failedScheduleCount = countMissingLiveGuideEntries(visibleChannels, mergedProgramsByChannel),
lastUpdatedAt = System.currentTimeMillis(),
baseChannelsWithSchedule = channelsWithSchedule,
baseGuideStale = visibleChannels.isNotEmpty() && (channelsWithSchedule == 0 || !hasUpcomingData)
@@ -1852,32 +1855,6 @@ class EpgViewModel @Inject constructor(
guideWindowEnd == context.guideWindowEnd &&
visibleChannels.map(Channel::id) == context.visibleChannelIds
- private fun countMissingGuideEntries(
- channels: List<Channel>,
- programsByChannel: Map<String, List<Program>>
- ): Int =
- channels.mapNotNull(Channel::guideLookupKey)
- .distinct()
- .count { lookupKey -> programsByChannel[lookupKey].isNullOrEmpty() }
-
- private fun countChannelsWithSchedule(
- channels: List<Channel>,
- programsByChannel: Map<String, List<Program>>
- ): Int =
- channels.count { channel ->
- channel.guideLookupKey()
- ?.let { lookupKey -> programsByChannel[lookupKey].orEmpty().isNotEmpty() }
- ?: false
- }
-
- private fun hasUpcomingGuideData(
- programsByChannel: Map<String, List<Program>>,
- windowStart: Long
- ): Boolean =
- programsByChannel.values.any { programs ->
- programs.any { program -> program.endTime > windowStart }
- }
-
private suspend fun buildGuideDisplaySnapshot(
baseSnapshot: GuideBaseSnapshot,
searchQuery: String,
diff --git a/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md b/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
index a5bdb52e..a3e7ef89 100644
--- a/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
+++ b/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
@@ -141,8 +141,8 @@ pane, guide toolbar, guide message state, hero badge, timeline header, grid
rows/cells, grid host, EPG content host, focus reconciliation, Home layout
metrics, and Home parental-lock policy are now feature-owned, with the options
overlay and EPG-match dialog also feature-owned
-and the EPG guide category/channel lock policies and category-selection fallback
-policy now feature-owned
+and the EPG guide category/channel lock policies, category-selection fallback
+policy, and schedule metrics now feature-owned
while the Home and EPG
screen/dialog composition remains in `:app` for the remaining app-specific
dialogs.
@@ -157,7 +157,7 @@ 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, Home layout metrics, Home parental-lock policy, EPG guide
-category/channel lock policies, category-selection fallback policy, options
-overlay, and EPG-match dialog are independent of app code;
+category/channel lock policies, category-selection fallback policy, schedule
+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 be4c5467..e6999e08 100644
--- a/docs/superpowers/plans/2026-08-28-live-feature-extraction.md
+++ b/docs/superpowers/plans/2026-08-28-live-feature-extraction.md
@@ -31,8 +31,8 @@ pane, guide toolbar, guide message state, hero badge, timeline header, grid
rows/cells, grid host, EPG content host, focus reconciliation, Home layout
metrics, and Home parental-lock policy are now feature-owned, with the options
overlay and EPG-match dialog also feature-owned
-and the EPG guide category/channel lock policies and category-selection fallback
-policy now feature-owned
+and the EPG guide category/channel lock policies, category-selection fallback
+policy, and schedule metrics 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.
@@ -740,6 +740,9 @@ The EPG category-selection fallback policy now preserves the existing
All/Favorites/accessibility ordering and explicit-unlock behavior behind a
feature-owned pure resolver; `EpgViewModel` delegates while retaining repository
coordination.
+Guide schedule metrics (missing entries, channels with schedules, and upcoming
+data) are now feature-owned pure functions; `EpgViewModel` delegates while
+retaining data loading and state assembly.
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/LiveGuideScheduleMetrics.kt b/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveGuideScheduleMetrics.kt
new file mode 100644
index 00000000..5cb860fc
--- /dev/null
+++ b/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveGuideScheduleMetrics.kt
@@ -0,0 +1,28 @@
+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
+
+fun countMissingLiveGuideEntries(
+ channels: List<Channel>,
+ programsByChannel: Map<String, List<Program>>
+): Int = channels.mapNotNull(Channel::guideLookupKey)
+ .distinct()
+ .count { lookupKey -> programsByChannel[lookupKey].isNullOrEmpty() }
+
+fun countLiveGuideChannelsWithSchedule(
+ channels: List<Channel>,
+ programsByChannel: Map<String, List<Program>>
+): Int = channels.count { channel ->
+ channel.guideLookupKey()
+ ?.let { lookupKey -> programsByChannel[lookupKey].orEmpty().isNotEmpty() }
+ ?: false
+}
+
+fun hasUpcomingLiveGuideData(
+ programsByChannel: Map<String, List<Program>>,
+ windowStart: Long
+): Boolean = programsByChannel.values.any { programs ->
+ programs.any { program -> program.endTime > windowStart }
+}
diff --git a/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideScheduleMetricsTest.kt b/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideScheduleMetricsTest.kt
new file mode 100644
index 00000000..9b6ea6ff
--- /dev/null
+++ b/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideScheduleMetricsTest.kt
@@ -0,0 +1,44 @@
+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 LiveGuideScheduleMetricsTest {
+ private val scheduledChannel = Channel(id = 1L, name = "Scheduled", epgChannelId = "scheduled")
+ private val missingChannel = Channel(id = 2L, name = "Missing", epgChannelId = "missing")
+ private val scheduledProgram = Program(
+ channelId = "scheduled",
+ title = "News",
+ startTime = 100L,
+ endTime = 200L
+ )
+
+ @Test
+ fun `schedule metrics count channels by distinct lookup keys`() {
+ val duplicate = Channel(id = 3L, name = "Duplicate", epgChannelId = "scheduled")
+ val programs = mapOf("scheduled" to listOf(scheduledProgram))
+
+ assertThat(
+ countMissingLiveGuideEntries(
+ channels = listOf(scheduledChannel, duplicate, missingChannel),
+ programsByChannel = programs
+ )
+ ).isEqualTo(1)
+ assertThat(
+ countLiveGuideChannelsWithSchedule(
+ channels = listOf(scheduledChannel, duplicate, missingChannel),
+ programsByChannel = programs
+ )
+ ).isEqualTo(2)
+ }
+
+ @Test
+ fun `upcoming guide data requires a program ending after the window start`() {
+ val programs = mapOf("scheduled" to listOf(scheduledProgram))
+
+ assertThat(hasUpcomingLiveGuideData(programs, windowStart = 150L)).isTrue()
+ assertThat(hasUpcomingLiveGuideData(programs, windowStart = 200L)).isFalse()
+ }
+}