Skip to content

Commit

Permalink
Fix another navigation issue upon starting of the app
Browse files Browse the repository at this point in the history
  • Loading branch information
CNugteren committed Feb 11, 2025
1 parent df4b2dd commit 486bbdc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/src/main/java/foss/cnugteren/nlweer/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MainActivity : AppCompatActivity() {
var gpsLon: Float? = null
private var baseContextWrappingDelegate: AppCompatDelegate? = null
private lateinit var binding: ActivityMainBinding
private var navGraphCreated: Boolean = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -120,7 +121,10 @@ class MainActivity : AppCompatActivity() {
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
}

private fun createNavGraph() {
fun createNavGraph() {
if (navGraphCreated) {
return
}
// This is instead of a hard-coded mobile_navigation.xml file. That file still exists though
// to define the R.id values
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
Expand Down Expand Up @@ -173,7 +177,7 @@ class MainActivity : AppCompatActivity() {
}
}
}

navGraphCreated = true
}

fun setMenuItemsVisibility() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class MapFragment : Fragment() {
): View? {
_binding = FragmentKnmiBinding.inflate(inflater, container, false)
val activity = this.activity as MainActivity
activity.createNavGraph() // only runs if it wasn't created yet

// Iterate over all items to find the current one and set the private variables accordingly
val navController = NavHostFragment.findNavController(this)
Expand Down

0 comments on commit 486bbdc

Please sign in to comment.