@@ -70,7 +70,7 @@ class MainActivity : AndromedaActivity() {
7070 private val binding: ActivityMainBinding
7171 get() = _binding !!
7272
73- private val navController: NavController
73+ private val navController: NavController ?
7474 get() = findNavController()
7575
7676 val errorBanner: ErrorBannerView
@@ -146,7 +146,7 @@ class MainActivity : AndromedaActivity() {
146146 * Update the bottom nav selection based on the current navigation destination
147147 */
148148 private fun updateBottomNavSelection () {
149- val currentNavId = navController.currentDestination?.id
149+ val currentNavId = navController? .currentDestination?.id
150150 val tools = Tools .getTools(this )
151151 val selectedTool = tools.firstOrNull { it.isOpen(currentNavId ? : 0 ) }
152152 // If the tool appears in the bottom nav, select it. Otherwise, select the Tools tab
@@ -222,7 +222,7 @@ class MainActivity : AndromedaActivity() {
222222 appInitialized = true
223223 updateBottomNavigation()
224224
225- navController.addOnDestinationChangedListener { _, _, _ ->
225+ navController? .addOnDestinationChangedListener { _, _, _ ->
226226 binding.quickActionsSheet.close()
227227 updateBottomNavSelection()
228228 }
@@ -280,11 +280,11 @@ class MainActivity : AndromedaActivity() {
280280 errorBanner.dismissAll()
281281
282282 if (shouldReloadNavigation) {
283- navController.navigate(
283+ navController? .navigate(
284284 binding.bottomNavigation.selectedItemId,
285285 null ,
286286 NavOptions .Builder ().setPopUpTo(
287- navController.currentDestination?.id ? : R .id.action_experimental_tools, true
287+ navController? .currentDestination?.id ? : R .id.action_experimental_tools, true
288288 ).build()
289289 )
290290 }
@@ -316,7 +316,7 @@ class MainActivity : AndromedaActivity() {
316316 if (intent.action == TrailSenseExceptionHandler .ACTION_TOOL_ERROR ) {
317317 val toolId = intent.getLongExtra(TrailSenseExceptionHandler .EXTRA_TOOL_ID , 0L )
318318 val error = intent.getStringExtra(TrailSenseExceptionHandler .EXTRA_ERROR ) ? : " "
319- navController.navigate(
319+ navController? .navigate(
320320 R .id.fragmentToolErrorHandler,
321321 bundleOf(" tool_id" to toolId, " error" to error)
322322 )
@@ -327,8 +327,8 @@ class MainActivity : AndromedaActivity() {
327327 val toolId = intent.getLongExtra(" tool_id" , - 1 )
328328 val tool = Tools .getTool(this , toolId)
329329 if (tool != null ) {
330- if (navController.currentDestination?.id != tool.navAction) {
331- navController.navigate(tool.navAction)
330+ if (navController? .currentDestination?.id != tool.navAction) {
331+ navController? .navigate(tool.navAction)
332332 }
333333 binding.bottomNavigation.selectedItemId = tool.navAction
334334 }
@@ -361,7 +361,7 @@ class MainActivity : AndromedaActivity() {
361361 if (savedInstanceState.containsKey(" navigation" )) {
362362 tryOrNothing {
363363 val bundle = savedInstanceState.getBundle(" navigation_arguments" )
364- navController.navigate(savedInstanceState.getInt(" navigation" ), bundle)
364+ navController? .navigate(savedInstanceState.getInt(" navigation" ), bundle)
365365 }
366366 }
367367 }
@@ -370,10 +370,10 @@ class MainActivity : AndromedaActivity() {
370370 super .onSaveInstanceState(outState)
371371 tryOrLog {
372372 outState.putInt(" page" , binding.bottomNavigation.selectedItemId)
373- navController.currentBackStackEntry?.arguments?.let {
373+ navController? .currentBackStackEntry?.arguments?.let {
374374 outState.putBundle(" navigation_arguments" , it)
375375 }
376- navController.currentDestination?.id?.let {
376+ navController? .currentDestination?.id?.let {
377377 outState.putInt(" navigation" , it)
378378 }
379379 }
@@ -412,7 +412,7 @@ class MainActivity : AndromedaActivity() {
412412 }
413413
414414 private fun getVolumeAction (): VolumeAction ? {
415- val navigationId = navController.currentDestination?.id
415+ val navigationId = navController? .currentDestination?.id
416416 val fragment = getFragment() as ? AndromedaFragment ? : return null
417417 val tools = Tools .getTools(this )
418418
@@ -492,7 +492,7 @@ class MainActivity : AndromedaActivity() {
492492 getString(R .string.tools)
493493 ).setIcon(R .drawable.apps)
494494 .setOnMenuItemClickListener {
495- if (navController.currentDestination?.id == R .id.action_experimental_tools && ! binding.quickActionsSheet.isOpen()) {
495+ if (navController? .currentDestination?.id == R .id.action_experimental_tools && ! binding.quickActionsSheet.isOpen()) {
496496 val searchinput = findViewById<TextInputEditText >(R .id.search_view_edit_text)
497497 if (searchinput?.requestFocus() == true ) {
498498 val imm = getSystemService(InputMethodManager ::class .java)
@@ -525,15 +525,16 @@ class MainActivity : AndromedaActivity() {
525525 initializeNavGraph(initialItem)
526526 }
527527 // Bind to navigation
528- binding.bottomNavigation.setupWithNavController(navController , false )
528+ navController?. let { binding.bottomNavigation.setupWithNavController(it , false ) }
529529
530530 updateBottomNavSelection()
531531 }
532532
533533 private fun initializeNavGraph (startDestination : Int ) {
534- val navGraph = navController.navInflater.inflate(R .navigation.nav_graph)
534+ val nav = navController ? : return
535+ val navGraph = nav.navInflater.inflate(R .navigation.nav_graph)
535536 navGraph.setStartDestination(startDestination)
536- navController .graph = navGraph
537+ nav .graph = navGraph
537538 }
538539
539540 private fun onPowerSavingModeChanged (data : Bundle ): Boolean {
0 commit comments