Skip to content

StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.

refactor(system): register feature-owned navigation

David Nashashdcd74f59bff8
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 16ff1299..f9129bc8 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -378,16 +378,12 @@ abstract class VerifyFeatureNavigationBoundaryTask : DefaultTask() {
@TaskAction
fun verify() {
- val expectedFiles = setOf(
- "WelcomeGraph.kt",
- "LiveGraph.kt",
- "SystemGraph.kt"
- )
+ val expectedFiles = setOf("LiveGraph.kt")
val files = sourceRoot.get().asFile.walkTopDown()
.filter { it.isFile && it.extension == "kt" }
.toList()
- check(files.map { it.name }.containsAll(expectedFiles)) {
- "Missing feature graph registrations: ${expectedFiles - files.map { it.name }.toSet()}"
+ check(files.map { it.name }.toSet() == expectedFiles) {
+ "App-local graph registrations must be exactly $expectedFiles, found ${files.map { it.name }}"
}
val violations = files
.filter { source ->
diff --git a/app/src/main/java/com/streamvault/app/navigation/AppNavHost.kt b/app/src/main/java/com/streamvault/app/navigation/AppNavHost.kt
index 8bea1fca..9312eaf3 100644
--- a/app/src/main/java/com/streamvault/app/navigation/AppNavHost.kt
+++ b/app/src/main/java/com/streamvault/app/navigation/AppNavHost.kt
@@ -5,8 +5,6 @@ import androidx.lifecycle.compose.dropUnlessResumed
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import com.streamvault.app.navigation.graph.registerLiveGraph
-import com.streamvault.app.navigation.graph.registerSystemGraph
-import com.streamvault.app.navigation.graph.registerWelcomeGraph
import com.streamvault.app.ui.components.shell.AppNavigationChrome
import com.streamvault.app.ui.components.shell.AppScreenScaffold
import com.streamvault.feature.settings.presentation.BackupImportPreviewDialog
@@ -32,6 +30,9 @@ import com.streamvault.feature.catalog.api.CatalogScaffoldContent
import com.streamvault.feature.catalog.navigation.registerCatalogGraph
import com.streamvault.feature.settings.presentation.DashboardShelfCustomizationDialog
import com.streamvault.domain.model.ContentType
+import com.streamvault.feature.system.api.SystemScaffoldContent
+import com.streamvault.feature.system.navigation.SystemRoutePatterns
+import com.streamvault.feature.system.navigation.registerSystemGraph
@Composable
internal fun AppNavHost(
@@ -51,9 +52,14 @@ internal fun AppNavHost(
NavHost(
navController = navController,
- startDestination = AppRoutePatterns.WELCOME
+ startDestination = SystemRoutePatterns.WELCOME
) {
- registerWelcomeGraph(actions, startupReady, onStartupNavigationRequested)
+ registerSystemGraph(
+ actions = actions,
+ startupReady = startupReady,
+ onStartupNavigationRequested = onStartupNavigationRequested,
+ scaffold = appSystemScaffold(onTopLevelDestinationRequested),
+ )
registerProviderGraph(
actions = actions,
startupReady = startupReady,
@@ -162,10 +168,24 @@ internal fun AppNavHost(
)
}
)
- registerSystemGraph(actions, onTopLevelDestinationRequested)
}
}
+private fun appSystemScaffold(
+ onTopLevelDestinationRequested: (AppDestination) -> Unit,
+): SystemScaffoldContent = { destination, title, subtitle, compactHeader, showScreenHeader, content ->
+ AppScreenScaffold(
+ currentRoute = AppRouteCodec.encode(destination),
+ onNavigate = { route -> AppRouteCodec.decode(route)?.let(onTopLevelDestinationRequested) },
+ title = title,
+ subtitle = subtitle,
+ navigationChrome = AppNavigationChrome.TopBar,
+ compactHeader = compactHeader,
+ showScreenHeader = showScreenHeader,
+ content = content,
+ )
+}
+
private fun appCatalogScaffold(
onTopLevelDestinationRequested: (AppDestination) -> Unit
): CatalogScaffoldContent = { currentDestination, title, subtitle, chrome, topBarVisible, compactHeader, showScreenHeader, content ->
diff --git a/app/src/main/java/com/streamvault/app/navigation/AppRouteCodec.kt b/app/src/main/java/com/streamvault/app/navigation/AppRouteCodec.kt
index 9ac621c7..81dff977 100644
--- a/app/src/main/java/com/streamvault/app/navigation/AppRouteCodec.kt
+++ b/app/src/main/java/com/streamvault/app/navigation/AppRouteCodec.kt
@@ -7,22 +7,23 @@ import com.streamvault.core.navigation.AppDestination
import com.streamvault.feature.playback.navigation.PlaybackRoutePatterns
import com.streamvault.feature.live.navigation.LiveRoutePatterns
import com.streamvault.feature.catalog.navigation.CatalogRoutePatterns
+import com.streamvault.feature.system.navigation.SystemRoutePatterns
import java.net.URLDecoder
internal object AppRoutePatterns {
- const val WELCOME = "welcome"
+ const val WELCOME = SystemRoutePatterns.WELCOME
const val HOME = CatalogRoutePatterns.HOME
const val LIVE_TV = LiveRoutePatterns.LIVE_TV
const val LIVE_TV_DESTINATION = LiveRoutePatterns.LIVE_TV_DESTINATION
const val MOVIES = CatalogRoutePatterns.MOVIES
const val SERIES = CatalogRoutePatterns.SERIES
const val VOD = CatalogRoutePatterns.VOD
- const val DOWNLOADS = "downloads"
+ const val DOWNLOADS = SystemRoutePatterns.DOWNLOADS
const val EPG = LiveRoutePatterns.EPG
const val EPG_DESTINATION = LiveRoutePatterns.EPG_DESTINATION
const val SETTINGS = "settings"
const val SETTINGS_DESTINATION = "settings?backupUri={backupUri}"
- const val PLUGINS = "plugins"
+ const val PLUGINS = SystemRoutePatterns.PLUGINS
const val PLAYER = PlaybackRoutePatterns.PLAYER
const val SEARCH = CatalogRoutePatterns.SEARCH
const val SEARCH_DESTINATION = CatalogRoutePatterns.SEARCH_DESTINATION
diff --git a/app/src/main/java/com/streamvault/app/navigation/graph/SystemGraph.kt b/app/src/main/java/com/streamvault/app/navigation/graph/SystemGraph.kt
deleted file mode 100644
index 5b79b103..00000000
--- a/app/src/main/java/com/streamvault/app/navigation/graph/SystemGraph.kt
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.streamvault.app.navigation.graph
-
-import androidx.navigation.NavGraphBuilder
-import androidx.navigation.compose.composable
-import com.streamvault.app.navigation.AppRouteCodec
-import com.streamvault.app.navigation.AppRoutePatterns
-import com.streamvault.app.ui.components.shell.AppNavigationChrome
-import com.streamvault.app.ui.components.shell.AppScreenScaffold
-import com.streamvault.core.navigation.AppDestination
-import com.streamvault.core.navigation.NavigationActions
-import com.streamvault.feature.system.api.SystemScaffoldContent
-import com.streamvault.feature.system.presentation.downloads.DownloadsScreen
-import com.streamvault.feature.system.presentation.plugins.PluginsScreen
-
-internal fun NavGraphBuilder.registerSystemGraph(
- actions: NavigationActions,
- onTopLevelDestinationRequested: (AppDestination) -> Unit
-) {
- composable(AppRoutePatterns.DOWNLOADS) {
- DownloadsScreen(
- scaffold = appSystemScaffold(onTopLevelDestinationRequested)
- )
- }
-
- composable(AppRoutePatterns.PLUGINS) {
- PluginsScreen(
- scaffold = appSystemScaffold(onTopLevelDestinationRequested)
- )
- }
-
-}
-
-private fun appSystemScaffold(
- onTopLevelDestinationRequested: (AppDestination) -> Unit
-): SystemScaffoldContent = { currentDestination, title, subtitle, compactHeader, showScreenHeader, content ->
- AppScreenScaffold(
- currentRoute = AppRouteCodec.encode(currentDestination),
- onNavigate = { route -> AppRouteCodec.decode(route)?.let(onTopLevelDestinationRequested) },
- title = title,
- subtitle = subtitle,
- navigationChrome = AppNavigationChrome.TopBar,
- compactHeader = compactHeader,
- showScreenHeader = showScreenHeader,
- content = content
- )
-}
diff --git a/app/src/test/java/com/streamvault/app/navigation/AppRouteCodecTest.kt b/app/src/test/java/com/streamvault/app/navigation/AppRouteCodecTest.kt
index 390d1b50..83c8045e 100644
--- a/app/src/test/java/com/streamvault/app/navigation/AppRouteCodecTest.kt
+++ b/app/src/test/java/com/streamvault/app/navigation/AppRouteCodecTest.kt
@@ -2,6 +2,7 @@ package com.streamvault.app.navigation
import com.google.common.truth.Truth.assertThat
import com.streamvault.core.navigation.AppDestination
+import com.streamvault.feature.system.navigation.SystemRoutePatterns
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@@ -16,6 +17,9 @@ class AppRouteCodecTest {
AppDestination.Guide(21L, 1_700_000_000_000L, true) to
"epg?categoryId=21&anchorTime=1700000000000&favoritesOnly=true",
AppDestination.Search("night shift") to "search?query=night%20shift",
+ AppDestination.Welcome to SystemRoutePatterns.WELCOME,
+ AppDestination.Downloads to SystemRoutePatterns.DOWNLOADS,
+ AppDestination.Plugins to SystemRoutePatterns.PLUGINS,
AppDestination.ProviderSetup(7L, "content://playlist/1") to
"provider_setup?providerId=7&importUri=content%3A%2F%2Fplaylist%2F1"
)
diff --git a/app/src/test/java/com/streamvault/app/navigation/FeatureGraphBoundaryTest.kt b/app/src/test/java/com/streamvault/app/navigation/FeatureGraphBoundaryTest.kt
index ade07ccb..4d66687e 100644
--- a/app/src/test/java/com/streamvault/app/navigation/FeatureGraphBoundaryTest.kt
+++ b/app/src/test/java/com/streamvault/app/navigation/FeatureGraphBoundaryTest.kt
@@ -10,12 +10,12 @@ class FeatureGraphBoundaryTest {
val graphRoots = listOf(
File("src/main/java/com/streamvault/app/navigation/graph"),
File("../feature/provider/src/main/java/com/streamvault/feature/provider/navigation"),
- File("../feature/catalog/src/main/java/com/streamvault/feature/catalog/navigation")
+ File("../feature/catalog/src/main/java/com/streamvault/feature/catalog/navigation"),
+ File("../feature/system/src/main/java/com/streamvault/feature/system/navigation")
)
val files = graphRoots
.flatMap { root -> root.walkTopDown().filter { it.extension == "kt" }.toList() }
assertThat(files.map { it.name }).containsAtLeast(
- "WelcomeGraph.kt",
"ProviderGraph.kt",
"LiveGraph.kt",
"CatalogGraph.kt",
diff --git a/feature/system/src/androidTest/java/com/streamvault/feature/system/navigation/SystemRouteGraphBehaviorTest.kt b/feature/system/src/androidTest/java/com/streamvault/feature/system/navigation/SystemRouteGraphBehaviorTest.kt
new file mode 100644
index 00000000..5793992b
--- /dev/null
+++ b/feature/system/src/androidTest/java/com/streamvault/feature/system/navigation/SystemRouteGraphBehaviorTest.kt
@@ -0,0 +1,73 @@
+package com.streamvault.feature.system.navigation
+
+import androidx.compose.foundation.layout.Column
+import androidx.compose.runtime.remember
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.test.junit4.createComposeRule
+import androidx.navigation.compose.ComposeNavigator
+import androidx.navigation.createGraph
+import androidx.navigation.testing.TestNavHostController
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.streamvault.core.navigation.AppDestination
+import com.streamvault.core.navigation.NavigationActions
+import com.streamvault.core.navigation.NavigationOptions
+import com.streamvault.core.navigation.PlayerNavigationRequest
+import com.streamvault.feature.system.api.SystemScaffoldContent
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class SystemRouteGraphBehaviorTest {
+ @get:Rule
+ val composeRule = createComposeRule()
+
+ @Test
+ fun systemGraphRegistersWelcomeDownloadsAndPlugins() {
+ lateinit var navController: TestNavHostController
+
+ composeRule.setContent {
+ val context = LocalContext.current
+ navController = remember(context) {
+ TestNavHostController(context).apply {
+ navigatorProvider.addNavigator(ComposeNavigator())
+ graph = createGraph(startDestination = SystemRoutePatterns.WELCOME) {
+ registerSystemGraph(
+ actions = recordingActions(),
+ startupReady = true,
+ onStartupNavigationRequested = {},
+ scaffold = testScaffold,
+ )
+ }
+ }
+ }
+ }
+
+ composeRule.runOnIdle {
+ navController.navigate(SystemRoutePatterns.DOWNLOADS)
+ check(navController.currentBackStackEntry?.destination?.route == SystemRoutePatterns.DOWNLOADS)
+ }
+ composeRule.waitForIdle()
+ composeRule.runOnIdle {
+ navController.navigate(SystemRoutePatterns.PLUGINS)
+ check(navController.currentBackStackEntry?.destination?.route == SystemRoutePatterns.PLUGINS)
+ }
+ composeRule.waitForIdle()
+
+ check(navController.currentBackStackEntry?.destination?.route == SystemRoutePatterns.PLUGINS)
+ }
+
+ private val testScaffold: SystemScaffoldContent = { _, _, _, _, _, content ->
+ Column { content() }
+ }
+
+ private fun recordingActions() = object : NavigationActions {
+ override fun navigate(destination: AppDestination, options: NavigationOptions) = Unit
+
+ override fun openPlayer(request: PlayerNavigationRequest) = Unit
+
+ override fun back(): Boolean = true
+
+ override fun returnTo(destination: AppDestination?): Boolean = true
+ }
+}
diff --git a/app/src/main/java/com/streamvault/app/navigation/graph/WelcomeGraph.kt b/feature/system/src/main/java/com/streamvault/feature/system/navigation/SystemGraph.kt
similarity index 56%
rename from app/src/main/java/com/streamvault/app/navigation/graph/WelcomeGraph.kt
rename to feature/system/src/main/java/com/streamvault/feature/system/navigation/SystemGraph.kt
index 21b2060d..e64a5f0d 100644
--- a/app/src/main/java/com/streamvault/app/navigation/graph/WelcomeGraph.kt
+++ b/feature/system/src/main/java/com/streamvault/feature/system/navigation/SystemGraph.kt
@@ -1,20 +1,23 @@
-package com.streamvault.app.navigation.graph
+package com.streamvault.feature.system.navigation
import androidx.lifecycle.compose.dropUnlessResumed
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
-import com.streamvault.app.navigation.AppRoutePatterns
-import com.streamvault.feature.system.presentation.welcome.WelcomeScreen
import com.streamvault.core.navigation.AppDestination
import com.streamvault.core.navigation.NavigationActions
import com.streamvault.core.navigation.NavigationOptions
+import com.streamvault.feature.system.api.SystemScaffoldContent
+import com.streamvault.feature.system.presentation.downloads.DownloadsScreen
+import com.streamvault.feature.system.presentation.plugins.PluginsScreen
+import com.streamvault.feature.system.presentation.welcome.WelcomeScreen
-internal fun NavGraphBuilder.registerWelcomeGraph(
+fun NavGraphBuilder.registerSystemGraph(
actions: NavigationActions,
startupReady: Boolean,
- onStartupNavigationRequested: (AppDestination) -> Unit
+ onStartupNavigationRequested: (AppDestination) -> Unit,
+ scaffold: SystemScaffoldContent,
) {
- composable(AppRoutePatterns.WELCOME) {
+ composable(SystemRoutePatterns.WELCOME) {
WelcomeScreen(
onNavigateToHome = dropUnlessResumed {
onStartupNavigationRequested(AppDestination.Welcome)
@@ -23,9 +26,15 @@ internal fun NavGraphBuilder.registerWelcomeGraph(
onNavigateToSetup = dropUnlessResumed {
actions.navigate(
AppDestination.ProviderSetup(),
- NavigationOptions(popUpTo = AppDestination.Welcome, inclusive = true)
+ NavigationOptions(popUpTo = AppDestination.Welcome, inclusive = true),
)
- }
+ },
)
}
+ composable(SystemRoutePatterns.DOWNLOADS) {
+ DownloadsScreen(scaffold = scaffold)
+ }
+ composable(SystemRoutePatterns.PLUGINS) {
+ PluginsScreen(scaffold = scaffold)
+ }
}
diff --git a/feature/system/src/main/java/com/streamvault/feature/system/navigation/SystemRoutePatterns.kt b/feature/system/src/main/java/com/streamvault/feature/system/navigation/SystemRoutePatterns.kt
index 495ccc54..30420391 100644
--- a/feature/system/src/main/java/com/streamvault/feature/system/navigation/SystemRoutePatterns.kt
+++ b/feature/system/src/main/java/com/streamvault/feature/system/navigation/SystemRoutePatterns.kt
@@ -5,3 +5,9 @@ object SystemRoutePatterns {
const val DOWNLOADS = "downloads"
const val PLUGINS = "plugins"
}
+
+internal fun systemGraphRoutes(): List<String> = listOf(
+ SystemRoutePatterns.WELCOME,
+ SystemRoutePatterns.DOWNLOADS,
+ SystemRoutePatterns.PLUGINS,
+)
diff --git a/feature/system/src/test/java/com/streamvault/feature/system/navigation/SystemGraphTest.kt b/feature/system/src/test/java/com/streamvault/feature/system/navigation/SystemGraphTest.kt
new file mode 100644
index 00000000..d08ceb9e
--- /dev/null
+++ b/feature/system/src/test/java/com/streamvault/feature/system/navigation/SystemGraphTest.kt
@@ -0,0 +1,15 @@
+package com.streamvault.feature.system.navigation
+
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+
+class SystemGraphTest {
+ @Test
+ fun systemGraphRouteSetPreservesExistingDestinations() {
+ assertThat(systemGraphRoutes()).containsExactly(
+ "welcome",
+ "downloads",
+ "plugins",
+ ).inOrder()
+ }
+}