1
1
package co.nimblehq.compose.crypto.ui.navigation
2
2
3
3
import androidx.compose.runtime.Composable
4
+ import androidx.hilt.navigation.compose.hiltViewModel
4
5
import androidx.navigation.*
5
6
import androidx.navigation.compose.*
7
+ import co.nimblehq.compose.crypto.R
8
+ import co.nimblehq.compose.crypto.extension.collectAsEffect
9
+ import co.nimblehq.compose.crypto.ui.common.AppDialogPopUp
10
+ import co.nimblehq.compose.crypto.ui.screens.MainViewModel
6
11
import co.nimblehq.compose.crypto.ui.screens.detail.DetailScreen
7
12
import co.nimblehq.compose.crypto.ui.screens.home.HomeScreen
8
13
9
14
@Composable
10
15
fun AppNavigation (
11
16
navController : NavHostController = rememberNavController(),
17
+ mainViewModel : MainViewModel = hiltViewModel(),
12
18
startDestination : String = AppDestination .Home .destination
13
19
) {
20
+
21
+ mainViewModel.isNetworkConnected.collectAsEffect { isNetworkConnected ->
22
+ if (isNetworkConnected == false ) {
23
+ val destination = AppDestination .NoNetwork
24
+
25
+ val currentRoute = navController.currentBackStackEntry?.destination?.route
26
+ if (currentRoute == AppDestination .NoNetwork .route) {
27
+ navController.popBackStack()
28
+ }
29
+
30
+ navController.navigate(destination)
31
+ }
32
+ }
14
33
NavHost (
15
34
navController = navController,
16
35
startDestination = startDestination
@@ -27,6 +46,16 @@ fun AppNavigation(
27
46
coinId = it.arguments?.getString(KEY_COIN_ID ).orEmpty()
28
47
)
29
48
}
49
+
50
+ dialog(AppDestination .NoNetwork .route) {
51
+ AppDialogPopUp (
52
+ onDismiss = { navController.popBackStack() },
53
+ onClick = { navController.popBackStack() },
54
+ message = R .string.no_internet_message,
55
+ actionText = android.R .string.ok,
56
+ title = R .string.no_internet_title
57
+ )
58
+ }
30
59
}
31
60
}
32
61
0 commit comments