diff --git a/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/MainActivity.kt b/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/MainActivity.kt index acb17a8e7a1..c37f4af6541 100644 --- a/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/MainActivity.kt +++ b/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/MainActivity.kt @@ -35,6 +35,7 @@ import au.com.shiftyjelly.pocketcasts.wear.ui.downloads.DownloadsScreen import au.com.shiftyjelly.pocketcasts.wear.ui.episode.EpisodeScreenFlow import au.com.shiftyjelly.pocketcasts.wear.ui.episode.EpisodeScreenFlow.episodeGraph import au.com.shiftyjelly.pocketcasts.wear.ui.player.EffectsScreen +import au.com.shiftyjelly.pocketcasts.wear.ui.player.NowPlayingScreen import au.com.shiftyjelly.pocketcasts.wear.ui.player.PCVolumeScreen import au.com.shiftyjelly.pocketcasts.wear.ui.player.StreamingConfirmationScreen import au.com.shiftyjelly.pocketcasts.wear.ui.podcast.PodcastScreen @@ -120,7 +121,7 @@ fun WearApp( navigateToRoute = navController::navigate, toNowPlaying = { coroutineScope.launch { - pagerState.animateScrollToPage(1) + pagerState.animateScrollToPage(NowPlayingScreen.pagerIndex) } }, ) diff --git a/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/episode/EpisodeScreen.kt b/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/episode/EpisodeScreen.kt index 87b955df163..0ece3584eea 100644 --- a/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/episode/EpisodeScreen.kt +++ b/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/episode/EpisodeScreen.kt @@ -49,12 +49,16 @@ fun EpisodeScreen( navigateToConfirmDeleteDownload: () -> Unit, navigateToRemoveFromUpNextNotification: () -> Unit, navigateToStreamingConfirmation: () -> Unit, + navigateToNowPlaying: () -> Unit, ) { val viewModel = hiltViewModel() val state = viewModel.stateFlow.collectAsState().value if (state !is EpisodeViewModel.State.Loaded) return + val showNowPlaying = viewModel.showNowPlaying.collectAsState(false).value + if (showNowPlaying) navigateToNowPlaying() + val episode = state.episode val podcast = state.podcast val context = LocalContext.current diff --git a/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/episode/EpisodeScreenFlow.kt b/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/episode/EpisodeScreenFlow.kt index 529b2963511..e658efdf7a9 100644 --- a/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/episode/EpisodeScreenFlow.kt +++ b/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/episode/EpisodeScreenFlow.kt @@ -2,8 +2,10 @@ package au.com.shiftyjelly.pocketcasts.wear.ui.episode import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp @@ -18,11 +20,13 @@ import androidx.wear.compose.material.SwipeToDismissBoxState import au.com.shiftyjelly.pocketcasts.wear.ui.component.NotificationScreen import au.com.shiftyjelly.pocketcasts.wear.ui.component.NowPlayingPager import au.com.shiftyjelly.pocketcasts.wear.ui.component.ObtainConfirmationScreen +import au.com.shiftyjelly.pocketcasts.wear.ui.player.NowPlayingScreen import au.com.shiftyjelly.pocketcasts.wear.ui.player.StreamingConfirmationScreen import com.google.android.horologist.compose.layout.ScalingLazyColumnDefaults import com.google.android.horologist.compose.navscaffold.NavScaffoldViewModel import com.google.android.horologist.compose.navscaffold.composable import com.google.android.horologist.compose.navscaffold.scrollable +import kotlinx.coroutines.launch import au.com.shiftyjelly.pocketcasts.localization.R as LR object EpisodeScreenFlow { @@ -37,6 +41,7 @@ object EpisodeScreenFlow { private const val deleteDownloadNotificationScreen = "deleteDownloadNotificationScreen" private const val removeFromUpNextNotificationScreen = "removeFromUpNextNotificationScreen" + @OptIn(ExperimentalFoundationApi::class) fun NavGraphBuilder.episodeGraph( navigateToPodcast: (podcastUuid: String) -> Unit, navController: NavController, @@ -71,9 +76,13 @@ object EpisodeScreenFlow { } } + val pagerState = rememberPagerState() + val coroutineScope = rememberCoroutineScope() + @OptIn(ExperimentalFoundationApi::class) NowPlayingPager( navController = navController, + pagerState = pagerState, swipeToDismissState = swipeToDismissState, scrollableScaffoldContext = it, ) { @@ -90,6 +99,11 @@ object EpisodeScreenFlow { navigateToStreamingConfirmation = { navController.navigate(StreamingConfirmationScreen.route) }, + navigateToNowPlaying = { + coroutineScope.launch { + pagerState.animateScrollToPage(NowPlayingScreen.pagerIndex) + } + }, ) } } diff --git a/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/episode/EpisodeViewModel.kt b/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/episode/EpisodeViewModel.kt index 79574aad12e..4c9ff757342 100644 --- a/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/episode/EpisodeViewModel.kt +++ b/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/episode/EpisodeViewModel.kt @@ -36,8 +36,10 @@ import coil.request.SuccessResult import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filterIsInstance @@ -104,6 +106,10 @@ class EpisodeViewModel @Inject constructor( val stateFlow: StateFlow + // SharedFlow used for one shot operation like navigating to the Now Playing screen + private val _showNowPlaying = MutableSharedFlow() + val showNowPlaying = _showNowPlaying.asSharedFlow() + init { val episodeUuid = savedStateHandle.get(EpisodeScreenFlow.episodeUuidArgument) ?: throw IllegalStateException("EpisodeViewModel must have an episode uuid in the SavedStateHandle") @@ -259,6 +265,7 @@ class EpisodeViewModel @Inject constructor( episode = episode, playbackSource = analyticsSource, ) + _showNowPlaying.emit(true) } } diff --git a/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/player/NowPlayingScreen.kt b/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/player/NowPlayingScreen.kt index 828dde34860..367bc38d58d 100644 --- a/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/player/NowPlayingScreen.kt +++ b/wear/src/main/kotlin/au/com/shiftyjelly/pocketcasts/wear/ui/player/NowPlayingScreen.kt @@ -42,6 +42,7 @@ import au.com.shiftyjelly.pocketcasts.localization.R as LR object NowPlayingScreen { const val route = "now_playing" + const val pagerIndex = 1 } @OptIn(ExperimentalWearFoundationApi::class)