@@ -12,16 +12,17 @@ import androidx.navigation.navOptions
12
12
import com.espressodev.gptmap.core.common.NetworkMonitor
13
13
import com.espressodev.gptmap.core.common.snackbar.SnackbarManager
14
14
import com.espressodev.gptmap.core.common.snackbar.SnackbarMessage.Companion.toMessage
15
- import com.espressodev.gptmap.feature.favourite.FavouriteRoute
15
+ import com.espressodev.gptmap.feature.favourite.Favourite
16
16
import com.espressodev.gptmap.feature.favourite.navigateToFavourite
17
- import com.espressodev.gptmap.feature.map.MapRouteWithArg
17
+ import com.espressodev.gptmap.feature.map.Map
18
18
import com.espressodev.gptmap.feature.map.navigateToMap
19
- import com.espressodev.gptmap.feature.screenshot_gallery.ScreenshotGalleryRoute
19
+ import com.espressodev.gptmap.feature.map.toDestinationString
20
+ import com.espressodev.gptmap.feature.screenshot_gallery.ScreenshotGallery
20
21
import com.espressodev.gptmap.feature.screenshot_gallery.navigateToScreenshotGallery
21
22
import com.espressodev.gptmap.navigation.TopLevelDestination
22
23
import com.espressodev.gptmap.navigation.TopLevelDestination.FAVOURITE
23
24
import com.espressodev.gptmap.navigation.TopLevelDestination.MAP
24
- import com.espressodev.gptmap.navigation.TopLevelDestination.SCREENSHOT_GALLERY
25
+ import com.espressodev.gptmap.navigation.TopLevelDestination.SCREENSHOTGALLERY
25
26
import kotlinx.coroutines.CoroutineScope
26
27
import kotlinx.coroutines.flow.SharingStarted
27
28
import kotlinx.coroutines.flow.filterNotNull
@@ -36,7 +37,7 @@ class GmAppState(
36
37
val snackbarHostState : SnackbarHostState ,
37
38
private val snackbarManager : SnackbarManager ,
38
39
private val resources : Resources ,
39
- coroutineScope : CoroutineScope
40
+ coroutineScope : CoroutineScope ,
40
41
) {
41
42
init {
42
43
coroutineScope.launch {
@@ -67,24 +68,24 @@ class GmAppState(
67
68
.currentBackStackEntryAsState().value?.destination
68
69
69
70
val currentTopLevelDestination: TopLevelDestination ?
70
- @Composable get() = when (currentDestination?.route) {
71
- MapRouteWithArg -> MAP
72
- ScreenshotGalleryRoute -> SCREENSHOT_GALLERY
73
- FavouriteRoute -> FAVOURITE
71
+ @Composable get() = when (currentDestination?.route?.substringAfterLast( " . " ) ) {
72
+ Map ().toDestinationString() -> MAP
73
+ ScreenshotGallery .toString() -> SCREENSHOTGALLERY
74
+ Favourite .toString() -> FAVOURITE
74
75
else -> null
75
76
}
76
77
77
78
fun navigateToTopLevelDestination (topLevelDestination : TopLevelDestination ) {
78
79
val topLevelNavOptions = navOptions {
79
- popUpTo(MapRouteWithArg ) {
80
+ popUpTo(Map () ) {
80
81
saveState = true
81
82
}
82
83
launchSingleTop = true
83
84
restoreState = true
84
85
}
85
86
when (topLevelDestination) {
86
87
MAP -> navController.navigateToMap(navOptions = topLevelNavOptions)
87
- SCREENSHOT_GALLERY -> navController.navigateToScreenshotGallery(topLevelNavOptions)
88
+ SCREENSHOTGALLERY -> navController.navigateToScreenshotGallery(topLevelNavOptions)
88
89
FAVOURITE -> navController.navigateToFavourite(topLevelNavOptions)
89
90
}
90
91
}
0 commit comments