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 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.ktindex 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.RecordingManagerimport com.streamvault.domain.usecase.GetCustomCategoriesimport com.streamvault.domain.usecase.ScheduleRecordingimport com.streamvault.domain.usecase.ScheduleRecordingCommand-import com.streamvault.domain.util.AdultContentVisibilityPolicyimport com.streamvault.data.preferences.PreferencesRepositoryimport dagger.hilt.android.lifecycle.HiltViewModelimport kotlinx.coroutines.Deferred@@ -78,6 +77,7 @@ import com.streamvault.feature.live.presentation.epg.shiftGuideAnchorByDaysimport com.streamvault.feature.live.presentation.epg.GuideChannelModeimport com.streamvault.feature.live.presentation.epg.GuideDensityimport com.streamvault.feature.live.presentation.epg.programReminderDeliveryIssueMessage+import com.streamvault.feature.live.presentation.epg.isLiveGuideCategoryAccessibleimport javax.inject.Provider as InjectProviderdata 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.ktindex 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.epgimport com.streamvault.domain.model.Categoryimport com.streamvault.domain.model.Channel+import com.streamvault.domain.util.AdultContentVisibilityPolicyfun 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.ktindex 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()+ }+@Testfun `guide channel is locked by its own protection or source category`() {val protectedCategory = Category(id = 4L, name = "Protected", isAdult = true)