|
1 | 1 | /*
|
2 | 2 | * Infomaniak Core - Android
|
3 |
| - * Copyright (C) 2022-2024 Infomaniak Network SA |
| 3 | + * Copyright (C) 2022-2025 Infomaniak Network SA |
4 | 4 | *
|
5 | 5 | * This program is free software: you can redistribute it and/or modify
|
6 | 6 | * it under the terms of the GNU General Public License as published by
|
@@ -53,6 +53,7 @@ import androidx.lifecycle.DefaultLifecycleObserver
|
53 | 53 | import androidx.lifecycle.Lifecycle.Event
|
54 | 54 | import androidx.lifecycle.LifecycleEventObserver
|
55 | 55 | import androidx.lifecycle.LifecycleOwner
|
| 56 | +import androidx.navigation.NavController |
56 | 57 | import androidx.navigation.NavDirections
|
57 | 58 | import androidx.navigation.NavOptions
|
58 | 59 | import androidx.navigation.Navigator
|
@@ -362,14 +363,18 @@ fun ImageView.loadAvatar(
|
362 | 363 | }
|
363 | 364 |
|
364 | 365 | fun Fragment.canNavigate(currentClassName: String? = null): Boolean {
|
365 |
| - val className = currentClassName ?: when (val currentDestination = findNavController().currentDestination) { |
| 366 | + return findNavController().canNavigate(allowedStartingClassName = javaClass.name, currentClassName) |
| 367 | +} |
| 368 | + |
| 369 | +fun NavController.canNavigate(allowedStartingClassName: String, currentClassName: String? = null): Boolean { |
| 370 | + val className = currentClassName ?: when (val currentDestination = currentDestination) { |
366 | 371 | is FragmentNavigator.Destination -> currentDestination.className
|
367 | 372 | is DialogFragmentNavigator.Destination -> currentDestination.className
|
368 |
| - null -> javaClass.name |
| 373 | + null -> allowedStartingClassName |
369 | 374 | else -> null
|
370 | 375 | }
|
371 | 376 |
|
372 |
| - return javaClass.name == className |
| 377 | + return allowedStartingClassName == className |
373 | 378 | }
|
374 | 379 |
|
375 | 380 | fun Fragment.safeNavigate(directions: NavDirections, currentClassName: String? = null) = with(findNavController()) {
|
|
0 commit comments