aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCloudburst <us@conep.one>2023-01-24 10:04:15 +0000
committerCloudburst <us@conep.one>2023-01-24 10:04:15 +0000
commitc6ed7f7437494d9c4c844743c5db604717eda4aa (patch)
tree8155d58e1cb5871ffe9f2372e067c4b25e557e6c
parent99421a085164d8bef3afcf4dd8a504181bc7758d (diff)
downloadpluralwear-c6ed7f7437494d9c4c844743c5db604717eda4aa.tar.gz
pluralwear-c6ed7f7437494d9c4c844743c5db604717eda4aa.tar.bz2
pluralwear-c6ed7f7437494d9c4c844743c5db604717eda4aa.zip
Reduce code duplication
-rw-r--r--wear/src/main/java/dev/equestria/pluralwear/components/Errors.kt155
-rw-r--r--wear/src/main/java/dev/equestria/pluralwear/components/Loading.kt (renamed from wear/src/main/java/dev/equestria/pluralwear/presentation/activity/loading/LoadingActivity.kt)102
-rw-r--r--wear/src/main/java/dev/equestria/pluralwear/components/Success.kt116
-rw-r--r--wear/src/main/java/dev/equestria/pluralwear/presentation/MainActivity.kt2
-rw-r--r--wear/src/main/java/dev/equestria/pluralwear/presentation/activity/register_switch/SwitchActivity.kt195
-rw-r--r--wear/src/main/res/values/strings.xml1
6 files changed, 395 insertions, 176 deletions
diff --git a/wear/src/main/java/dev/equestria/pluralwear/components/Errors.kt b/wear/src/main/java/dev/equestria/pluralwear/components/Errors.kt
new file mode 100644
index 0000000..9d026b0
--- /dev/null
+++ b/wear/src/main/java/dev/equestria/pluralwear/components/Errors.kt
@@ -0,0 +1,155 @@
+package dev.equestria.pluralwear.components
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.wrapContentSize
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.MutableState
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.unit.ExperimentalUnitApi
+import androidx.compose.ui.unit.TextUnit
+import androidx.compose.ui.unit.TextUnitType
+import androidx.compose.ui.unit.dp
+import androidx.wear.compose.material.Button
+import androidx.wear.compose.material.ButtonDefaults
+import androidx.wear.compose.material.Icon
+import androidx.wear.compose.material.MaterialTheme
+import androidx.wear.compose.material.Text
+import androidx.wear.compose.material.dialog.Alert
+import androidx.wear.compose.material.dialog.Dialog
+import androidx.wear.compose.material.rememberScalingLazyListState
+import dev.equestria.pluralwear.R
+
+// Contains composable functions for displaying error screens.
+
+/**
+ * Creates an error dialog, which can be used to display an error message to the user.
+ *
+ * @param drawableId The ID of the drawable to render.
+ * @param drawableDescription The content description of the drawable to render.
+ * @param title The title of the error dialog.
+ * @param description The body of the error dialog.
+ * @param callback A callback to execute when the dialog is dismissed.
+ */
+class ErrorDialog(
+ private val drawableId: Int = R.drawable.baseline_warning_48,
+ private val drawableDescription: String = "warning",
+ private val title: String = "Something went wrong",
+ private val description: String = "An unknown error has occurred, we're sorry for the inconvenience.",
+ private var visibility: MutableState<Boolean>,
+ private val callback: () -> Unit
+) {
+ private var _isVisible by visibility
+
+ /**
+ * Whether the dialog is visible or not.
+ */
+ val isVisible: Boolean = _isVisible
+
+ /**
+ * Show the dialog to the user.
+ */
+ fun show() {
+ _isVisible = true
+ }
+
+ /**
+ * Hide the dialog from the user.
+ */
+ fun hide() {
+ _isVisible = false
+ }
+
+ /**
+ * Build the error dialog so that it appears to the end user when needed.
+ */
+ @Composable
+ fun Build() {
+ val failureDialogScrollState = rememberScalingLazyListState()
+ return Dialog(
+ showDialog = _isVisible,
+ onDismissRequest = {
+ _isVisible = false
+ callback.invoke()
+ },
+ scrollState = failureDialogScrollState
+ ) {
+ Alert(
+ scrollState = failureDialogScrollState,
+ verticalArrangement = Arrangement.spacedBy(4.dp, Alignment.Top),
+ contentPadding =
+ PaddingValues(start = 10.dp, end = 10.dp, top = 24.dp, bottom = 52.dp),
+ icon = {
+ Icon(
+ painter = painterResource(id = drawableId),
+ contentDescription = drawableDescription,
+ modifier = Modifier
+ .size(48.dp)
+ .wrapContentSize(align = Alignment.Center)
+ )
+ },
+ title = { Text(text = title, textAlign = TextAlign.Center) },
+ message = {
+ Text(
+ text = description,
+ textAlign = TextAlign.Center,
+ style = MaterialTheme.typography.body2
+ )
+ },
+ ) {}
+ }
+ }
+}
+
+/**
+ * Renders an error page with Compose.
+ *
+ * @param drawableId The ID of the drawable to render.
+ * @param drawableDescription The content description of the drawable to render.
+ * @param title The title of the error page.
+ * @param description The body of the error page.
+ *
+ * @return A Compose element, which is shown to the user immediately.
+ */
+@Composable
+fun ErrorPage(
+ drawableId: Int = R.drawable.baseline_warning_48,
+ drawableDescription: String = "warning",
+ title: String = "Something went wrong",
+ description: String = "An unknown error has occurred, we're sorry for the inconvenience."
+) {
+ val scrollState = rememberScalingLazyListState()
+ return Alert(
+ scrollState = scrollState,
+ verticalArrangement = Arrangement.spacedBy(4.dp, Alignment.Top),
+ contentPadding =
+ PaddingValues(start = 10.dp, end = 10.dp, top = 24.dp, bottom = 52.dp),
+ icon = {
+ Icon(
+ painter = painterResource(id = drawableId),
+ contentDescription = drawableDescription,
+ modifier = Modifier
+ .size(48.dp)
+ .wrapContentSize(align = Alignment.Center)
+ )
+ },
+ title = { Text(text = title, textAlign = TextAlign.Center) },
+ message = {
+ Text(
+ text = description,
+ textAlign = TextAlign.Center,
+ style = MaterialTheme.typography.body2
+ )
+ },
+ modifier = Modifier.fillMaxSize()
+ ) {}
+} \ No newline at end of file
diff --git a/wear/src/main/java/dev/equestria/pluralwear/presentation/activity/loading/LoadingActivity.kt b/wear/src/main/java/dev/equestria/pluralwear/components/Loading.kt
index 7b5556b..ca0eee2 100644
--- a/wear/src/main/java/dev/equestria/pluralwear/presentation/activity/loading/LoadingActivity.kt
+++ b/wear/src/main/java/dev/equestria/pluralwear/components/Loading.kt
@@ -1,4 +1,4 @@
-package dev.equestria.pluralwear.presentation.activity.loading
+package dev.equestria.pluralwear.components
import android.os.Bundle
import androidx.activity.ComponentActivity
@@ -9,12 +9,12 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
-import androidx.compose.foundation.layout.size
-import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.MutableState
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
-import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Devices
@@ -23,11 +23,7 @@ import androidx.compose.ui.unit.ExperimentalUnitApi
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.TextUnitType
import androidx.compose.ui.unit.dp
-import androidx.navigation.NavHostController
-import androidx.wear.compose.material.Button
-import androidx.wear.compose.material.ButtonDefaults
import androidx.wear.compose.material.CircularProgressIndicator
-import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.MaterialTheme
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.dialog.Alert
@@ -54,7 +50,9 @@ fun LoadingPage(
verticalArrangement = Arrangement.Center
) {
Text(
- modifier = Modifier.fillMaxWidth().padding(5.dp),
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(5.dp),
textAlign = TextAlign.Center,
color = MaterialTheme.colors.onBackground,
text = stringResource(R.string.load_system)
@@ -66,7 +64,9 @@ fun LoadingPage(
trackColor = MaterialTheme.colors.background
)
Text(
- modifier = Modifier.fillMaxWidth().padding(5.dp),
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(5.dp),
textAlign = TextAlign.Center,
color = MaterialTheme.colors.onBackground,
text = stringResource(R.string.please_wait),
@@ -75,34 +75,64 @@ fun LoadingPage(
}
}
-@Composable
-fun LoadingDialog(
- showDialog: Boolean
+/**
+ * Creates a loading dialog, which can be used to show the user that the app is doing something.
+ *
+ * @param text The text to display to the user when loading.
+ */
+class LoadingDialog(
+ private val text: String,
+ private var visibility: MutableState<Boolean>
) {
- val dialogScrollState = rememberScalingLazyListState()
- Dialog(
- showDialog = showDialog,
- onDismissRequest = {},
- scrollState = dialogScrollState
- ) {
- Alert(
- scrollState = dialogScrollState,
- verticalArrangement = Arrangement.spacedBy(4.dp, Alignment.Top),
- contentPadding =
- PaddingValues(start = 10.dp, end = 10.dp, top = 24.dp, bottom = 52.dp),
- icon = {
- CircularProgressIndicator(
- modifier = Modifier.fillMaxWidth(),
- startAngle = 270.0f,
- indicatorColor = MaterialTheme.colors.onBackground,
- trackColor = MaterialTheme.colors.background
- )
- },
- title = { Text(text = "Registering switch", textAlign = TextAlign.Center) },
- message = {
- Text(text = "Please wait...", textAlign = TextAlign.Center, style = MaterialTheme.typography.body2)
- }
+ private var _isVisible by visibility
+ /**
+ * Whether the dialog is visible or not.
+ */
+ val isVisible: Boolean = _isVisible
+
+ /**
+ * Show the dialog to the user.
+ */
+ fun show() {
+ _isVisible = true
+ }
+
+ /**
+ * Hide the dialog from the user.
+ */
+ fun hide() {
+ _isVisible = false
+ }
+
+ /**
+ * Build the loading dialog so that it appears to the end user when needed.
+ */
+ @Composable
+ fun Build() {
+ val scrollState = rememberScalingLazyListState()
+ return Dialog(
+ showDialog = _isVisible,
+ onDismissRequest = {},
+ scrollState = scrollState
) {
+ Alert(
+ scrollState = scrollState,
+ verticalArrangement = Arrangement.spacedBy(4.dp, Alignment.Top),
+ contentPadding =
+ PaddingValues(start = 10.dp, end = 10.dp, top = 24.dp, bottom = 52.dp),
+ icon = {
+ CircularProgressIndicator(
+ modifier = Modifier.fillMaxWidth(),
+ startAngle = 270.0f,
+ indicatorColor = MaterialTheme.colors.onBackground,
+ trackColor = MaterialTheme.colors.background
+ )
+ },
+ title = { Text(text = text, textAlign = TextAlign.Center) },
+ message = {
+ Text(text = stringResource(id = R.string.please_wait), textAlign = TextAlign.Center, style = MaterialTheme.typography.body2)
+ }
+ ) {}
}
}
}
diff --git a/wear/src/main/java/dev/equestria/pluralwear/components/Success.kt b/wear/src/main/java/dev/equestria/pluralwear/components/Success.kt
new file mode 100644
index 0000000..e309c68
--- /dev/null
+++ b/wear/src/main/java/dev/equestria/pluralwear/components/Success.kt
@@ -0,0 +1,116 @@
+package dev.equestria.pluralwear.components
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.wrapContentSize
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.MutableState
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.unit.dp
+import androidx.wear.compose.material.Button
+import androidx.wear.compose.material.ButtonDefaults
+import androidx.wear.compose.material.Icon
+import androidx.wear.compose.material.MaterialTheme
+import androidx.wear.compose.material.Text
+import androidx.wear.compose.material.dialog.Alert
+import androidx.wear.compose.material.dialog.Dialog
+import androidx.wear.compose.material.rememberScalingLazyListState
+import dev.equestria.pluralwear.R
+
+/**
+ * Creates an success dialog, which can be used to show the user that an action completed successfully.
+ *
+ * @param drawableId The ID of the drawable to render.
+ * @param drawableDescription The content description of the drawable to render.
+ * @param title The title of the success dialog.
+ * @param description The body of the success dialog.
+ * @param buttonId The ID of the drawable to render on the "back" button.
+ * @param buttonDescription The content description of the drawable to render on the "back" button/
+ * @param callback A callback to execute when the dialog is dismissed.
+ */
+class SuccessDialog(
+ private val drawableId: Int = R.drawable.baseline_check_48,
+ private val drawableDescription: String = "check",
+ private val title: String? = null,
+ private val description: String? = null,
+ private val buttonId: Int = R.drawable.baseline_home_24,
+ private val buttonDescription: String = "home",
+ private var visibility: MutableState<Boolean>,
+ private val callback: () -> Unit
+) {
+ private var _isVisible by visibility
+
+ /**
+ * Whether the dialog is visible or not.
+ */
+ val isVisible: Boolean = _isVisible
+
+ /**
+ * Show the dialog to the user.
+ */
+ fun show() {
+ _isVisible = true
+ }
+
+ /**
+ * Hide the dialog from the user.
+ */
+ fun hide() {
+ _isVisible = false
+ }
+
+ /**
+ * Build the success dialog so that it appears to the end user when needed.
+ */
+ @Composable
+ fun Build() {
+ val scrollState = rememberScalingLazyListState()
+ return Dialog(
+ showDialog = _isVisible,
+ onDismissRequest = {
+ _isVisible = false
+ callback.invoke()
+ },
+ scrollState = scrollState
+ ) {
+ Alert(
+ scrollState = scrollState,
+ verticalArrangement = Arrangement.spacedBy(4.dp, Alignment.Top),
+ contentPadding =
+ PaddingValues(start = 10.dp, end = 10.dp, top = 24.dp, bottom = 52.dp),
+ icon = {
+ Icon(
+ painter = painterResource(id = drawableId),
+ contentDescription = drawableDescription,
+ modifier = Modifier
+ .size(48.dp)
+ .wrapContentSize(align = Alignment.Center)
+ )
+ },
+ title = { if(title != null) Text(text = title, textAlign = TextAlign.Center) },
+ message = { if(description != null) Text(text = description, textAlign = TextAlign.Center, style = MaterialTheme.typography.body2) }
+ ) {
+ item {
+ Button(
+ onClick = {
+ _isVisible = false
+ callback.invoke()
+ },
+ colors = ButtonDefaults.primaryButtonColors()
+ ) {
+ Icon(
+ painter = painterResource(id = buttonId),
+ contentDescription = buttonDescription
+ )
+ }
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/wear/src/main/java/dev/equestria/pluralwear/presentation/MainActivity.kt b/wear/src/main/java/dev/equestria/pluralwear/presentation/MainActivity.kt
index 26f81a1..c5e7ec4 100644
--- a/wear/src/main/java/dev/equestria/pluralwear/presentation/MainActivity.kt
+++ b/wear/src/main/java/dev/equestria/pluralwear/presentation/MainActivity.kt
@@ -50,6 +50,7 @@ import com.google.android.gms.wearable.DataMapItem
import com.google.android.gms.wearable.Wearable
import dev.equestria.pluralwear.R
import dev.equestria.pluralwear.complication.MainComplicationService
+import dev.equestria.pluralwear.components.LoadingPage
import dev.equestria.pluralwear.pluralkt.PluralKt
import dev.equestria.pluralwear.pluralkt.fulltypes.PkFullSystem
import dev.equestria.pluralwear.pluralkt.types.PkFronter
@@ -58,7 +59,6 @@ import dev.equestria.pluralwear.pluralkt.types.PkMember
import dev.equestria.pluralwear.pluralkt.types.PkSystem
import dev.equestria.pluralwear.pluralkt.types.PkSystemSettings
import dev.equestria.pluralwear.presentation.activity.home.HomePage
-import dev.equestria.pluralwear.presentation.activity.loading.LoadingPage
import dev.equestria.pluralwear.presentation.activity.register_switch.SwitchPage
import dev.equestria.pluralwear.presentation.theme.PluralwearTheme
import dev.equestria.pluralwear.tile.MainTileService
diff --git a/wear/src/main/java/dev/equestria/pluralwear/presentation/activity/register_switch/SwitchActivity.kt b/wear/src/main/java/dev/equestria/pluralwear/presentation/activity/register_switch/SwitchActivity.kt
index 12bfa75..06d2447 100644
--- a/wear/src/main/java/dev/equestria/pluralwear/presentation/activity/register_switch/SwitchActivity.kt
+++ b/wear/src/main/java/dev/equestria/pluralwear/presentation/activity/register_switch/SwitchActivity.kt
@@ -6,40 +6,25 @@ import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
-import androidx.compose.foundation.layout.Arrangement
-import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.foundation.layout.size
-import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.runtime.Composable
-import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
-import androidx.compose.runtime.setValue
-import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
-import androidx.compose.ui.res.painterResource
-import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
-import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
-import androidx.navigation.NavOptions
-import androidx.wear.compose.material.Button
-import androidx.wear.compose.material.ButtonDefaults
-import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.MaterialTheme
-import androidx.wear.compose.material.Text
-import androidx.wear.compose.material.dialog.Alert
-import androidx.wear.compose.material.dialog.Dialog
-import androidx.wear.compose.material.rememberScalingLazyListState
import dev.equestria.pluralwear.R
+import dev.equestria.pluralwear.components.ErrorDialog
+import dev.equestria.pluralwear.components.LoadingDialog
import dev.equestria.pluralwear.pluralkt.PluralKt
import dev.equestria.pluralwear.pluralkt.fulltypes.PkFullSystem
import dev.equestria.pluralwear.pluralkt.types.SwitchCreate
-import dev.equestria.pluralwear.presentation.activity.loading.LoadingDialog
import dev.equestria.pluralwear.components.MultipleMemberList
+import dev.equestria.pluralwear.components.SuccessDialog
import dev.equestria.pluralwear.pluralkt.fulltypes.PkFullFronter
import dev.equestria.pluralwear.presentation.executeSync
import dev.equestria.pluralwear.presentation.theme.PluralwearTheme
@@ -58,141 +43,73 @@ class HomeActivity : ComponentActivity() {
@Composable
fun SwitchPage(system: PkFullSystem?, navController: NavHostController?) {
- var showLoadingDialog by remember { mutableStateOf(false) }
- var showFailureDialog by remember { mutableStateOf(false) }
- var showSuccessDialog by remember { mutableStateOf(false) }
+ var loadingDialog = LoadingDialog(
+ stringResource(id = R.string.register_switch),
+ remember { mutableStateOf(false) }
+ )
+ val failureDialog = ErrorDialog(
+ R.drawable.baseline_warning_48,
+ "warning",
+ "Something went wrong",
+ "An unknown error has occurred, we're sorry for the inconvenience\n\nIf you have telemetry enabled, an error dump has been sent to Equestria.dev.",
+ remember { mutableStateOf(false) }
+ ) {}
+ val successDialog = SuccessDialog(
+ R.drawable.baseline_check_48,
+ "check",
+ "Successfully registered switch",
+ null,
+ R.drawable.baseline_home_24,
+ "home",
+ remember { mutableStateOf(false) }
+ ) {
+ navController?.popBackStack("switch", inclusive = true)
+ }
- val uiState = MemberUiState()
val coroutineScope = rememberCoroutineScope()
if(system?.members != null) {
- for(member in system.members!!) {
- uiState.addMember(member)
- }
- }
-
- PluralwearTheme {
- MultipleMemberList(
- modifier = Modifier
- .fillMaxSize()
- .background(MaterialTheme.colors.background),
- members = uiState.members
- ) {
- coroutineScope.launch {
- showLoadingDialog = true
- val switch = SwitchCreate()
+ PluralwearTheme {
+ MultipleMemberList(
+ modifier = Modifier
+ .fillMaxSize()
+ .background(MaterialTheme.colors.background),
+ members = system.members!!.toList()
+ ) {
+ coroutineScope.launch {
+ loadingDialog.show()
+ val switch = SwitchCreate()
- for (member in it) {
- switch.members.add(member.id)
- }
+ for (member in it) {
+ switch.members.add(member.id)
+ }
- withContext(Dispatchers.IO) {
- try {
- val data = PluralKt.Switch.createSwitch(switch).get()
- showSuccessDialog = true
- if (system != null) {
+ withContext(Dispatchers.IO) {
+ try {
+ val data = PluralKt.Switch.createSwitch(switch).get()
+ successDialog.show()
system.front = PkFullFronter(data)
executeSync(system)
+ } catch (ex: NotFoundException) {
+ Log.e("Pluralwear", "Couldn't find system?")
+ failureDialog.show()
+ } catch (ex: UnknownError) {
+ Log.e("Pluralwear", "PluralKit error: " + ex.message)
+ failureDialog.show()
}
- } catch (ex: NotFoundException) {
- Log.e("Pluralwear", "Couldn't find system?")
- showFailureDialog = true
- } catch (ex: UnknownError) {
- Log.e("Pluralwear", "PluralKit error: " + ex.message)
- showFailureDialog = true
}
+ loadingDialog.hide()
}
- showLoadingDialog = false
}
}
+ } else {
+ // Uhh... idk?
}
- LoadingDialog(showLoadingDialog)
-
- val failureDialogScrollState = rememberScalingLazyListState()
- Dialog(
- showDialog = showFailureDialog,
- onDismissRequest = { showFailureDialog = false },
- scrollState = failureDialogScrollState
- ) {
- Alert(
- scrollState = failureDialogScrollState,
- verticalArrangement = Arrangement.spacedBy(4.dp, Alignment.Top),
- contentPadding =
- PaddingValues(start = 10.dp, end = 10.dp, top = 24.dp, bottom = 52.dp),
- icon = {
- Icon(
- painter = painterResource(id = R.drawable.baseline_warning_48),
- contentDescription = "warning",
- modifier = Modifier
- .size(48.dp)
- .wrapContentSize(align = Alignment.Center)
- )
- },
- title = { Text(text = "Something went wrong", textAlign = TextAlign.Center) },
- message = {
- Text(
- text = "An unknown error has occurred, we're sorry for the inconvenience\n\nIf you have telemetry enabled, an error dump has been sent to Equestria.dev.",
- textAlign = TextAlign.Center,
- style = MaterialTheme.typography.body2
- )
- },
- ) {
- item {
- Button(
- onClick = { showFailureDialog = false },
- colors = ButtonDefaults.primaryButtonColors()
- ) {
- Icon(
- painter = painterResource(id = R.drawable.baseline_arrow_back_24),
- contentDescription = "Close"
- )
- }
- }
- }
- }
-
- val successDialogScrollState = rememberScalingLazyListState()
- Dialog(
- showDialog = showSuccessDialog,
- onDismissRequest = {
- showSuccessDialog = false
- navController?.popBackStack("home", inclusive = true)
- },
- scrollState = successDialogScrollState
- ) {
- Alert(
- scrollState = successDialogScrollState,
- verticalArrangement = Arrangement.spacedBy(4.dp, Alignment.Top),
- contentPadding =
- PaddingValues(start = 10.dp, end = 10.dp, top = 24.dp, bottom = 52.dp),
- icon = {
- Icon(
- painter = painterResource(id = R.drawable.baseline_check_48),
- contentDescription = "check",
- modifier = Modifier
- .size(48.dp)
- .wrapContentSize(align = Alignment.Center)
- )
- },
- title = { Text(text = "Successfully registered switch", textAlign = TextAlign.Center) },
- ) {
- item {
- Button(
- onClick = {
- showSuccessDialog = false
- navController?.popBackStack("switch", inclusive = true)
- },
- colors = ButtonDefaults.primaryButtonColors()
- ) {
- Icon(
- painter = painterResource(id = R.drawable.baseline_home_24),
- contentDescription = "Home"
- )
- }
- }
- }
- }
+ // Build dialogs./
+ loadingDialog.Build()
+ failureDialog.Build()
+ successDialog.Build()
}
@Preview(device = Devices.WEAR_OS_SMALL_ROUND, showSystemUi = true)
diff --git a/wear/src/main/res/values/strings.xml b/wear/src/main/res/values/strings.xml
index 8b439eb..524914a 100644
--- a/wear/src/main/res/values/strings.xml
+++ b/wear/src/main/res/values/strings.xml
@@ -11,6 +11,7 @@
<string name="complication_label">Fronter avatar</string>
<string name="wait_app">Waiting for mobile app…</string>
<string name="load_system">Loading System…</string>
+ <string name="register_switch">Registering switch…</string>
<string name="please_wait">Please wait.</string>
<string name="greeting">Good %1$s</string>
<string name="greeting_morning">morning</string>