Skip to content

Commit acbab2f

Browse files
authored
feat: improve no connection screen (#470)
* feat: Improve no connection error screen
1 parent 362cd45 commit acbab2f

File tree

3 files changed

+39
-8
lines changed
  • mockzilla-management-ui

3 files changed

+39
-8
lines changed

mockzilla-management-ui/mockzilla-management-ui-common/src/commonMain/kotlin/com/apadmi/mockzilla/ui/i18n/En.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ val EnStrings = Strings(
1919
ipInputLabel = "e.g 127.0.0.1:8080",
2020
androidDevConnectButton = "Connect to development Mockzilla",
2121
errorTitle = "Failed to connect",
22+
errorMessage = "Please check the following:" +
23+
"\n1. You have called startMockzilla() during your application's launch." +
24+
"\n2. The Mockzilla library you are using is above the minimum versions (KMP: 2.4.1, Flutter: 1.3.0).",
2225
connected = "Connected",
2326
tooltips = Strings.Widgets.DeviceConnection.ToolTips(
2427
notYourSimulator = "We don't think this is your simulator, but you can try to connect! (Probably won't work)",

mockzilla-management-ui/mockzilla-management-ui-common/src/commonMain/kotlin/com/apadmi/mockzilla/ui/i18n/Strings.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ data class Strings(
152152
* @property autoConnectButton
153153
* @property androidDevConnectButton
154154
* @property errorTitle
155+
* @property errorMessage
155156
* @property connected
156157
*/
157158
data class DeviceConnection(
@@ -164,6 +165,7 @@ data class Strings(
164165
val autoConnectButton: String,
165166
val androidDevConnectButton: String,
166167
val errorTitle: String,
168+
val errorMessage: String,
167169
val connected: String
168170
) {
169171
/**

mockzilla-management-ui/mockzilla-mobile-ui/src/commonMain/kotlin/com/apadmi/mockzilla/mobile/ui/deviceconnection/MobileDeviceConnectionWidget.kt

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.apadmi.mockzilla.mobile.ui.deviceconnection
22

3+
import androidx.compose.foundation.background
34
import androidx.compose.foundation.layout.Arrangement
45
import androidx.compose.foundation.layout.Column
5-
import androidx.compose.foundation.layout.PaddingValues
66
import androidx.compose.foundation.layout.fillMaxSize
77
import androidx.compose.foundation.layout.padding
88
import androidx.compose.foundation.layout.size
@@ -13,7 +13,9 @@ import androidx.compose.material3.Text
1313
import androidx.compose.runtime.Composable
1414
import androidx.compose.runtime.collectAsState
1515
import androidx.compose.runtime.getValue
16+
import androidx.compose.ui.Alignment
1617
import androidx.compose.ui.Modifier
18+
import androidx.compose.ui.text.style.TextAlign
1719
import androidx.compose.ui.unit.dp
1820
import com.apadmi.mockzilla.mobile.ui.deviceconnection.MobileDeviceConnectionViewModel.*
1921
import com.apadmi.mockzilla.ui.di.utils.getViewModel
@@ -27,19 +29,43 @@ internal fun MobileDeviceConnectionWidget(
2729
val viewModel = getViewModel<MobileDeviceConnectionViewModel>()
2830
val state by viewModel.state.collectAsState()
2931

30-
return Column(Modifier.fillMaxSize(), verticalArrangement = Arrangement.Center) {
32+
return Column(
33+
modifier = Modifier
34+
.fillMaxSize()
35+
.background(color = MaterialTheme.colorScheme.background),
36+
verticalArrangement = Arrangement.spacedBy(20.dp, Alignment.CenterVertically),
37+
horizontalAlignment = Alignment.CenterHorizontally
38+
) {
3139
when (val currentState = state) {
32-
State.Connecting -> CircularProgressIndicator(Modifier.padding(end = 8.dp).size(20.dp))
40+
State.Connecting -> CircularProgressIndicator(
41+
modifier = Modifier.padding(end = 8.dp).size(20.dp)
42+
)
43+
3344
is State.Error -> {
34-
Text(strings.widgets.deviceConnection.errorTitle)
35-
Button(onClick = viewModel::attemptLocalConnection, contentPadding = PaddingValues(0.dp)) {
45+
Text(
46+
text = strings.widgets.deviceConnection.errorTitle,
47+
color = MaterialTheme.colorScheme.onBackground,
48+
style = MaterialTheme.typography.bodyLarge
49+
)
50+
51+
Button(
52+
onClick = viewModel::attemptLocalConnection
53+
) {
3654
Text(
37-
strings.widgets.errorBanner.refreshButton,
38-
style = MaterialTheme.typography.bodySmall
55+
text = strings.widgets.errorBanner.refreshButton,
56+
color = MaterialTheme.colorScheme.onPrimary,
57+
style = MaterialTheme.typography.bodyLarge
3958
)
4059
}
41-
Text(currentState.message)
60+
61+
Text(
62+
text = strings.widgets.deviceConnection.errorMessage,
63+
color = MaterialTheme.colorScheme.onBackground,
64+
style = MaterialTheme.typography.bodyLarge,
65+
textAlign = TextAlign.Center
66+
)
4267
}
68+
4369
State.Connected -> Text(strings.widgets.deviceConnection.connected)
4470
}
4571
}

0 commit comments

Comments
 (0)