@@ -9,13 +9,15 @@ import androidx.activity.ComponentActivity
99import androidx.activity.compose.setContent
1010import androidx.activity.enableEdgeToEdge
1111import androidx.compose.runtime.mutableStateOf
12+ import androidx.compose.runtime.remember
1213import androidx.lifecycle.Lifecycle
1314import androidx.lifecycle.lifecycleScope
1415import androidx.lifecycle.repeatOnLifecycle
15- import androidx.navigation.NavHostController
16- import androidx.navigation.compose.rememberNavController
16+ import androidx.navigation3.runtime.NavKey
17+ import androidx.navigation3.runtime.rememberNavBackStack
1718import com.darkrockstudios.app.securecamera.auth.AuthorizationRepository
18- import com.darkrockstudios.app.securecamera.navigation.AppDestinations
19+ import com.darkrockstudios.app.securecamera.navigation.*
20+ import com.darkrockstudios.app.securecamera.navigation.Camera
1921import com.darkrockstudios.app.securecamera.preferences.AppPreferencesDataSource
2022import kotlinx.coroutines.delay
2123import kotlinx.coroutines.flow.firstOrNull
@@ -31,7 +33,7 @@ class MainActivity : ComponentActivity() {
3133 private val locationRepository: LocationRepository by inject()
3234 private val preferences: AppPreferencesDataSource by inject()
3335 private val authorizationRepository: AuthorizationRepository by inject()
34- lateinit var navController: NavHostController
36+ lateinit var navController: NavController
3537
3638 override fun onCreate (savedInstanceState : Bundle ? ) {
3739 super .onCreate(savedInstanceState)
@@ -45,33 +47,34 @@ class MainActivity : ComponentActivity() {
4547
4648 enableEdgeToEdge()
4749
48- val startDestination = determineStartRoute ()
50+ val startKey = determineStartKey ()
4951 setContent {
50- navController = rememberNavController()
51- App (capturePhoto, startDestination, navController)
52+ val backStack = rememberNavBackStack(startKey)
53+ val controller = remember(backStack) { Nav3CompatController (backStack) }
54+ navController = controller
55+ App (capturePhoto, backStack, navController)
5256 }
5357
5458 startKeepAliveWatcher()
5559 }
5660
57- private fun determineStartRoute (): String {
61+ private fun determineStartKey (): NavKey {
5862 val photosToImport = receiveFiles()
5963 val hasCompletedIntro = runBlocking { preferences.hasCompletedIntro.firstOrNull() ? : false }
60- val startDestination = if (hasCompletedIntro) {
61- val targetDestination = if (photosToImport.isNotEmpty()) {
62- AppDestinations .createImportPhotosRoute( photosToImport)
64+ return if (hasCompletedIntro) {
65+ val targetKey : DestinationKey = if (photosToImport.isNotEmpty()) {
66+ ImportPhotos ( PhotoImportJob ( photosToImport) )
6367 } else {
64- AppDestinations . CAMERA_ROUTE
68+ Camera
6569 }
6670 if (authorizationRepository.checkSessionValidity()) {
67- targetDestination
71+ targetKey
6872 } else {
69- AppDestinations .createPinVerificationRoute(targetDestination )
73+ PinVerification (targetKey )
7074 }
7175 } else {
72- AppDestinations . INTRODUCTION_ROUTE
76+ Introduction
7377 }
74- return startDestination
7578 }
7679
7780 override fun onKeyDown (keyCode : Int , event : KeyEvent ? ): Boolean {
@@ -117,13 +120,13 @@ class MainActivity : ComponentActivity() {
117120 val intent = getIntent()
118121
119122 return if (Intent .ACTION_SEND == intent.action && intent.type != null ) {
120- if (intent.type?.startsWith(" image/jpeg " ) == true ) {
123+ if (intent.type?.startsWith(" image/" ) == true ) {
121124 handleSingleImage(intent)
122125 } else {
123126 emptyList()
124127 }
125128 } else if (Intent .ACTION_SEND_MULTIPLE == intent.action && intent.type != null ) {
126- if (intent.type?.startsWith(" image/jpeg " ) == true ) {
129+ if (intent.type?.startsWith(" image/" ) == true ) {
127130 handleMultipleImages(intent)
128131 } else {
129132 emptyList()
0 commit comments