|
| 1 | +/* |
| 2 | + * Copyright 2024 The Android Open Source Project |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.example.jetcaster |
| 18 | + |
| 19 | +/* |
| 20 | + * Copyright 2022 The Android Open Source Project |
| 21 | + * |
| 22 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 23 | + * you may not use this file except in compliance with the License. |
| 24 | + * You may obtain a copy of the License at |
| 25 | + * |
| 26 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 27 | + * |
| 28 | + * Unless required by applicable law or agreed to in writing, software |
| 29 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 30 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 31 | + * See the License for the specific language governing permissions and |
| 32 | + * limitations under the License. |
| 33 | + */ |
| 34 | + |
| 35 | +import androidx.compose.foundation.layout.fillMaxSize |
| 36 | +import androidx.compose.runtime.Composable |
| 37 | +import androidx.compose.ui.Modifier |
| 38 | +import androidx.compose.ui.res.stringResource |
| 39 | +import androidx.lifecycle.viewmodel.compose.viewModel |
| 40 | +import androidx.wear.compose.navigation.composable |
| 41 | +import androidx.wear.compose.navigation.rememberSwipeDismissableNavController |
| 42 | +import androidx.wear.compose.navigation.rememberSwipeDismissableNavHostState |
| 43 | +import com.example.jetcaster.theme.WearAppTheme |
| 44 | +import com.example.jetcaster.ui.JetcasterNavController.navigateToLatestEpisode |
| 45 | +import com.example.jetcaster.ui.JetcasterNavController.navigateToUpNext |
| 46 | +import com.example.jetcaster.ui.JetcasterNavController.navigateToYourPodcast |
| 47 | +import com.example.jetcaster.ui.LatestEpisodes |
| 48 | +import com.example.jetcaster.ui.home.HomeScreen |
| 49 | +import com.example.jetcaster.ui.library.LatestEpisodesScreen |
| 50 | +import com.example.jetcaster.ui.player.PlayerScreen |
| 51 | +import com.google.android.horologist.audio.ui.VolumeViewModel |
| 52 | +import com.google.android.horologist.media.ui.navigation.MediaNavController.navigateToPlayer |
| 53 | +import com.google.android.horologist.media.ui.navigation.MediaNavController.navigateToVolume |
| 54 | +import com.google.android.horologist.media.ui.navigation.MediaPlayerScaffold |
| 55 | +import com.google.android.horologist.media.ui.snackbar.SnackbarManager |
| 56 | +import com.google.android.horologist.media.ui.snackbar.SnackbarViewModel |
| 57 | + |
| 58 | +@Composable |
| 59 | +fun WearApp() { |
| 60 | + |
| 61 | + val navController = rememberSwipeDismissableNavController() |
| 62 | + val navHostState = rememberSwipeDismissableNavHostState() |
| 63 | + val volumeViewModel: VolumeViewModel = viewModel(factory = VolumeViewModel.Factory) |
| 64 | + |
| 65 | + // TODO remove from MediaPlayerScaffold |
| 66 | + val snackBarManager: SnackbarManager = SnackbarManager() |
| 67 | + val snackbarViewModel: SnackbarViewModel = SnackbarViewModel(snackBarManager) |
| 68 | + |
| 69 | + WearAppTheme { |
| 70 | + MediaPlayerScaffold( |
| 71 | + playerScreen = { |
| 72 | + PlayerScreen( |
| 73 | + modifier = Modifier.fillMaxSize(), |
| 74 | + volumeViewModel = volumeViewModel, |
| 75 | + onVolumeClick = { |
| 76 | + navController.navigateToVolume() |
| 77 | + }, |
| 78 | + ) |
| 79 | + }, |
| 80 | + libraryScreen = { |
| 81 | + HomeScreen( |
| 82 | + onLatestEpisodeClick = { navController.navigateToLatestEpisode() }, |
| 83 | + onYourPodcastClick = { navController.navigateToYourPodcast() }, |
| 84 | + onUpNextClick = { navController.navigateToUpNext() } |
| 85 | + ) |
| 86 | + }, |
| 87 | + categoryEntityScreen = { _, _ -> }, |
| 88 | + mediaEntityScreen = {}, |
| 89 | + playlistsScreen = {}, |
| 90 | + settingsScreen = {}, |
| 91 | + |
| 92 | + navHostState = navHostState, |
| 93 | + snackbarViewModel = snackbarViewModel, |
| 94 | + volumeViewModel = volumeViewModel, |
| 95 | + deepLinkPrefix = "", |
| 96 | + navController = navController, |
| 97 | + additionalNavRoutes = { |
| 98 | + composable( |
| 99 | + route = LatestEpisodes.navRoute, |
| 100 | + ) { |
| 101 | + LatestEpisodesScreen( |
| 102 | + playlistName = stringResource(id = R.string.latest_episodes), |
| 103 | + onShuffleButtonClick = { |
| 104 | + // navController.navigateToPlayer(it[0].episode.uri) |
| 105 | + }, |
| 106 | + onPlayButtonClick = { |
| 107 | + navController.navigateToPlayer() |
| 108 | + } |
| 109 | + ) |
| 110 | + } |
| 111 | + }, |
| 112 | + |
| 113 | + ) |
| 114 | + } |
| 115 | +} |
0 commit comments