StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.
Kotlin iptv-player
refactor: split app navigation graph registry
David Nashash9bef8a12eb46
diff --git a/app/build.gradle.kts b/app/build.gradle.ktsindex f658cfc2..6479e22f 100644--- a/app/build.gradle.kts+++ b/app/build.gradle.kts@@ -4,7 +4,9 @@ import java.security.KeyStoreimport java.security.MessageDigestimport org.gradle.api.DefaultTaskimport org.gradle.api.file.RegularFileProperty+import org.gradle.api.file.DirectoryPropertyimport org.gradle.api.tasks.InputFile+import org.gradle.api.tasks.InputDirectoryimport org.gradle.api.tasks.OutputFileimport org.gradle.api.tasks.PathSensitiveimport org.gradle.api.tasks.PathSensitivity@@ -183,7 +185,7 @@ android {* are also baseline rules, so keep the maintained baseline source as their union while* preserving startup-prof.txt as the startup-only subset consumed for DEX layout.*/- abstract class MergeStartupRulesIntoBaselineProfileTask : DefaultTask() {+abstract class MergeStartupRulesIntoBaselineProfileTask : DefaultTask() {@get:InputFile@get:PathSensitive(PathSensitivity.RELATIVE)abstract val baselineProfile: RegularFileProperty@@ -339,6 +341,49 @@ android {}}+abstract class VerifyFeatureNavigationBoundaryTask : DefaultTask() {+ @get:InputDirectory+ @get:PathSensitive(PathSensitivity.RELATIVE)+ abstract val sourceRoot: DirectoryProperty++ @TaskAction+ fun verify() {+ val expectedFiles = setOf(+ "WelcomeGraph.kt",+ "ProviderGraph.kt",+ "HomeGraph.kt",+ "LiveGraph.kt",+ "CatalogGraph.kt",+ "PlayerGraph.kt",+ "SystemGraph.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()}"+ }+ val violations = files+ .filter { source ->+ val text = source.readText()+ "NavHostController" in text || "NavController" in text+ }+ .map { it.name }+ check(violations.isEmpty()) {+ "Feature graph registrations must not reference a root navigation controller: $violations"+ }+ }+}++val verifyFeatureNavigationBoundary = tasks.register<VerifyFeatureNavigationBoundaryTask>(+ "verifyFeatureNavigationBoundary"+) {+ sourceRoot.set(layout.projectDirectory.dir("src/main/java/com/streamvault/app/navigation/graph"))+}+tasks.named("check") {+ dependsOn(verifyFeatureNavigationBoundary)+}+kotlin {compilerOptions {jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)diff --git a/app/src/main/java/com/streamvault/app/navigation/AppNavHost.kt b/app/src/main/java/com/streamvault/app/navigation/AppNavHost.ktnew file mode 100644index 00000000..0da27e6f--- /dev/null+++ b/app/src/main/java/com/streamvault/app/navigation/AppNavHost.kt@@ -0,0 +1,43 @@+package com.streamvault.app.navigation++import androidx.compose.runtime.Composable+import androidx.navigation.NavHostController+import androidx.navigation.compose.NavHost+import com.streamvault.app.navigation.graph.registerCatalogGraph+import com.streamvault.app.navigation.graph.registerHomeGraph+import com.streamvault.app.navigation.graph.registerLiveGraph+import com.streamvault.app.navigation.graph.registerPlayerGraph+import com.streamvault.app.navigation.graph.registerProviderGraph+import com.streamvault.app.navigation.graph.registerSystemGraph+import com.streamvault.app.navigation.graph.registerWelcomeGraph+import com.streamvault.core.navigation.AppDestination+import com.streamvault.core.navigation.NavigationActions++@Composable+internal fun AppNavHost(+ navController: NavHostController,+ actions: NavigationActions,+ catalogDetailActions: CatalogDetailNavigationActions,+ payloads: AppNavigationPayloads,+ startupReady: Boolean,+ onStartupNavigationRequested: (popUpTo: AppDestination) -> Unit,+ onTopLevelDestinationRequested: (AppDestination) -> Unit+) {+ NavHost(+ navController = navController,+ startDestination = AppRoutePatterns.WELCOME+ ) {+ registerWelcomeGraph(actions, startupReady, onStartupNavigationRequested)+ registerProviderGraph(actions, startupReady, onStartupNavigationRequested)+ registerHomeGraph(actions, catalogDetailActions, onTopLevelDestinationRequested)+ registerLiveGraph(actions, onTopLevelDestinationRequested)+ registerCatalogGraph(+ actions,+ catalogDetailActions,+ payloads,+ onTopLevelDestinationRequested+ )+ registerPlayerGraph(actions, payloads)+ registerSystemGraph(actions, onTopLevelDestinationRequested)+ }+}diff --git a/app/src/main/java/com/streamvault/app/navigation/AppNavigation.kt b/app/src/main/java/com/streamvault/app/navigation/AppNavigation.ktindex 9ca8078e..ecc08035 100644--- a/app/src/main/java/com/streamvault/app/navigation/AppNavigation.kt+++ b/app/src/main/java/com/streamvault/app/navigation/AppNavigation.kt@@ -201,11 +201,17 @@ fun AppNavigation(mainActivity: MainActivity) {}}- AppNavigationGraph(+ AppNavHost(navController = navController,- navigator = navigator,- startupRoute = startupRoute,- navigateToStartupTarget = { popUpRoute -> navigateToStartupTarget(popUpRoute) },- tabNavigate = { route -> tabNavigate(route) }+ actions = navigator,+ catalogDetailActions = navigator,+ payloads = navigator,+ startupReady = startupRoute != null,+ onStartupNavigationRequested = { popUpDestination ->+ navigateToStartupTarget(AppRouteCodec.encode(popUpDestination))+ },+ onTopLevelDestinationRequested = { destination ->+ tabNavigate(AppRouteCodec.encode(destination))+ })}diff --git a/app/src/main/java/com/streamvault/app/navigation/AppNavigationGraph.kt b/app/src/main/java/com/streamvault/app/navigation/AppNavigationGraph.ktdeleted file mode 100644index f8cfe9a8..00000000--- a/app/src/main/java/com/streamvault/app/navigation/AppNavigationGraph.kt+++ /dev/null@@ -1,501 +0,0 @@-package com.streamvault.app.navigation--import android.net.Uri-import android.util.Log-import androidx.compose.runtime.Composable-import androidx.compose.runtime.LaunchedEffect-import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.produceState-import androidx.compose.runtime.remember-import androidx.compose.runtime.rememberCoroutineScope-import androidx.compose.runtime.setValue-import androidx.lifecycle.Lifecycle-import androidx.lifecycle.LifecycleEventObserver-import androidx.lifecycle.compose.collectAsStateWithLifecycle-import androidx.lifecycle.compose.dropUnlessResumed-import androidx.navigation.NavHostController-import androidx.navigation.NavOptionsBuilder-import androidx.navigation.NavType-import androidx.navigation.compose.NavHost-import androidx.navigation.compose.composable-import androidx.navigation.compose.currentBackStackEntryAsState-import androidx.navigation.compose.rememberNavController-import androidx.navigation.navArgument-import com.streamvault.app.ui.model.isArchivePlayable-import com.streamvault.core.navigation.PlayerNavigationRequest-import com.streamvault.core.navigation.AppDestination-import com.streamvault.core.navigation.NavigationOptions-import com.streamvault.core.navigation.NavigationCommand-import com.streamvault.domain.model.Channel-import com.streamvault.domain.model.Episode-import com.streamvault.domain.model.Movie-import com.streamvault.app.ui.screens.dashboard.DashboardScreen-import com.streamvault.app.ui.screens.multiview.MultiViewScreen-import com.streamvault.app.ui.screens.home.HomeScreen-import com.streamvault.app.ui.screens.movies.MoviesScreen-import com.streamvault.app.ui.screens.player.PlayerScreen-import com.streamvault.app.ui.screens.plugins.PluginsScreen-import com.streamvault.app.ui.screens.provider.ProviderSetupScreen-import com.streamvault.app.ui.screens.series.SeriesScreen-import com.streamvault.app.ui.screens.vod.VodScreen-import com.streamvault.app.ui.screens.settings.SettingsScreen-import com.streamvault.app.ui.screens.welcome.WelcomeScreen-import com.streamvault.app.ui.screens.downloads.DownloadsScreen-import com.streamvault.app.MainActivity-import com.streamvault.domain.model.AppLandingDestination-import com.streamvault.domain.model.AppTopLevelDestination-import com.streamvault.domain.model.ContentType-import com.streamvault.domain.model.CatalogLayout-import com.streamvault.domain.model.ActiveLiveSource-import com.streamvault.domain.model.Series-import com.streamvault.domain.model.VirtualCategoryIds-import java.io.Serializable-import kotlin.coroutines.resume-import kotlinx.coroutines.flow.first-import kotlinx.coroutines.launch-import kotlinx.coroutines.suspendCancellableCoroutine---@Composable-internal fun AppNavigationGraph(- navController: NavHostController,- navigator: NavControllerNavigator,- startupRoute: String?,- navigateToStartupTarget: (String) -> Boolean,- tabNavigate: (String) -> Unit-) {- NavHost(- navController = navController,- startDestination = Routes.WELCOME- ) {- composable(Routes.WELCOME) {- WelcomeScreen(- onNavigateToHome = dropUnlessResumed {- navigateToStartupTarget(Routes.WELCOME)- },- startupReady = startupRoute != null,- onNavigateToSetup = dropUnlessResumed {- navigator.navigateIfResumed(- AppDestination.ProviderSetup(),- NavigationOptions(popUpTo = AppDestination.Welcome, inclusive = true)- )- }- )- }-- composable(- route = Routes.PROVIDER_SETUP,- arguments = listOf(- navArgument("providerId") { type = NavType.LongType; defaultValue = -1L },- navArgument("importUri") { type = NavType.StringType; defaultValue = "" }- )- ) { backStackEntry ->- val providerId = backStackEntry.arguments?.getLong("providerId")?.takeIf { it != -1L }- val importUri = backStackEntry.arguments?.getString("importUri")?.takeIf { it.isNotBlank() }-- ProviderSetupScreen(- editProviderId = providerId,- initialImportUri = importUri,- onBack = { navigator.back() },- onProviderAdded = dropUnlessResumed {- navigateToStartupTarget(Routes.PROVIDER_SETUP)- }- )- }-// ...-- composable(Routes.HOME) {- DashboardScreen(- onNavigate = { route -> tabNavigate(route) },- onAddProvider = dropUnlessResumed {- navigator.navigateIfResumed(AppDestination.ProviderSetup())- },- onRecentChannelClick = { channel, combinedProfileId ->- navigator.openPlayer(- channel.toLivePlayerRequest(- categoryId = com.streamvault.domain.model.VirtualCategoryIds.RECENT,- providerId = channel.providerId,- isVirtual = true,- combinedProfileId = combinedProfileId,- returnDestination = AppDestination.Home- )- )- },- onFavoriteChannelClick = { channel, combinedProfileId ->- navigator.openPlayer(- channel.toLivePlayerRequest(- categoryId = com.streamvault.domain.model.VirtualCategoryIds.FAVORITES,- providerId = channel.providerId,- isVirtual = true,- combinedProfileId = combinedProfileId,- returnDestination = AppDestination.Home- )- )- },- onMovieClick = { movie ->- navigator.openMovieDetail(movie, AppDestination.Home)- },- onSeriesClick = { series ->- navigator.openSeriesDetail(series, AppDestination.Home)- },- onPlaybackHistoryClick = { history ->- val route = when (history.contentType) {- com.streamvault.domain.model.ContentType.LIVE -> {- history.toPlayerNavigationRequest(AppDestination.Home)- }- com.streamvault.domain.model.ContentType.MOVIE,- com.streamvault.domain.model.ContentType.VOD -> {- history.toPlayerNavigationRequest(AppDestination.Home)- }- com.streamvault.domain.model.ContentType.SERIES -> {- Routes.seriesDetail(history.contentId, Routes.HOME)- }- com.streamvault.domain.model.ContentType.SERIES_EPISODE -> {- history.toPlayerNavigationRequest(AppDestination.Home)- }- }- if (route is PlayerNavigationRequest) {- navigator.openPlayer(route)- } else {- AppRouteCodec.decode(route as String)?.let { destination ->- navigator.navigateIfResumed(- destination,- NavigationOptions(launchSingleTop = true)- )- }- }- },- currentRoute = Routes.HOME- )- }-- composable(- route = Routes.LIVE_TV_DESTINATION,- arguments = listOf(- navArgument("categoryId") { type = NavType.LongType; defaultValue = -1L }- )- ) { backStackEntry ->- val initialCategoryId = backStackEntry.arguments?.getLong("categoryId")?.takeIf { it != -1L }- HomeScreen(- onChannelClick = { channel, category, provider, combinedProfileId, combinedSourceFilterProviderId ->- navigator.openPlayer(- channel.toLivePlayerRequest(- categoryId = category?.id,- providerId = provider?.id,- isVirtual = category?.isVirtual == true,- combinedProfileId = combinedProfileId,- combinedSourceFilterProviderId = combinedSourceFilterProviderId,- returnDestination = AppDestination.LiveTv(category?.id)- )- )- },- onNavigate = { route -> tabNavigate(route) },- currentRoute = Routes.LIVE_TV,- initialCategoryId = initialCategoryId- )- }-// ... (rest of file)-- composable(Routes.MOVIES) {- MoviesScreen(- onMovieClick = { movie ->- navigator.openMovieDetail(movie, AppDestination.Movies)- },- onContinueWatchingPlay = { history ->- navigator.openPlayer(- history.toPlayerNavigationRequest().copy(returnDestination = AppDestination.Movies)- )- },- onNavigate = { route -> tabNavigate(route) },- currentRoute = Routes.MOVIES- )- }-- composable(Routes.SERIES) {- SeriesScreen(- onSeriesClick = { series ->- navigator.openSeriesDetail(series, AppDestination.Series)- },- onSeriesIdClick = { seriesId ->- navigator.navigateIfResumed(- AppDestination.SeriesDetail(seriesId, AppDestination.Series),- NavigationOptions(launchSingleTop = true)- )- },- onNavigate = { route -> tabNavigate(route) },- currentRoute = Routes.SERIES- )- }-- composable(Routes.VOD) {- VodScreen(- onMovieClick = { movie ->- navigator.openMovieDetail(movie, AppDestination.Vod)- },- onSeriesClick = { series ->- navigator.openSeriesDetail(series, AppDestination.Vod)- },- onNavigate = { route -> tabNavigate(route) },- currentRoute = Routes.VOD- )- }-- composable(Routes.DOWNLOADS) {- DownloadsScreen(- onNavigate = { route -> tabNavigate(route) },- currentRoute = Routes.DOWNLOADS- )- }-- composable(- route = Routes.EPG_DESTINATION,- arguments = listOf(- navArgument("categoryId") { type = NavType.LongType; defaultValue = -1L },- navArgument("anchorTime") { type = NavType.LongType; defaultValue = -1L },- navArgument("favoritesOnly") { type = NavType.BoolType; defaultValue = false }- )- ) { backStackEntry ->- val epgCategoryId = backStackEntry.arguments?.getLong("categoryId")?.takeIf { it != -1L }- val epgAnchorTime = backStackEntry.arguments?.getLong("anchorTime")?.takeIf { it != -1L }- val epgFavoritesOnly = backStackEntry.arguments?.getBoolean("favoritesOnly") ?: false- com.streamvault.app.ui.screens.epg.FullEpgScreen(- currentRoute = Routes.EPG,- initialCategoryId = epgCategoryId,- initialAnchorTime = epgAnchorTime,- initialFavoritesOnly = epgFavoritesOnly,- onPlayChannel = { channel, categoryId, isVirtual, combinedProfileId, returnRoute ->- navigator.openPlayer(- channel.toLivePlayerRequest(- categoryId = categoryId,- providerId = channel.providerId,- isVirtual = isVirtual,- combinedProfileId = combinedProfileId,- returnDestination = AppRouteCodec.decode(returnRoute)- )- )- },- onPlayArchive = { channel, program, categoryId, isVirtual, combinedProfileId, returnRoute ->- if (!channel.isArchivePlayable(program)) {- return@FullEpgScreen- }- navigator.openPlayer(- playerNavigationRequest(- streamUrl = channel.streamUrl,- title = channel.name,- channelId = channel.epgChannelId,- internalId = channel.id,- categoryId = categoryId,- providerId = channel.providerId,- isVirtual = isVirtual,- combinedProfileId = combinedProfileId,- contentType = "LIVE",- archiveStartMs = program.startTime,- archiveEndMs = program.endTime,- archiveTitle = "${channel.name}: ${program.title}",- returnDestination = AppRouteCodec.decode(returnRoute)- )- )- },- onNavigate = { route -> tabNavigate(route) }- )- }-- composable(- route = Routes.SETTINGS_DESTINATION,- arguments = listOf(- navArgument("backupUri") { type = NavType.StringType; defaultValue = "" }- )- ) { backStackEntry ->- val backupUri = backStackEntry.arguments?.getString("backupUri")?.takeIf { it.isNotBlank() }- SettingsScreen(- onNavigate = { route -> tabNavigate(route) },- onAddProvider = dropUnlessResumed {- navigator.navigateIfResumed(AppDestination.ProviderSetup())- },- onEditProvider = { provider ->- navigator.navigateIfResumed(- AppDestination.ProviderSetup(providerId = provider.id),- NavigationOptions(launchSingleTop = true)- )- },- onNavigateToParentalControl = { providerId ->- navigator.navigateIfResumed(- AppDestination.ParentalControlGroups(providerId),- NavigationOptions(launchSingleTop = true)- )- },- currentRoute = Routes.SETTINGS,- initialBackupImportUri = backupUri- )- }-- composable(Routes.PLUGINS) {- PluginsScreen(- currentRoute = Routes.PLUGINS,- onNavigate = { route -> tabNavigate(route) }- )- }-- composable(- route = Routes.PARENTAL_CONTROL_GROUPS,- arguments = listOf(- navArgument("providerId") { type = NavType.LongType }- )- ) {- com.streamvault.app.ui.screens.settings.parental.ParentalControlGroupScreen(- currentRoute = Routes.SETTINGS,- onNavigate = { route -> tabNavigate(route) },- onBack = { navigator.back() }- )- }-- composable(- route = Routes.SEARCH_DESTINATION,- arguments = listOf(- navArgument("query") { type = NavType.StringType; defaultValue = "" }- )- ) { backStackEntry ->- com.streamvault.app.ui.screens.search.SearchScreen(- initialQuery = backStackEntry.arguments?.getString("query").orEmpty(),- onChannelClick = { channel ->- navigator.openPlayer(- channel.toLivePlayerRequest(- categoryId = channel.categoryId,- providerId = channel.providerId,- isVirtual = false,- returnDestination = AppDestination.Search(backStackEntry.arguments?.getString("query").orEmpty())- )- )- },- onMovieClick = { movie ->- navigator.openMovieDetail(- movie,- AppDestination.Search(backStackEntry.arguments?.getString("query").orEmpty())- )- },- onSeriesClick = { series ->- navigator.openSeriesDetail(- series,- AppDestination.Search(backStackEntry.arguments?.getString("query").orEmpty())- )- },- onNavigate = { route -> tabNavigate(route) },- currentRoute = Routes.SEARCH- )- }-- composable(route = Routes.PLAYER) { backStackEntry ->- val playerRequest = navigator.consumePlayerRequest(backStackEntry)- val safePlayerRequest = safePlayerNavigationRequest(playerRequest)- if (safePlayerRequest == null) {- LaunchedEffect(playerRequest) {- Log.w(APP_NAVIGATION_TAG, "Missing or invalid player request; returning to previous destination")- if (!navigator.execute(NavigationCommand.Back)) {- navigator.execute(- NavigationCommand.Navigate(- AppDestination.Home,- NavigationOptions(- launchSingleTop = true,- popUpTo = AppDestination.Player,- inclusive = true- )- )- )- }- }- } else {- PlayerScreen(- streamUrl = safePlayerRequest.streamUrl,- title = safePlayerRequest.title,- epgChannelId = safePlayerRequest.channelId,- internalChannelId = safePlayerRequest.internalId,- categoryId = safePlayerRequest.categoryId,- providerId = safePlayerRequest.providerId,- isVirtual = safePlayerRequest.isVirtual,- combinedProfileId = safePlayerRequest.combinedProfileId,- combinedSourceFilterProviderId = safePlayerRequest.combinedSourceFilterProviderId,- contentType = safePlayerRequest.contentType,- artworkUrl = safePlayerRequest.artworkUrl,- archiveStartMs = safePlayerRequest.archiveStartMs,- archiveEndMs = safePlayerRequest.archiveEndMs,- archiveTitle = safePlayerRequest.archiveTitle,- returnDestination = safePlayerRequest.returnDestination,- seriesId = safePlayerRequest.seriesId,- seasonNumber = safePlayerRequest.seasonNumber,- episodeNumber = safePlayerRequest.episodeNumber,- episodeId = safePlayerRequest.episodeId,- onBack = { navigator.returnTo(safePlayerRequest.returnDestination) },- onNavigate = { destination ->- navigator.navigateIfResumed(- destination,- NavigationOptions(- launchSingleTop = true,- popUpTo = AppDestination.Player.takeIf { destination == AppDestination.MultiView },- inclusive = destination == AppDestination.MultiView- )- )- }- )- }- }-- composable(- route = Routes.MOVIE_DETAIL,- arguments = listOf(- navArgument("movieId") { type = NavType.LongType },- navArgument("returnRoute") { type = NavType.StringType; defaultValue = "" }- )- ) { backStackEntry ->- navigator.consumeMoviePresentationHint(backStackEntry)- val returnRoute = backStackEntry.arguments?.getString("returnRoute").orEmpty().takeIf { it.isNotBlank() }- val returnDestination = returnRoute?.let(AppRouteCodec::decode)- val movieId = backStackEntry.arguments?.getLong("movieId") ?: -1L- com.streamvault.app.ui.screens.movies.MovieDetailScreen(- onPlay = { movie ->- navigator.openPlayer(- movie.toPlayerNavigationRequest(- returnDestination = AppDestination.MovieDetail(- movieId = movie.id.takeIf { it > 0L } ?: movieId,- returnDestination = returnDestination- )- )- )- },- onBack = { navigator.returnTo(returnDestination) }- )- }-- composable(- route = Routes.SERIES_DETAIL,- arguments = listOf(- navArgument("seriesId") { type = NavType.LongType },- navArgument("returnRoute") { type = NavType.StringType; defaultValue = "" }- )- ) { backStackEntry ->- navigator.consumeSeriesPresentationHint(backStackEntry)- val returnRoute = backStackEntry.arguments?.getString("returnRoute").orEmpty().takeIf { it.isNotBlank() }- val returnDestination = returnRoute?.let(AppRouteCodec::decode)- val seriesId = backStackEntry.arguments?.getLong("seriesId") ?: -1L- com.streamvault.app.ui.screens.series.SeriesDetailScreen(- onEpisodeClick = { episode ->- navigator.openPlayer(- episode.toPlayerNavigationRequest(- returnDestination = AppDestination.SeriesDetail(- seriesId = episode.seriesId.takeIf { it > 0L } ?: seriesId,- returnDestination = returnDestination- )- )- )- },- onBack = { navigator.returnTo(returnDestination) }- )- }-- composable(Routes.MULTI_VIEW) {- MultiViewScreen(- onBack = { navigator.back() }- )- }- }}-diff --git a/app/src/main/java/com/streamvault/app/navigation/graph/CatalogGraph.kt b/app/src/main/java/com/streamvault/app/navigation/graph/CatalogGraph.ktnew file mode 100644index 00000000..98c162b2--- /dev/null+++ b/app/src/main/java/com/streamvault/app/navigation/graph/CatalogGraph.kt@@ -0,0 +1,166 @@+package com.streamvault.app.navigation.graph++import androidx.navigation.NavGraphBuilder+import androidx.navigation.NavType+import androidx.navigation.compose.composable+import androidx.navigation.navArgument+import com.streamvault.app.navigation.AppNavigationPayloads+import com.streamvault.app.navigation.AppRouteCodec+import com.streamvault.app.navigation.AppRoutePatterns+import com.streamvault.app.navigation.CatalogDetailNavigationActions+import com.streamvault.app.navigation.toLivePlayerRequest+import com.streamvault.app.navigation.toPlayerNavigationRequest+import com.streamvault.app.ui.screens.movies.MovieDetailScreen+import com.streamvault.app.ui.screens.movies.MoviesScreen+import com.streamvault.app.ui.screens.search.SearchScreen+import com.streamvault.app.ui.screens.series.SeriesDetailScreen+import com.streamvault.app.ui.screens.series.SeriesScreen+import com.streamvault.app.ui.screens.vod.VodScreen+import com.streamvault.core.navigation.AppDestination+import com.streamvault.core.navigation.NavigationActions+import com.streamvault.core.navigation.NavigationOptions++internal fun NavGraphBuilder.registerCatalogGraph(+ actions: NavigationActions,+ catalogDetailActions: CatalogDetailNavigationActions,+ payloads: AppNavigationPayloads,+ onTopLevelDestinationRequested: (AppDestination) -> Unit+) {+ composable(AppRoutePatterns.MOVIES) {+ MoviesScreen(+ onMovieClick = { movie ->+ catalogDetailActions.openMovieDetail(movie, AppDestination.Movies)+ },+ onContinueWatchingPlay = { history ->+ actions.openPlayer(+ history.toPlayerNavigationRequest().copy(returnDestination = AppDestination.Movies)+ )+ },+ onNavigate = { route ->+ AppRouteCodec.decode(route)?.let(onTopLevelDestinationRequested)+ },+ currentRoute = AppRoutePatterns.MOVIES+ )+ }++ composable(AppRoutePatterns.SERIES) {+ SeriesScreen(+ onSeriesClick = { series ->+ catalogDetailActions.openSeriesDetail(series, AppDestination.Series)+ },+ onSeriesIdClick = { seriesId ->+ actions.navigate(+ AppDestination.SeriesDetail(seriesId, AppDestination.Series),+ NavigationOptions(launchSingleTop = true)+ )+ },+ onNavigate = { route ->+ AppRouteCodec.decode(route)?.let(onTopLevelDestinationRequested)+ },+ currentRoute = AppRoutePatterns.SERIES+ )+ }++ composable(AppRoutePatterns.VOD) {+ VodScreen(+ onMovieClick = { movie ->+ catalogDetailActions.openMovieDetail(movie, AppDestination.Vod)+ },+ onSeriesClick = { series ->+ catalogDetailActions.openSeriesDetail(series, AppDestination.Vod)+ },+ onNavigate = { route ->+ AppRouteCodec.decode(route)?.let(onTopLevelDestinationRequested)+ },+ currentRoute = AppRoutePatterns.VOD+ )+ }++ composable(+ route = AppRoutePatterns.SEARCH_DESTINATION,+ arguments = listOf(+ navArgument("query") { type = NavType.StringType; defaultValue = "" }+ )+ ) { backStackEntry ->+ val query = backStackEntry.arguments?.getString("query").orEmpty()+ SearchScreen(+ initialQuery = query,+ onChannelClick = { channel ->+ actions.openPlayer(+ channel.toLivePlayerRequest(+ categoryId = channel.categoryId,+ providerId = channel.providerId,+ isVirtual = false,+ returnDestination = AppDestination.Search(query)+ )+ )+ },+ onMovieClick = { movie ->+ catalogDetailActions.openMovieDetail(movie, AppDestination.Search(query))+ },+ onSeriesClick = { series ->+ catalogDetailActions.openSeriesDetail(series, AppDestination.Search(query))+ },+ onNavigate = { route ->+ AppRouteCodec.decode(route)?.let(onTopLevelDestinationRequested)+ },+ currentRoute = AppRoutePatterns.SEARCH+ )+ }++ composable(+ route = AppRoutePatterns.MOVIE_DETAIL,+ arguments = listOf(+ navArgument("movieId") { type = NavType.LongType },+ navArgument("returnRoute") { type = NavType.StringType; defaultValue = "" }+ )+ ) { backStackEntry ->+ payloads.consumeMoviePresentationHint(backStackEntry)+ val returnDestination = backStackEntry.arguments?.getString("returnRoute")+ .orEmpty()+ .takeIf { it.isNotBlank() }+ ?.let(AppRouteCodec::decode)+ val movieId = backStackEntry.arguments?.getLong("movieId") ?: -1L+ MovieDetailScreen(+ onPlay = { movie ->+ actions.openPlayer(+ movie.toPlayerNavigationRequest(+ returnDestination = AppDestination.MovieDetail(+ movieId = movie.id.takeIf { it > 0L } ?: movieId,+ returnDestination = returnDestination+ )+ )+ )+ },+ onBack = { actions.returnTo(returnDestination) }+ )+ }++ composable(+ route = AppRoutePatterns.SERIES_DETAIL,+ arguments = listOf(+ navArgument("seriesId") { type = NavType.LongType },+ navArgument("returnRoute") { type = NavType.StringType; defaultValue = "" }+ )+ ) { backStackEntry ->+ payloads.consumeSeriesPresentationHint(backStackEntry)+ val returnDestination = backStackEntry.arguments?.getString("returnRoute")+ .orEmpty()+ .takeIf { it.isNotBlank() }+ ?.let(AppRouteCodec::decode)+ val seriesId = backStackEntry.arguments?.getLong("seriesId") ?: -1L+ SeriesDetailScreen(+ onEpisodeClick = { episode ->+ actions.openPlayer(+ episode.toPlayerNavigationRequest(+ returnDestination = AppDestination.SeriesDetail(+ seriesId = episode.seriesId.takeIf { it > 0L } ?: seriesId,+ returnDestination = returnDestination+ )+ )+ )+ },+ onBack = { actions.returnTo(returnDestination) }+ )+ }+}diff --git a/app/src/main/java/com/streamvault/app/navigation/graph/HomeGraph.kt b/app/src/main/java/com/streamvault/app/navigation/graph/HomeGraph.ktnew file mode 100644index 00000000..28546fde--- /dev/null+++ b/app/src/main/java/com/streamvault/app/navigation/graph/HomeGraph.kt@@ -0,0 +1,74 @@+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.navigation.CatalogDetailNavigationActions+import com.streamvault.app.navigation.toPlayerNavigationRequest+import com.streamvault.app.navigation.toLivePlayerRequest+import com.streamvault.app.ui.screens.dashboard.DashboardScreen+import com.streamvault.core.navigation.AppDestination+import com.streamvault.core.navigation.NavigationActions+import com.streamvault.core.navigation.NavigationOptions+import com.streamvault.domain.model.ContentType++internal fun NavGraphBuilder.registerHomeGraph(+ actions: NavigationActions,+ catalogDetailActions: CatalogDetailNavigationActions,+ onTopLevelDestinationRequested: (AppDestination) -> Unit+) {+ composable(AppRoutePatterns.HOME) {+ DashboardScreen(+ onNavigate = { route ->+ AppRouteCodec.decode(route)?.let(onTopLevelDestinationRequested)+ },+ onAddProvider = {+ actions.navigate(AppDestination.ProviderSetup())+ },+ onRecentChannelClick = { channel, combinedProfileId ->+ actions.openPlayer(+ channel.toLivePlayerRequest(+ categoryId = com.streamvault.domain.model.VirtualCategoryIds.RECENT,+ providerId = channel.providerId,+ isVirtual = true,+ combinedProfileId = combinedProfileId,+ returnDestination = AppDestination.Home+ )+ )+ },+ onFavoriteChannelClick = { channel, combinedProfileId ->+ actions.openPlayer(+ channel.toLivePlayerRequest(+ categoryId = com.streamvault.domain.model.VirtualCategoryIds.FAVORITES,+ providerId = channel.providerId,+ isVirtual = true,+ combinedProfileId = combinedProfileId,+ returnDestination = AppDestination.Home+ )+ )+ },+ onMovieClick = { movie ->+ catalogDetailActions.openMovieDetail(movie, AppDestination.Home)+ },+ onSeriesClick = { series ->+ catalogDetailActions.openSeriesDetail(series, AppDestination.Home)+ },+ onPlaybackHistoryClick = { history ->+ when (history.contentType) {+ ContentType.SERIES -> actions.navigate(+ AppDestination.SeriesDetail(history.contentId, AppDestination.Home),+ NavigationOptions(launchSingleTop = true)+ )+ ContentType.LIVE,+ ContentType.MOVIE,+ ContentType.VOD,+ ContentType.SERIES_EPISODE -> actions.openPlayer(+ history.toPlayerNavigationRequest(AppDestination.Home)+ )+ }+ },+ currentRoute = AppRoutePatterns.HOME+ )+ }+}diff --git a/app/src/main/java/com/streamvault/app/navigation/graph/LiveGraph.kt b/app/src/main/java/com/streamvault/app/navigation/graph/LiveGraph.ktnew file mode 100644index 00000000..9126d67f--- /dev/null+++ b/app/src/main/java/com/streamvault/app/navigation/graph/LiveGraph.kt@@ -0,0 +1,101 @@+package com.streamvault.app.navigation.graph++import androidx.navigation.NavGraphBuilder+import androidx.navigation.NavType+import androidx.navigation.compose.composable+import androidx.navigation.navArgument+import com.streamvault.app.navigation.AppRouteCodec+import com.streamvault.app.navigation.AppRoutePatterns+import com.streamvault.app.navigation.playerNavigationRequest+import com.streamvault.app.navigation.toLivePlayerRequest+import com.streamvault.app.ui.model.isArchivePlayable+import com.streamvault.app.ui.screens.epg.FullEpgScreen+import com.streamvault.app.ui.screens.home.HomeScreen+import com.streamvault.core.navigation.AppDestination+import com.streamvault.core.navigation.NavigationActions++internal fun NavGraphBuilder.registerLiveGraph(+ actions: NavigationActions,+ onTopLevelDestinationRequested: (AppDestination) -> Unit+) {+ composable(+ route = AppRoutePatterns.LIVE_TV_DESTINATION,+ arguments = listOf(+ navArgument("categoryId") { type = NavType.LongType; defaultValue = -1L }+ )+ ) { backStackEntry ->+ val initialCategoryId = backStackEntry.arguments?.getLong("categoryId")?.takeIf { it != -1L }+ HomeScreen(+ onChannelClick = { channel, category, provider, combinedProfileId, combinedSourceFilterProviderId ->+ actions.openPlayer(+ channel.toLivePlayerRequest(+ categoryId = category?.id,+ providerId = provider?.id,+ isVirtual = category?.isVirtual == true,+ combinedProfileId = combinedProfileId,+ combinedSourceFilterProviderId = combinedSourceFilterProviderId,+ returnDestination = AppDestination.LiveTv(category?.id)+ )+ )+ },+ onNavigate = { route ->+ AppRouteCodec.decode(route)?.let(onTopLevelDestinationRequested)+ },+ currentRoute = AppRoutePatterns.LIVE_TV,+ initialCategoryId = initialCategoryId+ )+ }++ composable(+ route = AppRoutePatterns.EPG_DESTINATION,+ arguments = listOf(+ navArgument("categoryId") { type = NavType.LongType; defaultValue = -1L },+ navArgument("anchorTime") { type = NavType.LongType; defaultValue = -1L },+ navArgument("favoritesOnly") { type = NavType.BoolType; defaultValue = false }+ )+ ) { backStackEntry ->+ val epgCategoryId = backStackEntry.arguments?.getLong("categoryId")?.takeIf { it != -1L }+ val epgAnchorTime = backStackEntry.arguments?.getLong("anchorTime")?.takeIf { it != -1L }+ val epgFavoritesOnly = backStackEntry.arguments?.getBoolean("favoritesOnly") ?: false+ FullEpgScreen(+ currentRoute = AppRoutePatterns.EPG,+ initialCategoryId = epgCategoryId,+ initialAnchorTime = epgAnchorTime,+ initialFavoritesOnly = epgFavoritesOnly,+ onPlayChannel = { channel, categoryId, isVirtual, combinedProfileId, returnRoute ->+ actions.openPlayer(+ channel.toLivePlayerRequest(+ categoryId = categoryId,+ providerId = channel.providerId,+ isVirtual = isVirtual,+ combinedProfileId = combinedProfileId,+ returnDestination = AppRouteCodec.decode(returnRoute)+ )+ )+ },+ onPlayArchive = { channel, program, categoryId, isVirtual, combinedProfileId, returnRoute ->+ if (!channel.isArchivePlayable(program)) return@FullEpgScreen+ actions.openPlayer(+ playerNavigationRequest(+ streamUrl = channel.streamUrl,+ title = channel.name,+ channelId = channel.epgChannelId,+ internalId = channel.id,+ categoryId = categoryId,+ providerId = channel.providerId,+ isVirtual = isVirtual,+ combinedProfileId = combinedProfileId,+ contentType = "LIVE",+ archiveStartMs = program.startTime,+ archiveEndMs = program.endTime,+ archiveTitle = "${channel.name}: ${program.title}",+ returnDestination = AppRouteCodec.decode(returnRoute)+ )+ )+ },+ onNavigate = { route ->+ AppRouteCodec.decode(route)?.let(onTopLevelDestinationRequested)+ }+ )+ }+}diff --git a/app/src/main/java/com/streamvault/app/navigation/graph/PlayerGraph.kt b/app/src/main/java/com/streamvault/app/navigation/graph/PlayerGraph.ktnew file mode 100644index 00000000..68f05dbc--- /dev/null+++ b/app/src/main/java/com/streamvault/app/navigation/graph/PlayerGraph.kt@@ -0,0 +1,77 @@+package com.streamvault.app.navigation.graph++import android.util.Log+import androidx.compose.runtime.LaunchedEffect+import androidx.navigation.NavGraphBuilder+import androidx.navigation.compose.composable+import com.streamvault.app.navigation.APP_NAVIGATION_TAG+import com.streamvault.app.navigation.AppNavigationPayloads+import com.streamvault.app.navigation.AppRoutePatterns+import com.streamvault.app.navigation.safePlayerNavigationRequest+import com.streamvault.app.ui.screens.multiview.MultiViewScreen+import com.streamvault.app.ui.screens.player.PlayerScreen+import com.streamvault.core.navigation.AppDestination+import com.streamvault.core.navigation.NavigationActions+import com.streamvault.core.navigation.NavigationOptions++internal fun NavGraphBuilder.registerPlayerGraph(+ actions: NavigationActions,+ payloads: AppNavigationPayloads+) {+ composable(AppRoutePatterns.PLAYER) { backStackEntry ->+ val playerRequest = payloads.consumePlayerRequest(backStackEntry)+ val safePlayerRequest = safePlayerNavigationRequest(playerRequest)+ if (safePlayerRequest == null) {+ LaunchedEffect(playerRequest) {+ Log.w(APP_NAVIGATION_TAG, "Missing or invalid player request; returning to previous destination")+ if (!actions.back()) {+ actions.navigate(+ AppDestination.Home,+ NavigationOptions(+ launchSingleTop = true,+ popUpTo = AppDestination.Player,+ inclusive = true+ )+ )+ }+ }+ } else {+ PlayerScreen(+ streamUrl = safePlayerRequest.streamUrl,+ title = safePlayerRequest.title,+ epgChannelId = safePlayerRequest.channelId,+ internalChannelId = safePlayerRequest.internalId,+ categoryId = safePlayerRequest.categoryId,+ providerId = safePlayerRequest.providerId,+ isVirtual = safePlayerRequest.isVirtual,+ combinedProfileId = safePlayerRequest.combinedProfileId,+ combinedSourceFilterProviderId = safePlayerRequest.combinedSourceFilterProviderId,+ contentType = safePlayerRequest.contentType,+ artworkUrl = safePlayerRequest.artworkUrl,+ archiveStartMs = safePlayerRequest.archiveStartMs,+ archiveEndMs = safePlayerRequest.archiveEndMs,+ archiveTitle = safePlayerRequest.archiveTitle,+ returnDestination = safePlayerRequest.returnDestination,+ seriesId = safePlayerRequest.seriesId,+ seasonNumber = safePlayerRequest.seasonNumber,+ episodeNumber = safePlayerRequest.episodeNumber,+ episodeId = safePlayerRequest.episodeId,+ onBack = { actions.returnTo(safePlayerRequest.returnDestination) },+ onNavigate = { destination ->+ actions.navigate(+ destination,+ NavigationOptions(+ launchSingleTop = true,+ popUpTo = AppDestination.Player.takeIf { destination == AppDestination.MultiView },+ inclusive = destination == AppDestination.MultiView+ )+ )+ }+ )+ }+ }++ composable(AppRoutePatterns.MULTI_VIEW) {+ MultiViewScreen(onBack = { actions.back() })+ }+}diff --git a/app/src/main/java/com/streamvault/app/navigation/graph/ProviderGraph.kt b/app/src/main/java/com/streamvault/app/navigation/graph/ProviderGraph.ktnew file mode 100644index 00000000..21946043--- /dev/null+++ b/app/src/main/java/com/streamvault/app/navigation/graph/ProviderGraph.kt@@ -0,0 +1,36 @@+package com.streamvault.app.navigation.graph++import androidx.lifecycle.compose.dropUnlessResumed+import androidx.navigation.NavGraphBuilder+import androidx.navigation.NavType+import androidx.navigation.compose.composable+import androidx.navigation.navArgument+import com.streamvault.app.navigation.AppRoutePatterns+import com.streamvault.app.ui.screens.provider.ProviderSetupScreen+import com.streamvault.core.navigation.AppDestination+import com.streamvault.core.navigation.NavigationActions++internal fun NavGraphBuilder.registerProviderGraph(+ actions: NavigationActions,+ startupReady: Boolean,+ onStartupNavigationRequested: (AppDestination) -> Unit+) {+ composable(+ route = AppRoutePatterns.PROVIDER_SETUP,+ arguments = listOf(+ navArgument("providerId") { type = NavType.LongType; defaultValue = -1L },+ navArgument("importUri") { type = NavType.StringType; defaultValue = "" }+ )+ ) { backStackEntry ->+ val providerId = backStackEntry.arguments?.getLong("providerId")?.takeIf { it != -1L }+ val importUri = backStackEntry.arguments?.getString("importUri")?.takeIf { it.isNotBlank() }+ ProviderSetupScreen(+ editProviderId = providerId,+ initialImportUri = importUri,+ onBack = { actions.back() },+ onProviderAdded = dropUnlessResumed {+ onStartupNavigationRequested(AppDestination.ProviderSetup())+ }+ )+ }+}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.ktnew file mode 100644index 00000000..3b81d116--- /dev/null+++ b/app/src/main/java/com/streamvault/app/navigation/graph/SystemGraph.kt@@ -0,0 +1,85 @@+package com.streamvault.app.navigation.graph++import androidx.lifecycle.compose.dropUnlessResumed+import androidx.navigation.NavGraphBuilder+import androidx.navigation.NavType+import androidx.navigation.compose.composable+import androidx.navigation.navArgument+import com.streamvault.app.navigation.AppRouteCodec+import com.streamvault.app.navigation.AppRoutePatterns+import com.streamvault.app.ui.screens.downloads.DownloadsScreen+import com.streamvault.app.ui.screens.plugins.PluginsScreen+import com.streamvault.app.ui.screens.settings.SettingsScreen+import com.streamvault.app.ui.screens.settings.parental.ParentalControlGroupScreen+import com.streamvault.core.navigation.AppDestination+import com.streamvault.core.navigation.NavigationActions+import com.streamvault.core.navigation.NavigationOptions++internal fun NavGraphBuilder.registerSystemGraph(+ actions: NavigationActions,+ onTopLevelDestinationRequested: (AppDestination) -> Unit+) {+ composable(AppRoutePatterns.DOWNLOADS) {+ DownloadsScreen(+ onNavigate = { route ->+ AppRouteCodec.decode(route)?.let(onTopLevelDestinationRequested)+ },+ currentRoute = AppRoutePatterns.DOWNLOADS+ )+ }++ composable(+ route = AppRoutePatterns.SETTINGS_DESTINATION,+ arguments = listOf(+ navArgument("backupUri") { type = NavType.StringType; defaultValue = "" }+ )+ ) { backStackEntry ->+ val backupUri = backStackEntry.arguments?.getString("backupUri")?.takeIf { it.isNotBlank() }+ SettingsScreen(+ onNavigate = { route ->+ AppRouteCodec.decode(route)?.let(onTopLevelDestinationRequested)+ },+ onAddProvider = dropUnlessResumed {+ actions.navigate(AppDestination.ProviderSetup())+ },+ onEditProvider = { provider ->+ actions.navigate(+ AppDestination.ProviderSetup(providerId = provider.id),+ NavigationOptions(launchSingleTop = true)+ )+ },+ onNavigateToParentalControl = { providerId ->+ actions.navigate(+ AppDestination.ParentalControlGroups(providerId),+ NavigationOptions(launchSingleTop = true)+ )+ },+ currentRoute = AppRoutePatterns.SETTINGS,+ initialBackupImportUri = backupUri+ )+ }++ composable(AppRoutePatterns.PLUGINS) {+ PluginsScreen(+ currentRoute = AppRoutePatterns.PLUGINS,+ onNavigate = { route ->+ AppRouteCodec.decode(route)?.let(onTopLevelDestinationRequested)+ }+ )+ }++ composable(+ route = AppRoutePatterns.PARENTAL_CONTROL_GROUPS,+ arguments = listOf(+ navArgument("providerId") { type = NavType.LongType }+ )+ ) {+ ParentalControlGroupScreen(+ currentRoute = AppRoutePatterns.SETTINGS,+ onNavigate = { route ->+ AppRouteCodec.decode(route)?.let(onTopLevelDestinationRequested)+ },+ onBack = { actions.back() }+ )+ }+}diff --git a/app/src/main/java/com/streamvault/app/navigation/graph/WelcomeGraph.kt b/app/src/main/java/com/streamvault/app/navigation/graph/WelcomeGraph.ktnew file mode 100644index 00000000..6b96a074--- /dev/null+++ b/app/src/main/java/com/streamvault/app/navigation/graph/WelcomeGraph.kt@@ -0,0 +1,31 @@+package com.streamvault.app.navigation.graph++import androidx.lifecycle.compose.dropUnlessResumed+import androidx.navigation.NavGraphBuilder+import androidx.navigation.compose.composable+import com.streamvault.app.navigation.AppRoutePatterns+import com.streamvault.app.ui.screens.welcome.WelcomeScreen+import com.streamvault.core.navigation.AppDestination+import com.streamvault.core.navigation.NavigationActions+import com.streamvault.core.navigation.NavigationOptions++internal fun NavGraphBuilder.registerWelcomeGraph(+ actions: NavigationActions,+ startupReady: Boolean,+ onStartupNavigationRequested: (AppDestination) -> Unit+) {+ composable(AppRoutePatterns.WELCOME) {+ WelcomeScreen(+ onNavigateToHome = dropUnlessResumed {+ onStartupNavigationRequested(AppDestination.Welcome)+ },+ startupReady = startupReady,+ onNavigateToSetup = dropUnlessResumed {+ actions.navigate(+ AppDestination.ProviderSetup(),+ NavigationOptions(popUpTo = AppDestination.Welcome, inclusive = true)+ )+ }+ )+ }+}diff --git a/app/src/test/java/com/streamvault/app/navigation/FeatureGraphBoundaryTest.kt b/app/src/test/java/com/streamvault/app/navigation/FeatureGraphBoundaryTest.ktnew file mode 100644index 00000000..2a737913--- /dev/null+++ b/app/src/test/java/com/streamvault/app/navigation/FeatureGraphBoundaryTest.kt@@ -0,0 +1,29 @@+package com.streamvault.app.navigation++import com.google.common.truth.Truth.assertThat+import java.io.File+import org.junit.Test++class FeatureGraphBoundaryTest {+ @Test+ fun featureGraphsDoNotReferenceRootController() {+ val graphRoot = File("src/main/java/com/streamvault/app/navigation/graph")+ val files = graphRoot.walkTopDown()+ .filter { it.extension == "kt" }+ .toList()+ assertThat(files.map { it.name }).containsAtLeast(+ "WelcomeGraph.kt",+ "ProviderGraph.kt",+ "HomeGraph.kt",+ "LiveGraph.kt",+ "CatalogGraph.kt",+ "PlayerGraph.kt",+ "SystemGraph.kt"+ )+ val violations = files+ .filter { "NavHostController" in it.readText() || "NavController" in it.readText() }+ .map { it.name }+ .toList()+ assertThat(violations).isEmpty()+ }+}