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] Wear - adds navigation to player, cleanup #1316

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ data class PlayerEpisode(
val author: String = "",
val summary: String = "",
val podcastImageUrl: String = "",
val uri: String = ""
) {
constructor(podcastInfo: PodcastInfo, episodeInfo: EpisodeInfo) : this(
title = episodeInfo.title,
Expand All @@ -39,6 +40,7 @@ data class PlayerEpisode(
author = episodeInfo.author,
summary = episodeInfo.summary,
podcastImageUrl = podcastInfo.imageUrl,
uri = episodeInfo.uri
)
}

Expand All @@ -49,4 +51,5 @@ fun EpisodeToPodcast.toPlayerEpisode(): PlayerEpisode =
podcastName = podcast.title,
summary = episode.summary ?: "",
podcastImageUrl = podcast.imageUrl ?: "",
uri = episode.uri
)
2 changes: 2 additions & 0 deletions Jetcaster/wear/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ android {
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.majorVersion
freeCompilerArgs = freeCompilerArgs + "-opt-in=kotlin.RequiresOptIn"
freeCompilerArgs = freeCompilerArgs + "-opt-in=com.google.android.horologist.annotations.ExperimentalHorologistApi"
}
buildFeatures {
compose true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,113 +14,22 @@
* limitations under the License.
*/

@file:OptIn(ExperimentalHorologistApi::class, ExperimentalWearFoundationApi::class)

package com.example.jetcaster

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.wear.compose.foundation.ExperimentalWearFoundationApi
import androidx.wear.compose.material.TimeText
import androidx.wear.compose.navigation.composable
import androidx.wear.compose.navigation.rememberSwipeDismissableNavController
import androidx.wear.compose.navigation.rememberSwipeDismissableNavHostState
import com.example.jetcaster.theme.WearAppTheme
import com.example.jetcaster.ui.JetcasterNavController.navigateToLatestEpisode
import com.example.jetcaster.ui.JetcasterNavController.navigateToUpNext
import com.example.jetcaster.ui.JetcasterNavController.navigateToYourPodcast
import com.example.jetcaster.ui.LatestEpisodes
import com.example.jetcaster.ui.home.HomeScreen
import com.example.jetcaster.ui.library.LatestEpisodesScreen
import com.example.jetcaster.ui.player.PlayerScreen
import com.google.android.horologist.annotations.ExperimentalHorologistApi
import com.google.android.horologist.audio.ui.VolumeViewModel
import com.google.android.horologist.compose.layout.ScreenScaffold
import com.google.android.horologist.compose.layout.rememberColumnState
import com.google.android.horologist.media.ui.navigation.MediaNavController.navigateToVolume
import com.google.android.horologist.media.ui.navigation.MediaPlayerScaffold
import com.google.android.horologist.media.ui.snackbar.SnackbarManager
import com.google.android.horologist.media.ui.snackbar.SnackbarViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState)

setContent {
installSplashScreen()
WearApp()
}
}
}

@OptIn(ExperimentalHorologistApi::class)
@Composable
fun WearApp() {

val navController = rememberSwipeDismissableNavController()
val navHostState = rememberSwipeDismissableNavHostState()
val volumeViewModel: VolumeViewModel = viewModel(factory = VolumeViewModel.Factory)
val snackBarManager: SnackbarManager = SnackbarManager()
val snackbarViewModel: SnackbarViewModel = SnackbarViewModel(snackBarManager)

WearAppTheme {
MediaPlayerScaffold(
playerScreen = {
PlayerScreen(
modifier = Modifier.fillMaxSize(),
volumeViewModel = volumeViewModel,
onVolumeClick = {
navController.navigateToVolume()
},
)
},
libraryScreen = {
HomeScreen(
onLatestEpisodeClick = { navController.navigateToLatestEpisode() },
onYourPodcastClick = { navController.navigateToYourPodcast() },
onUpNextClick = { navController.navigateToUpNext() },
onErrorDialogCancelClick = { navController.popBackStack() }
)
},
categoryEntityScreen = { _, _ -> },
mediaEntityScreen = {},
playlistsScreen = {},
settingsScreen = {},

navHostState = navHostState,
snackbarViewModel = snackbarViewModel,
volumeViewModel = volumeViewModel,
timeText = {
TimeText()
},
deepLinkPrefix = "",
navController = navController,
additionalNavRoutes = {
composable(
route = LatestEpisodes.navRoute,
) {
val columnState = rememberColumnState()

ScreenScaffold(scrollState = columnState) {
LatestEpisodesScreen(
columnState = columnState,
playlistName = stringResource(id = R.string.latest_episodes),
onShuffleButtonClick = {},
onPlayButtonClick = {}
)
}
}
},

)
}
}
115 changes: 115 additions & 0 deletions Jetcaster/wear/src/main/java/com/example/jetcaster/WearApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.jetcaster

