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 access policy

David Nashashc89575512ca9
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 838ba75f..d26c2eef 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
@@ -36,7 +36,6 @@ import com.streamvault.domain.manager.RecordingManager
import com.streamvault.domain.usecase.GetCustomCategories
import com.streamvault.domain.usecase.ScheduleRecording
import com.streamvault.domain.usecase.ScheduleRecordingCommand
-import com.streamvault.domain.util.AdultContentVisibilityPolicy
import com.streamvault.data.preferences.PreferencesRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Deferred
@@ -78,6 +77,7 @@ import com.streamvault.feature.live.presentation.epg.shiftGuideAnchorByDays
import com.streamvault.feature.live.presentation.epg.GuideChannelMode
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 javax.inject.Provider as InjectProvider
data class RecordingConflictInfo(
@@ -2053,14 +2053,7 @@ class EpgViewModel @Inject constructor(
category: Category,
parentalControlLevel: Int,
unlockedCategoryIds: Set<Long>
- ): Boolean {
- // Non-adult/protected categories are always accessible
- if (!category.isAdult && !category.isUserProtected) return true
- // Adult/protected: accessible if level permits aggregated surfaces (OFF or LOCKED),
- // OR if the user has explicitly unlocked this category
- return AdultContentVisibilityPolicy.showInAggregatedSurfaces(parentalControlLevel) ||
- unlockedCategoryIds.contains(category.id)
- }
+ ): Boolean = isLiveGuideCategoryAccessible(category, parentalControlLevel, unlockedCategoryIds)
}
private data class GuidePresentationState(
diff --git a/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveGuideLockPolicy.kt b/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveGuideLockPolicy.kt
index edbc8d53..4ecb9e99 100644
--- a/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveGuideLockPolicy.kt
+++ b/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveGuideLockPolicy.kt
@@ -2,10 +2,23 @@ package com.streamvault.feature.live.presentation.epg
import com.streamvault.domain.model.Category
import com.streamvault.domain.model.Channel
+import com.streamvault.domain.util.AdultContentVisibilityPolicy
fun isLiveGuideCategoryLocked(category: Category, parentalControlLevel: Int): Boolean =
parentalControlLevel in 1..2 && (category.isAdult || category.isUserProtected)
+fun isLiveGuideCategoryAccessible(
+ category: Category,
+ parentalControlLevel: Int,
+ unlockedCategoryIds: Set<Long>
+): Boolean {
+ if (!category.isAdult && !category.isUserProtected) {
+ return true
+ }
+ return AdultContentVisibilityPolicy.showInAggregatedSurfaces(parentalControlLevel) ||
+ category.id in unlockedCategoryIds
+}
+
fun isLiveGuideChannelLocked(
channel: Channel,
categoriesById: Map<Long, Category>,
diff --git a/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideLockPolicyTest.kt b/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideLockPolicyTest.kt
index 9918d3df..a99307d7 100644
--- a/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideLockPolicyTest.kt
+++ b/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideLockPolicyTest.kt
@@ -14,6 +14,26 @@ class LiveGuideLockPolicyTest {
assertThat(isLiveGuideCategoryLocked(protectedCategory, parentalControlLevel = 0)).isFalse()
}
+ @Test
+ fun `guide category access allows explicit unlock at private or hidden levels`() {
+ val protectedCategory = Category(id = 4L, name = "Protected", isAdult = true)
+
+ assertThat(
+ isLiveGuideCategoryAccessible(
+ category = protectedCategory,
+ parentalControlLevel = 2,
+ unlockedCategoryIds = emptySet()
+ )
+ ).isFalse()
+ assertThat(
+ isLiveGuideCategoryAccessible(
+ category = protectedCategory,
+ parentalControlLevel = 2,
+ unlockedCategoryIds = setOf(protectedCategory.id)
+ )
+ ).isTrue()
+ }
+
@Test
fun `guide channel is locked by its own protection or source category`() {
val protectedCategory = Category(id = 4L, name = "Protected", isAdult = true)