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 home lock policy

David Nashasha71ec037c77c
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt
index 185e63ec..ae5db4da 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt
@@ -56,6 +56,8 @@ import com.streamvault.core.ui.components.dialogs.PremiumDialogFooterButton
import com.streamvault.app.ui.components.dialogs.RenameGroupDialog
import com.streamvault.feature.live.presentation.components.LiveReorderTopBar
import com.streamvault.feature.live.presentation.home.liveHomeLayoutMetrics
+import com.streamvault.feature.live.presentation.home.isLiveHomeCategoryLocked
+import com.streamvault.feature.live.presentation.home.isLiveHomeChannelLocked
import com.streamvault.app.ui.components.shell.AppNavigationChrome
import com.streamvault.app.ui.components.shell.AppScreenScaffold
import com.streamvault.core.ui.design.FocusRestoreHost
@@ -340,11 +342,7 @@ fun HomeScreen(
.toList()
}
val isCategoryLocked: (Category) -> Boolean = remember(uiState.parentalControlLevel, uiState.unlockedCategoryIds) {
- { category ->
- (category.isAdult || category.isUserProtected) &&
- uiState.parentalControlLevel in 1..2 &&
- kotlin.math.abs(category.id) !in uiState.unlockedCategoryIds
- }
+ { category -> isLiveHomeCategoryLocked(category, uiState.parentalControlLevel, uiState.unlockedCategoryIds) }
}
val isChannelLocked: (Channel) -> Boolean = remember(
uiState.parentalControlLevel,
@@ -355,24 +353,13 @@ fun HomeScreen(
uiState.selectedCategory?.isUserProtected
) {
{ channel ->
- val selectedCategory = uiState.selectedCategory
- val channelCategoryId = channel.categoryId
- val sourceCategory = uiState.categories.firstOrNull { it.id == channelCategoryId }
- val unlockedByChannelCategory =
- channelCategoryId != null && kotlin.math.abs(channelCategoryId) in uiState.unlockedCategoryIds
- val unlockedBySelectedCategory =
- selectedCategory != null && kotlin.math.abs(selectedCategory.id) in uiState.unlockedCategoryIds
- val unlocked = unlockedByChannelCategory || unlockedBySelectedCategory
- (
- channel.isAdult ||
- channel.isUserProtected ||
- (selectedCategory?.isAdult == true) ||
- (selectedCategory?.isUserProtected == true) ||
- (sourceCategory?.isAdult == true) ||
- (sourceCategory?.isUserProtected == true)
- ) &&
- uiState.parentalControlLevel in 1..2 &&
- !unlocked
+ isLiveHomeChannelLocked(
+ channel = channel,
+ categories = uiState.categories,
+ selectedCategory = uiState.selectedCategory,
+ parentalControlLevel = uiState.parentalControlLevel,
+ unlockedCategoryIds = uiState.unlockedCategoryIds
+ )
}
}
val unlockedVisibleCategories = remember(
diff --git a/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md b/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
index d27c1a03..90127ddb 100644
--- a/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
+++ b/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
@@ -138,9 +138,9 @@ quick-filter add dialog, delete-group dialog, rename-group dialog, M3U category
organizer dialog, M3U series-assignment dialogs, EPG search overlay, guide
category picker, compact guide-program dialog, guide control rows, EPG preview
pane, guide toolbar, guide message state, hero badge, timeline header, grid
-rows/cells, grid host, EPG content host, focus reconciliation, and Home layout
-metrics are now feature-owned, with the options overlay and EPG-match dialog
-also feature-owned
+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
while the Home and EPG
screen/dialog composition remains in `:app` for the remaining app-specific
dialogs.
@@ -154,7 +154,7 @@ series-assignment dialogs, the EPG search overlay, guide category picker, and
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, options overlay, and EPG-match dialog are
-independent of app code;
+reconciliation, Home layout metrics, Home parental-lock 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 82ac5952..75fcdf33 100644
--- a/docs/superpowers/plans/2026-08-28-live-feature-extraction.md
+++ b/docs/superpowers/plans/2026-08-28-live-feature-extraction.md
@@ -28,9 +28,9 @@ quick-filter add dialog, delete-group dialog, rename-group dialog, M3U category
organizer dialog, M3U series-assignment dialogs, EPG search overlay, guide
category picker, compact guide-program dialog, guide control rows, EPG preview
pane, guide toolbar, guide message state, hero badge, timeline header, grid
-rows/cells, grid host, EPG content host, focus reconciliation, and Home layout
-metrics are now feature-owned, with the options overlay and EPG-match dialog
-also feature-owned
+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 their feature checks are green. Home screen/dialog composition, the
remaining live cards/rows, complete locale resource migration, and acceptance
gates remain open.
@@ -728,7 +728,9 @@ overlay and EPG-match dialog likewise own their presentation and focus behavior
while the app supplies localized labels and state/action callbacks.
Home layout metrics now preserve the existing device/mode breakpoints behind a
feature-owned pure contract while `HomeScreen` supplies the configuration and
-device inputs.
+device inputs. Home parental-lock policy likewise preserves normalized unlock
+IDs and selected/source-category protection behind feature-owned pure
+predicates while the app supplies current state.
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/home/LiveHomeLockPolicy.kt b/feature/live/src/main/java/com/streamvault/feature/live/presentation/home/LiveHomeLockPolicy.kt
new file mode 100644
index 00000000..43851515
--- /dev/null
+++ b/feature/live/src/main/java/com/streamvault/feature/live/presentation/home/LiveHomeLockPolicy.kt
@@ -0,0 +1,40 @@
+package com.streamvault.feature.live.presentation.home
+
+import com.streamvault.domain.model.Category
+import com.streamvault.domain.model.Channel
+import kotlin.math.abs
+
+fun isLiveHomeCategoryLocked(
+ category: Category,
+ parentalControlLevel: Int,
+ unlockedCategoryIds: Set<Long>
+): Boolean =
+ (category.isAdult || category.isUserProtected) &&
+ parentalControlLevel in 1..2 &&
+ abs(category.id) !in unlockedCategoryIds
+
+fun isLiveHomeChannelLocked(
+ channel: Channel,
+ categories: List<Category>,
+ selectedCategory: Category?,
+ parentalControlLevel: Int,
+ unlockedCategoryIds: Set<Long>
+): Boolean {
+ val channelCategoryId = channel.categoryId
+ val sourceCategory = categories.firstOrNull { it.id == channelCategoryId }
+ val unlockedByChannelCategory =
+ channelCategoryId != null && abs(channelCategoryId) in unlockedCategoryIds
+ val unlockedBySelectedCategory =
+ selectedCategory != null && abs(selectedCategory.id) in unlockedCategoryIds
+ val unlocked = unlockedByChannelCategory || unlockedBySelectedCategory
+ return (
+ channel.isAdult ||
+ channel.isUserProtected ||
+ selectedCategory?.isAdult == true ||
+ selectedCategory?.isUserProtected == true ||
+ sourceCategory?.isAdult == true ||
+ sourceCategory?.isUserProtected == true
+ ) &&
+ parentalControlLevel in 1..2 &&
+ !unlocked
+}
diff --git a/feature/live/src/test/java/com/streamvault/feature/live/presentation/home/LiveHomeLockPolicyTest.kt b/feature/live/src/test/java/com/streamvault/feature/live/presentation/home/LiveHomeLockPolicyTest.kt
new file mode 100644
index 00000000..fbfeb1cb
--- /dev/null
+++ b/feature/live/src/test/java/com/streamvault/feature/live/presentation/home/LiveHomeLockPolicyTest.kt
@@ -0,0 +1,43 @@
+package com.streamvault.feature.live.presentation.home
+
+import com.google.common.truth.Truth.assertThat
+import com.streamvault.domain.model.Category
+import com.streamvault.domain.model.Channel
+import org.junit.Test
+
+class LiveHomeLockPolicyTest {
+ @Test
+ fun `adult category is locked until its normalized id is unlocked`() {
+ val category = Category(id = -7L, name = "Adult", isAdult = true)
+
+ assertThat(isLiveHomeCategoryLocked(category, 1, emptySet())).isTrue()
+ assertThat(isLiveHomeCategoryLocked(category, 1, setOf(7L))).isFalse()
+ assertThat(isLiveHomeCategoryLocked(category, 0, emptySet())).isFalse()
+ }
+
+ @Test
+ fun `channel uses selected or source category protection`() {
+ val sourceCategory = Category(id = 4L, name = "Source", isUserProtected = true)
+ val selectedCategory = Category(id = 5L, name = "Selected")
+ val channel = Channel(id = 9L, name = "Channel", categoryId = 4L)
+
+ assertThat(
+ isLiveHomeChannelLocked(
+ channel = channel,
+ categories = listOf(sourceCategory, selectedCategory),
+ selectedCategory = selectedCategory,
+ parentalControlLevel = 2,
+ unlockedCategoryIds = emptySet()
+ )
+ ).isTrue()
+ assertThat(
+ isLiveHomeChannelLocked(
+ channel = channel,
+ categories = listOf(sourceCategory, selectedCategory),
+ selectedCategory = selectedCategory,
+ parentalControlLevel = 2,
+ unlockedCategoryIds = setOf(4L)
+ )
+ ).isFalse()
+ }
+}