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 category selection

David Nashash6d2d6d9d5d3a
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 ef4807e1..b6d2d911 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
@@ -79,6 +79,7 @@ import com.streamvault.feature.live.presentation.epg.GuideDensity
import com.streamvault.feature.live.presentation.epg.programReminderDeliveryIssueMessage
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 javax.inject.Provider as InjectProvider
data class RecordingConflictInfo(
@@ -2020,34 +2021,13 @@ class EpgViewModel @Inject constructor(
parentalControlLevel: Int,
unlockedCategoryIds: Set<Long>,
fallbackFromEmptyFavorites: Boolean = false
- ): Long {
- val requestedExists = categories.any { it.id == requestedCategoryId }
- if (requestedCategoryId == ChannelRepository.ALL_CHANNELS_ID && requestedExists) {
- return ChannelRepository.ALL_CHANNELS_ID
- }
-
- val requestedCategory = categories.firstOrNull { it.id == requestedCategoryId }
- if (requestedCategory != null && isGuideCategoryAccessible(requestedCategory, parentalControlLevel, unlockedCategoryIds)) {
- if (fallbackFromEmptyFavorites && requestedCategory.id == VirtualCategoryIds.FAVORITES && requestedCategory.count <= 0) {
- return categories.find { it.id == ChannelRepository.ALL_CHANNELS_ID }?.id
- ?: categories.firstOrNull {
- !(it.id == VirtualCategoryIds.FAVORITES && it.count <= 0) &&
- isGuideCategoryAccessible(it, parentalControlLevel, unlockedCategoryIds)
- }?.id
- ?: categories.firstOrNull()?.id
- ?: ChannelRepository.ALL_CHANNELS_ID
- }
- return requestedCategory.id
- }
-
- return categories.firstOrNull { category ->
- if (fallbackFromEmptyFavorites && category.id == VirtualCategoryIds.FAVORITES && category.count <= 0) {
- false
- } else {
- isGuideCategoryAccessible(category, parentalControlLevel, unlockedCategoryIds)
- }
- }?.id ?: categories.firstOrNull()?.id ?: ChannelRepository.ALL_CHANNELS_ID
- }
+ ): Long = resolveLiveGuideCategorySelection(
+ requestedCategoryId = requestedCategoryId,
+ categories = categories,
+ parentalControlLevel = parentalControlLevel,
+ unlockedCategoryIds = unlockedCategoryIds,
+ fallbackFromEmptyFavorites = fallbackFromEmptyFavorites
+ )
private fun isGuideCategoryAccessible(
category: Category,
diff --git a/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md b/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
index 6af80bbb..a5bdb52e 100644
--- a/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
+++ b/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
@@ -141,7 +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 now feature-owned
+and the EPG guide category/channel lock policies and category-selection fallback
+policy now feature-owned
while the Home and EPG
screen/dialog composition remains in `:app` for the remaining app-specific
dialogs.
@@ -156,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, options overlay, and EPG-match dialog are
-independent of app code;
+category/channel lock policies, category-selection fallback policy, 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 1dd6ddee..be4c5467 100644
--- a/docs/superpowers/plans/2026-08-28-live-feature-extraction.md
+++ b/docs/superpowers/plans/2026-08-28-live-feature-extraction.md
@@ -31,7 +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 now feature-owned
+and the EPG guide category/channel lock policies and category-selection fallback
+policy 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.
@@ -735,6 +736,10 @@ predicates while the app supplies current state. EPG guide-channel lock policy
now preserves the existing parental-control level, channel protection, and
source-category protection behind feature-owned pure predicates; `EpgScreen`
keeps its compatibility wrappers while supplying current state.
+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.
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/LiveGuideCategorySelection.kt b/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveGuideCategorySelection.kt
new file mode 100644
index 00000000..a7b69076
--- /dev/null
+++ b/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveGuideCategorySelection.kt
@@ -0,0 +1,48 @@
+package com.streamvault.feature.live.presentation.epg
+
+import com.streamvault.domain.model.Category
+import com.streamvault.domain.model.VirtualCategoryIds
+import com.streamvault.domain.repository.ChannelRepository
+
+fun resolveLiveGuideCategorySelection(
+ requestedCategoryId: Long,
+ categories: List<Category>,
+ parentalControlLevel: Int,
+ unlockedCategoryIds: Set<Long>,
+ fallbackFromEmptyFavorites: Boolean = false
+): Long {
+ val requestedExists = categories.any { it.id == requestedCategoryId }
+ if (requestedCategoryId == ChannelRepository.ALL_CHANNELS_ID && requestedExists) {
+ return ChannelRepository.ALL_CHANNELS_ID
+ }
+
+ val requestedCategory = categories.firstOrNull { it.id == requestedCategoryId }
+ if (requestedCategory != null &&
+ isLiveGuideCategoryAccessible(requestedCategory, parentalControlLevel, unlockedCategoryIds)
+ ) {
+ if (fallbackFromEmptyFavorites &&
+ requestedCategory.id == VirtualCategoryIds.FAVORITES &&
+ requestedCategory.count <= 0
+ ) {
+ return categories.find { it.id == ChannelRepository.ALL_CHANNELS_ID }?.id
+ ?: categories.firstOrNull {
+ !(it.id == VirtualCategoryIds.FAVORITES && it.count <= 0) &&
+ isLiveGuideCategoryAccessible(it, parentalControlLevel, unlockedCategoryIds)
+ }?.id
+ ?: categories.firstOrNull()?.id
+ ?: ChannelRepository.ALL_CHANNELS_ID
+ }
+ return requestedCategory.id
+ }
+
+ return categories.firstOrNull { category ->
+ if (fallbackFromEmptyFavorites &&
+ category.id == VirtualCategoryIds.FAVORITES &&
+ category.count <= 0
+ ) {
+ false
+ } else {
+ isLiveGuideCategoryAccessible(category, parentalControlLevel, unlockedCategoryIds)
+ }
+ }?.id ?: categories.firstOrNull()?.id ?: ChannelRepository.ALL_CHANNELS_ID
+}
diff --git a/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideCategorySelectionTest.kt b/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideCategorySelectionTest.kt
new file mode 100644
index 00000000..dd87437a
--- /dev/null
+++ b/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideCategorySelectionTest.kt
@@ -0,0 +1,60 @@
+package com.streamvault.feature.live.presentation.epg
+
+import com.google.common.truth.Truth.assertThat
+import com.streamvault.domain.model.Category
+import com.streamvault.domain.model.VirtualCategoryIds
+import com.streamvault.domain.repository.ChannelRepository
+import org.junit.Test
+
+class LiveGuideCategorySelectionTest {
+ private val allChannels = Category(
+ id = ChannelRepository.ALL_CHANNELS_ID,
+ name = "All channels",
+ isVirtual = true
+ )
+ private val favorites = Category(
+ id = VirtualCategoryIds.FAVORITES,
+ name = "Favorites",
+ isVirtual = true,
+ count = 0
+ )
+ private val general = Category(id = 10L, name = "General")
+ private val protected = Category(id = 20L, name = "Protected", isAdult = true)
+
+ @Test
+ fun `empty favorite startup falls back to all channels`() {
+ assertThat(
+ resolveLiveGuideCategorySelection(
+ requestedCategoryId = VirtualCategoryIds.FAVORITES,
+ categories = listOf(allChannels, favorites, general),
+ parentalControlLevel = 0,
+ unlockedCategoryIds = emptySet(),
+ fallbackFromEmptyFavorites = true
+ )
+ ).isEqualTo(ChannelRepository.ALL_CHANNELS_ID)
+ }
+
+ @Test
+ fun `protected selection falls back to accessible category`() {
+ assertThat(
+ resolveLiveGuideCategorySelection(
+ requestedCategoryId = protected.id,
+ categories = listOf(allChannels, general, protected),
+ parentalControlLevel = 2,
+ unlockedCategoryIds = emptySet()
+ )
+ ).isEqualTo(ChannelRepository.ALL_CHANNELS_ID)
+ }
+
+ @Test
+ fun `explicitly unlocked protected selection is retained`() {
+ assertThat(
+ resolveLiveGuideCategorySelection(
+ requestedCategoryId = protected.id,
+ categories = listOf(allChannels, general, protected),
+ parentalControlLevel = 2,
+ unlockedCategoryIds = setOf(protected.id)
+ )
+ ).isEqualTo(protected.id)
+ }
+}