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 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.ktindex 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.GuideDensityimport com.streamvault.feature.live.presentation.epg.programReminderDeliveryIssueMessageimport com.streamvault.feature.live.presentation.epg.isLiveGuideCategoryAccessibleimport com.streamvault.feature.live.presentation.epg.matchesLiveGuideMetadataSearch+import com.streamvault.feature.live.presentation.epg.resolveLiveGuideCategorySelectionimport javax.inject.Provider as InjectProviderdata 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.mdindex 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, gridrows/cells, grid host, EPG content host, focus reconciliation, Home layoutmetrics, and Home parental-lock policy are now feature-owned, with the optionsoverlay 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-ownedwhile the Home and EPGscreen/dialog composition remains in `:app` for the remaining app-specificdialogs.@@ -156,7 +157,7 @@ compact 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, focusreconciliation, 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 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 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, gridrows/cells, grid host, EPG content host, focus reconciliation, Home layoutmetrics, and Home parental-lock policy are now feature-owned, with the optionsoverlay 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-ownedand their feature checks are green. Home screen/dialog composition, theremaining live cards/rows, complete locale resource migration, and acceptancegates remain open.@@ -735,6 +736,10 @@ predicates while the app supplies current state. EPG guide-channel lock policynow preserves the existing parental-control level, channel protection, andsource-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`. Theremaining app-owned live cards and shell/dialog composition still requirecompatibility 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.ktnew file mode 100644index 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.ktnew file mode 100644index 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)+ }+}