Skip to content

Commit e0e0e42

Browse files
committed
[#100] Ui implementation for no connection dialog
1 parent 8a173a8 commit e0e0e42

File tree

4 files changed

+95
-5
lines changed

4 files changed

+95
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package co.nimblehq.compose.crypto.ui.common
2+
3+
import androidx.annotation.StringRes
4+
import androidx.compose.foundation.background
5+
import androidx.compose.foundation.layout.*
6+
import androidx.compose.material.*
7+
import androidx.compose.runtime.Composable
8+
import androidx.compose.ui.Modifier
9+
import androidx.compose.ui.graphics.Color
10+
import androidx.compose.ui.res.stringResource
11+
import androidx.compose.ui.tooling.preview.Preview
12+
import androidx.compose.ui.window.Dialog
13+
import co.nimblehq.compose.crypto.R
14+
import co.nimblehq.compose.crypto.ui.theme.*
15+
16+
@Composable
17+
fun AppDialogPopUp(
18+
onDismiss: () -> Unit,
19+
onClick: () -> Unit,
20+
@StringRes title: Int,
21+
@StringRes message: Int,
22+
@StringRes actionText: Int,
23+
) {
24+
Dialog(
25+
onDismissRequest = onDismiss
26+
) {
27+
Column(
28+
modifier = Modifier
29+
.background(Color.White)
30+
.width(DialogWidth)
31+
) {
32+
Text(
33+
text = stringResource(id = title),
34+
style = AppTheme.typography.h6,
35+
color = Color.Black,
36+
modifier = Modifier.padding(top = Dp16, start = Dp16, end = Dp16)
37+
)
38+
Text(
39+
text = stringResource(id = message),
40+
style = AppTheme.typography.body1,
41+
color = Color.Black,
42+
modifier = Modifier.padding(Dp16)
43+
)
44+
Row(
45+
horizontalArrangement = Arrangement.End,
46+
modifier = Modifier
47+
.fillMaxWidth()
48+
.padding(bottom = Dp16, end = Dp8)
49+
) {
50+
TextButton(
51+
onClick = onClick
52+
) {
53+
Text(
54+
text = stringResource(id = actionText),
55+
style = AppTheme.styles.semiBold16,
56+
color = Color.Blue,
57+
)
58+
}
59+
}
60+
}
61+
}
62+
}
63+
64+
@Composable
65+
@Preview(showSystemUi = true)
66+
fun AppDialogPopUpPreview() {
67+
ComposeTheme {
68+
Box {
69+
AppDialogPopUp(
70+
onDismiss = { /*TODO*/ },
71+
onClick = { /*TODO*/ },
72+
message = R.string.no_internet_message,
73+
actionText = android.R.string.ok,
74+
title = R.string.no_internet_title
75+
)
76+
}
77+
}
78+
}

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

+12-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import co.nimblehq.compose.crypto.R
2323
import co.nimblehq.compose.crypto.extension.boxShadow
2424
import co.nimblehq.compose.crypto.lib.IsLoading
2525
import co.nimblehq.compose.crypto.ui.base.LoadingState
26+
import co.nimblehq.compose.crypto.ui.common.AppDialogPopUp
2627
import co.nimblehq.compose.crypto.ui.navigation.AppDestination
2728
import co.nimblehq.compose.crypto.ui.preview.HomeScreenParams
2829
import co.nimblehq.compose.crypto.ui.preview.HomeScreenPreviewParameterProvider
@@ -58,11 +59,6 @@ fun HomeScreen(
5859

5960
// TODO remove in integration ticket
6061
val hasConnection by viewModel.hasConnection.collectAsState()
61-
LaunchedEffect(key1 = hasConnection) {
62-
if (hasConnection != null) {
63-
Toast.makeText(context,"Connection: $hasConnection", Toast.LENGTH_SHORT).show()
64-
}
65-
}
6662

6763
val showMyCoinsLoading: IsLoading by viewModel.output.showMyCoinsLoading.collectAsState()
6864
val showTrendingCoinsLoading: LoadingState by viewModel.output.showTrendingCoinsLoading.collectAsState()
@@ -94,6 +90,17 @@ fun HomeScreen(
9490
onRefresh = { viewModel.input.loadData(isRefreshing = true) },
9591
onTrendingCoinsLoadMore = { viewModel.input.getTrendingCoins(loadMore = true) }
9692
)
93+
94+
// TODO remove in integration ticket
95+
if (hasConnection == false) {
96+
AppDialogPopUp(
97+
onDismiss = { /*TODO*/ },
98+
onClick = { /*TODO*/ },
99+
message = R.string.no_internet_message,
100+
actionText = android.R.string.ok,
101+
title = R.string.no_internet_title
102+
)
103+
}
97104
}
98105

99106
@OptIn(ExperimentalMaterialApi::class)

app/src/main/java/co/nimblehq/compose/crypto/ui/theme/Dimension.kt

+2
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ val Sp12 = 12.sp
2424
val Sp14 = 14.sp
2525
val Sp16 = 16.sp
2626
val Sp24 = 24.sp
27+
28+
val DialogWidth = 300.dp

app/src/main/res/values/strings.xml

+3
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@
2020

2121
<string name="coin_info_sell_button">Sell</string>
2222
<string name="coin_info_buy_button">Buy</string>
23+
24+
<string name="no_internet_title">Oops!</string>
25+
<string name="no_internet_message">No internet connection was found. Please check your internet connection and try again.</string>
2326
</resources>

0 commit comments

Comments
 (0)