Skip to content

Commit

Permalink
Update with the feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
chikoski committed Apr 22, 2024
1 parent 1e968b8 commit a01eadc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +30,7 @@ data class CategoryInfoList(val member: List<CategoryInfo>) : List<CategoryInfo>

companion object {
fun from(list: List<Category>): CategoryInfoList {
val member = list.map(Category::intoCategoryInfo)
val member = list.map(Category::asExternalModel)
return CategoryInfoList(member)
}
}
Expand All @@ -38,7 +39,3 @@ data class CategoryInfoList(val member: List<CategoryInfo>) : List<CategoryInfo>
private fun CategoryInfo.intoCategory(): Category {
return Category(id, name)
}

private fun Category.intoCategoryInfo(): CategoryInfo {
return CategoryInfo(id, name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) },
) {
Expand All @@ -77,29 +81,29 @@ 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) }
) {
Text(text = "Library")
}
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) }
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,44 +27,52 @@ import com.example.jetcaster.core.model.PlayerEpisode
class JetcasterAppState(
val navHostController: NavHostController
) {

private var _currentScreenState = mutableStateOf<Screen>(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) {
showEpisodeDetails(playerEpisode.uri)
}

fun playEpisode() {
navHostController.navigate(Screen.Player.route)
navigate(Screen.Player)
}

fun backToHome() {
Expand All @@ -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
}
}

0 comments on commit a01eadc

Please sign in to comment.