diff --git a/Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/model/CategoryInfoList.kt b/Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/model/CategoryInfoList.kt index a8af1dc726..8e2c46f759 100644 --- a/Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/model/CategoryInfoList.kt +++ b/Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/model/CategoryInfoList.kt @@ -18,6 +18,7 @@ package com.example.jetcaster.tv.model import androidx.compose.runtime.Immutable import com.example.jetcaster.core.data.database.model.Category +import com.example.jetcaster.core.data.database.model.asExternalModel import com.example.jetcaster.core.model.CategoryInfo @Immutable @@ -29,7 +30,7 @@ data class CategoryInfoList(val member: List) : List companion object { fun from(list: List): CategoryInfoList { - val member = list.map(Category::intoCategoryInfo) + val member = list.map(Category::asExternalModel) return CategoryInfoList(member) } } @@ -38,7 +39,3 @@ data class CategoryInfoList(val member: List) : List private fun CategoryInfo.intoCategory(): Category { return Category(id, name) } - -private fun Category.intoCategoryInfo(): CategoryInfo { - return CategoryInfo(id, name) -} diff --git a/Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/ui/JetcasterApp.kt b/Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/ui/JetcasterApp.kt index 529da265b4..d5b4f3b257 100644 --- a/Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/ui/JetcasterApp.kt +++ b/Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/ui/JetcasterApp.kt @@ -27,9 +27,11 @@ import androidx.compose.material.icons.filled.Search import androidx.compose.material.icons.filled.Settings import androidx.compose.material.icons.filled.VideoLibrary import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable +import androidx.tv.material3.DrawerValue import androidx.tv.material3.ExperimentalTvMaterial3Api import androidx.tv.material3.Icon import androidx.tv.material3.MaterialTheme @@ -58,15 +60,17 @@ private fun WithGlobalNavigation( modifier: Modifier = Modifier, content: @Composable () -> Unit ) { + val currentScreen by jetcasterAppState.currentScreenState + NavigationDrawer( drawerContent = { + val isClosed = it == DrawerValue.Closed Column( modifier = Modifier .padding(JetcasterAppDefaults.overScanMargin.drawer.intoPaddingValues()) ) { - NavigationDrawerItem( - selected = false, + selected = isClosed && currentScreen.index == Screen.Profile.index, onClick = jetcasterAppState::navigateToProfile, leadingContent = { Icon(Icons.Default.Person, contentDescription = null) }, ) { @@ -77,21 +81,21 @@ private fun WithGlobalNavigation( } Spacer(modifier = Modifier.weight(1f)) NavigationDrawerItem( - selected = false, + selected = isClosed && currentScreen.index == Screen.Search.index, onClick = jetcasterAppState::navigateToSearch, leadingContent = { Icon(Icons.Default.Search, contentDescription = null) } ) { Text(text = "Search") } NavigationDrawerItem( - selected = false, + selected = isClosed && currentScreen.index == Screen.Discover.index, onClick = jetcasterAppState::navigateToDiscover, leadingContent = { Icon(Icons.Default.Home, contentDescription = null) }, ) { Text(text = "Discover") } NavigationDrawerItem( - selected = false, + selected = isClosed && currentScreen.index == Screen.Library.index, onClick = jetcasterAppState::navigateToLibrary, leadingContent = { Icon(Icons.Default.VideoLibrary, contentDescription = null) } ) { @@ -99,7 +103,7 @@ private fun WithGlobalNavigation( } Spacer(modifier = Modifier.weight(1f)) NavigationDrawerItem( - selected = false, + selected = isClosed && currentScreen.index == Screen.Settings.index, onClick = jetcasterAppState::navigateToSettings, leadingContent = { Icon(Icons.Default.Settings, contentDescription = null) } ) { diff --git a/Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/ui/JetcasterAppState.kt b/Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/ui/JetcasterAppState.kt index 74077a81e6..8a508efacc 100644 --- a/Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/ui/JetcasterAppState.kt +++ b/Jetcaster/tv-app/src/main/java/com/example/jetcaster/tv/ui/JetcasterAppState.kt @@ -18,6 +18,7 @@ package com.example.jetcaster.tv.ui import android.net.Uri import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController @@ -26,36 +27,44 @@ import com.example.jetcaster.core.model.PlayerEpisode class JetcasterAppState( val navHostController: NavHostController ) { + + private var _currentScreenState = mutableStateOf(Screen.Discover) + val currentScreenState = _currentScreenState + private fun navigate(screen: Screen) { + _currentScreenState.value = screen + navHostController.navigate(screen.route) + } + fun navigateToDiscover() { - navHostController.navigate(Screen.Discover.route) + navigate(Screen.Discover) } fun navigateToLibrary() { - navHostController.navigate(Screen.Library.route) + navigate(Screen.Library) } fun navigateToProfile() { - navHostController.navigate(Screen.Profile.route) + navigate(Screen.Profile) } fun navigateToSearch() { - navHostController.navigate(Screen.Search.route) + navigate(Screen.Search) } fun navigateToSettings() { - navHostController.navigate(Screen.Settings.route) + navigate(Screen.Settings) } fun showPodcastDetails(podcastUri: String) { val encodedUrL = Uri.encode(podcastUri) val screen = Screen.Podcast(encodedUrL) - navHostController.navigate(screen.route) + navigate(screen) } fun showEpisodeDetails(episodeUri: String) { val encodeUrl = Uri.encode(episodeUri) val screen = Screen.Episode(encodeUrl) - navHostController.navigate(screen.route) + navigate(screen) } fun showEpisodeDetails(playerEpisode: PlayerEpisode) { @@ -63,7 +72,7 @@ class JetcasterAppState( } fun playEpisode() { - navHostController.navigate(Screen.Player.route) + navigate(Screen.Player) } fun backToHome() { @@ -82,48 +91,60 @@ fun rememberJetcasterAppState( sealed interface Screen { val route: String + val index: Int data object Discover : Screen { override val route = "/discover" + override val index = 0 } data object Library : Screen { override val route = "library" + override val index = 1 } data object Search : Screen { override val route = "search" + override val index = 2 } data object Profile : Screen { override val route = "profile" + override val index = 3 } data object Settings : Screen { override val route: String = "settings" + override val index = 4 } data class Podcast(private val podcastUri: String) : Screen { override val route = "$ROOT/$podcastUri" + override val index = Companion.index companion object : Screen { private const val ROOT = "podcast" const val PARAMETER_NAME = "podcastUri" override val route = "$ROOT/{$PARAMETER_NAME}" + override val index = 5 } } data class Episode(private val episodeUri: String) : Screen { override val route: String = "$ROOT/$episodeUri" + override val index = Companion.index + companion object : Screen { private const val ROOT = "episode" const val PARAMETER_NAME = "episodeUri" override val route = "$ROOT/{$PARAMETER_NAME}" + override val index = 6 } } data object Player : Screen { override val route = "player" + override val index = 7 } }