Skip to content

Commit 61b6af5

Browse files
committed
[#102] Add callback on click ok
1 parent fd3afad commit 61b6af5

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

app/src/main/java/co/nimblehq/compose/crypto/ui/navigation/AppNavigation.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ fun AppNavigation(
1818
startDestination: String = AppDestination.Home.destination
1919
) {
2020

21+
var onInternetRestore: () -> Unit = {}
22+
2123
mainViewModel.isNetworkConnected.collectAsEffect { isNetworkConnected ->
2224
if (isNetworkConnected == false) {
2325
val destination = AppDestination.NoNetwork
@@ -36,21 +38,30 @@ fun AppNavigation(
3638
) {
3739
composable(AppDestination.Home) {
3840
HomeScreen(
39-
navigator = { destination -> navController.navigate(destination) }
41+
navigator = { destination -> navController.navigate(destination) },
42+
onInternetRestore = {
43+
onInternetRestore = it
44+
}
4045
)
4146
}
4247

4348
composable(AppDestination.CoinDetail) {
4449
DetailScreen(
4550
navigator = { destination -> navController.navigate(destination) },
46-
coinId = it.arguments?.getString(KEY_COIN_ID).orEmpty()
51+
coinId = it.arguments?.getString(KEY_COIN_ID).orEmpty(),
52+
onInternetRestore = {
53+
onInternetRestore = it
54+
}
4755
)
4856
}
4957

5058
dialog(AppDestination.NoNetwork.route) {
5159
AppDialogPopUp(
5260
onDismiss = { navController.popBackStack() },
53-
onClick = { navController.popBackStack() },
61+
onClick = {
62+
navController.popBackStack()
63+
onInternetRestore.invoke()
64+
},
5465
message = R.string.no_internet_message,
5566
actionText = android.R.string.ok,
5667
title = R.string.no_internet_title

app/src/main/java/co/nimblehq/compose/crypto/ui/screens/detail/DetailScreen.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ fun DetailScreen(
5454
viewModel: DetailViewModel = hiltViewModel(),
5555
navigator: (destination: AppDestination) -> Unit,
5656
coinId: String,
57+
onInternetRestore: (() -> Unit) -> Unit
5758
) {
5859
val context = LocalContext.current
5960
LaunchedEffect(Unit) {
@@ -83,6 +84,10 @@ fun DetailScreen(
8384
LaunchedEffect(Unit) {
8485
viewModel.input.getCoinId(coinId = coinId)
8586
}
87+
88+
onInternetRestore {
89+
viewModel.input.getCoinId(coinId = coinId)
90+
}
8691
}
8792

8893
@Suppress("LongMethod", "LongParameterList")

app/src/main/java/co/nimblehq/compose/crypto/ui/screens/home/HomeScreen.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ const val TestTagCoinsLoader = "CoinsLoader"
4040
@Composable
4141
fun HomeScreen(
4242
viewModel: HomeViewModel = hiltViewModel(),
43-
navigator: (destination: AppDestination) -> Unit
43+
navigator: (destination: AppDestination) -> Unit,
44+
onInternetRestore: (() -> Unit) -> Unit
4445
) {
46+
4547
val context = LocalContext.current
4648
var rememberRefreshing by remember { mutableStateOf(false) }
4749

@@ -56,6 +58,10 @@ fun HomeScreen(
5658
}
5759
}
5860

61+
onInternetRestore {
62+
viewModel.input.loadData(isRefreshing = true)
63+
}
64+
5965
val showMyCoinsLoading: IsLoading by viewModel.output.showMyCoinsLoading.collectAsState()
6066
val showTrendingCoinsLoading: LoadingState by viewModel.output.showTrendingCoinsLoading.collectAsState()
6167
val myCoins: List<CoinItemUiModel> by viewModel.output.myCoins.collectAsState()

app/src/test/java/co/nimblehq/compose/crypto/ui/screens/detail/DetailScreenTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class DetailScreenTest : BaseViewModelTest() {
6868
DetailScreen(
6969
viewModel = viewModel,
7070
navigator = { destination -> appDestination = destination },
71-
coinId = "Bitcoin"
71+
coinId = "Bitcoin",
72+
onInternetRestore = {}
7273
)
7374
}
7475
}

app/src/test/java/co/nimblehq/compose/crypto/ui/screens/home/HomeScreenTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class HomeScreenTest : BaseViewModelTest() {
6363
composeAndroidTestRule.activity.setContent {
6464
HomeScreen(
6565
viewModel = viewModel,
66-
navigator = { destination -> appDestination = destination }
66+
navigator = { destination -> appDestination = destination },
67+
onInternetRestore = {}
6768
)
6869
}
6970
}

0 commit comments

Comments
 (0)