/*
* Copyright 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.wear.compose.navigation.composable
import androidx.wear.compose.navigation.rememberSwipeDismissableNavController
import androidx.wear.compose.navigation.rememberSwipeDismissableNavHostState
import com.example.jetcaster.theme.WearAppTheme
import com.example.jetcaster.ui.JetcasterNavController.navigateToLatestEpisode
import com.example.jetcaster.ui.JetcasterNavController.navigateToUpNext
import com.example.jetcaster.ui.JetcasterNavController.navigateToYourPodcast
import com.example.jetcaster.ui.LatestEpisodes
import com.example.jetcaster.ui.home.HomeScreen
import com.example.jetcaster.ui.library.LatestEpisodesScreen
import com.example.jetcaster.ui.player.PlayerScreen
import com.google.android.horologist.audio.ui.VolumeViewModel
import com.google.android.horologist.media.ui.navigation.MediaNavController.navigateToPlayer
import com.google.android.horologist.media.ui.navigation.MediaNavController.navigateToVolume
import com.google.android.horologist.media.ui.navigation.MediaPlayerScaffold
import com.google.android.horologist.media.ui.snackbar.SnackbarManager
import com.google.android.horologist.media.ui.snackbar.SnackbarViewModel

@Composable
fun WearApp() {

val navController = rememberSwipeDismissableNavController()
val navHostState = rememberSwipeDismissableNavHostState()
val volumeViewModel: VolumeViewModel = viewModel(factory = VolumeViewModel.Factory)

// TODO remove from MediaPlayerScaffold
val snackBarManager: SnackbarManager = SnackbarManager()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these needed or can these be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's leave them for now as I will need to add snackbar messages anyway for when added to queues.

val snackbarViewModel: SnackbarViewModel = SnackbarViewModel(snackBarManager)

WearAppTheme {
MediaPlayerScaffold(
playerScreen = {
PlayerScreen(
modifier = Modifier.fillMaxSize(),
volumeViewModel = volumeViewModel,
onVolumeClick = {
navController.navigateToVolume()
},
)
},
libraryScreen = {
HomeScreen(
onLatestEpisodeClick = { navController.navigateToLatestEpisode() },
onYourPodcastClick = { navController.navigateToYourPodcast() },
onUpNextClick = { navController.navigateToUpNext() }
)
},
categoryEntityScreen = { _, _ -> },
mediaEntityScreen = {},
playlistsScreen = {},
settingsScreen = {},

navHostState = navHostState,
snackbarViewModel = snackbarViewModel,
volumeViewModel = volumeViewModel,
deepLinkPrefix = "",
navController = navController,
additionalNavRoutes = {
composable(
route = LatestEpisodes.navRoute,
) {
LatestEpisodesScreen(
playlistName = stringResource(id = R.string.latest_episodes),
onShuffleButtonClick = {
// navController.navigateToPlayer(it[0].episode.uri)
},
onPlayButtonClick = {
navController.navigateToPlayer()
}
)
}
},

)
}
}
Loading