Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Jetcaster]: Podcast screen #1296

Merged
merged 12 commits into from
Apr 1, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@

package com.example.jetcaster.ui

import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.core.EaseIn
import androidx.compose.animation.core.EaseOut
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
Expand All @@ -27,9 +34,14 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.window.layout.DisplayFeature
import com.example.jetcaster.R
import com.example.jetcaster.core.data.di.Graph.episodePlayer
import com.example.jetcaster.core.data.di.Graph.episodeStore
import com.example.jetcaster.core.data.di.Graph.podcastStore
import com.example.jetcaster.ui.home.Home
import com.example.jetcaster.ui.player.PlayerScreen
import com.example.jetcaster.ui.player.PlayerViewModel
import com.example.jetcaster.ui.podcast.PodcastDetailsScreen
import com.example.jetcaster.ui.podcast.PodcastDetailsViewModel

@Composable
fun JetcasterApp(
Expand All @@ -44,9 +56,9 @@ fun JetcasterApp(
) {
composable(Screen.Home.route) { backStackEntry ->
Home(
navigateToPlayer = { episodeUri ->
appState.navigateToPlayer(episodeUri, backStackEntry)
}
navigateToPodcastDetails = { podcast ->
appState.navigateToPodcastDetails(podcast.uri, backStackEntry)
},
)
}
composable(Screen.Player.route) { backStackEntry ->
Expand All @@ -63,6 +75,46 @@ fun JetcasterApp(
onBackPress = appState::navigateBack
)
}
composable(
route = Screen.PodcastDetails.route,
enterTransition = {
fadeIn(
animationSpec = tween(
300, easing = LinearEasing
)
) + slideIntoContainer(
animationSpec = tween(300, easing = EaseIn),
towards = AnimatedContentTransitionScope.SlideDirection.Start
)
},
exitTransition = {
fadeOut(
animationSpec = tween(
300, easing = LinearEasing
)
) + slideOutOfContainer(
animationSpec = tween(300, easing = EaseOut),
towards = AnimatedContentTransitionScope.SlideDirection.End
)
}
) { backStackEntry ->
val podcastDetailsViewModel: PodcastDetailsViewModel = viewModel(
factory = PodcastDetailsViewModel.provideFactory(
episodeStore = episodeStore,
podcastStore = podcastStore,
episodePlayer = episodePlayer,
owner = backStackEntry,
defaultArgs = backStackEntry.arguments
)
)
PodcastDetailsScreen(
viewModel = podcastDetailsViewModel,
navigateToPlayer = { episodePlayer ->
appState.navigateToPlayer(episodePlayer.uri, backStackEntry)
},
navigateBack = appState::navigateBack
)
}
}
} else {
OfflineDialog { appState.refreshOnline() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,20 @@ import androidx.navigation.compose.rememberNavController
*/
sealed class Screen(val route: String) {
object Home : Screen("home")
object Player : Screen("player/{episodeUri}") {
object Player : Screen("player/{$ARG_EPISODE_URI}") {
fun createRoute(episodeUri: String) = "player/$episodeUri"
}

object PodcastDetails : Screen("podcast/{$ARG_PODCAST_URI}") {

val PODCAST_URI = "podcastUri"
fun createRoute(podcastUri: String) = "podcast/$podcastUri"
}

companion object {
val ARG_PODCAST_URI = "podcastUri"
val ARG_EPISODE_URI = "episodeUri"
}
}

@Composable
Expand Down Expand Up @@ -70,6 +81,13 @@ class JetcasterAppState(
}
}

fun navigateToPodcastDetails(podcastUri: String, from: NavBackStackEntry) {
if (from.lifecycleIsResumed()) {
val encodedUri = Uri.encode(podcastUri)
navController.navigate(Screen.PodcastDetails.createRoute(encodedUri))
}
}

fun navigateBack() {
navController.popBackStack()
}
Expand Down
Loading