Skip to content
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 @@ -20,16 +20,22 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.navigation.NavHostController
import androidx.wear.compose.navigation.rememberSwipeDismissableNavController
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
lateinit var navController: NavHostController

override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState)

setContent {
WearApp()
navController = rememberSwipeDismissableNavController()

WearApp(navController)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import androidx.wear.compose.navigation.SwipeDismissableNavHost
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.Episode
Expand Down Expand Up @@ -57,16 +57,14 @@ import com.google.android.horologist.media.ui.navigation.NavigationScreens
import com.google.android.horologist.media.ui.screens.playerlibrarypager.PlayerLibraryPagerScreen

@Composable
fun WearApp() {

val navController = rememberSwipeDismissableNavController()
fun WearApp(navController: NavHostController) {
val navHostState = rememberSwipeDismissableNavHostState()
val volumeViewModel: VolumeViewModel = viewModel(factory = VolumeViewModel.Factory)

WearAppTheme {
AppScaffold {
SwipeDismissableNavHost(
startDestination = NavigationScreens.Player.navRoute,
startDestination = NavigationScreens.Player.playerDestination(),
navController = navController,
modifier = Modifier.background(Color.Transparent),
state = navHostState,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2025 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

import androidx.compose.ui.test.junit4.createAndroidComposeRule
import com.example.jetcaster.ui.JetcasterNavController.navigateToUpNext
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode

@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34])
@GraphicsMode(GraphicsMode.Mode.NATIVE)
class NavigationTest {
@get:Rule
val rule = createAndroidComposeRule(MainActivity::class.java)

@Test
fun launchAndNavigate() {
val activity = rule.activity

val navController = activity.navController

rule.waitUntil {
navController.currentDestination?.route != null
}

assertEquals("player?page={page}", navController.currentDestination?.route)

navController.navigateToUpNext()

assertEquals("upNext", navController.currentDestination?.route)
}
}