refactor: streamline notification permission handling; extract logic into startCompletionFlow function and improve validation feedback
This commit is contained in:
+27
-7
@@ -88,8 +88,9 @@ fun ServerSetupScreen(onSetupComplete: () -> Unit) {
|
|||||||
finishOnce()
|
finishOnce()
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(validationResult) {
|
fun startCompletionFlow() {
|
||||||
if (validationResult == true && !completed) {
|
if (completed) return
|
||||||
|
|
||||||
// On Android 13+ prompt for notifications; otherwise default to enabled
|
// On Android 13+ prompt for notifications; otherwise default to enabled
|
||||||
if (Build.VERSION.SDK_INT >= 33) {
|
if (Build.VERSION.SDK_INT >= 33) {
|
||||||
val granted =
|
val granted =
|
||||||
@@ -121,6 +122,11 @@ fun ServerSetupScreen(onSetupComplete: () -> Unit) {
|
|||||||
finishOnce()
|
finishOnce()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(validationResult) {
|
||||||
|
if (validationResult == true && !completed) {
|
||||||
|
startCompletionFlow()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
@@ -148,7 +154,10 @@ fun ServerSetupScreen(onSetupComplete: () -> Unit) {
|
|||||||
|
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = serverUrl,
|
value = serverUrl,
|
||||||
onValueChange = { serverUrl = it },
|
onValueChange = {
|
||||||
|
serverUrl = it
|
||||||
|
viewModel.clearValidationState()
|
||||||
|
},
|
||||||
label = { Text("Server Hostname") },
|
label = { Text("Server Hostname") },
|
||||||
placeholder = { Text("example.com or 10.0.2.2:3000") },
|
placeholder = { Text("example.com or 10.0.2.2:3000") },
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
@@ -161,7 +170,7 @@ fun ServerSetupScreen(onSetupComplete: () -> Unit) {
|
|||||||
text = validationError ?: "",
|
text = validationError ?: "",
|
||||||
color = MaterialTheme.colorScheme.error,
|
color = MaterialTheme.colorScheme.error,
|
||||||
)
|
)
|
||||||
else -> Text("Hostname only. Port optional (80/443 default). No http://, no /api/")
|
else -> Text("Server address (e.g. 192.168.1.5:3000)")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
@@ -189,7 +198,10 @@ fun ServerSetupScreen(onSetupComplete: () -> Unit) {
|
|||||||
|
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = serverPassword,
|
value = serverPassword,
|
||||||
onValueChange = { serverPassword = it },
|
onValueChange = {
|
||||||
|
serverPassword = it
|
||||||
|
viewModel.clearValidationState()
|
||||||
|
},
|
||||||
label = { Text("Server Password") },
|
label = { Text("Server Password") },
|
||||||
placeholder = { Text("Enter server password") },
|
placeholder = { Text("Enter server password") },
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
@@ -208,9 +220,15 @@ fun ServerSetupScreen(onSetupComplete: () -> Unit) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
onClick = { viewModel.validateAndSaveServerUrl(serverUrl.trim(), serverPassword.trim()) },
|
onClick = {
|
||||||
|
if (validationResult == true) {
|
||||||
|
startCompletionFlow()
|
||||||
|
} else {
|
||||||
|
viewModel.validateAndSaveServerUrl(serverUrl.trim(), serverPassword.trim())
|
||||||
|
}
|
||||||
|
},
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
enabled = serverUrl.isNotBlank() && serverPassword.isNotBlank() && !isValidating,
|
enabled = (serverUrl.isNotBlank() && serverPassword.isNotBlank() && !isValidating) || validationResult == true,
|
||||||
) {
|
) {
|
||||||
if (isValidating) {
|
if (isValidating) {
|
||||||
CircularProgressIndicator(
|
CircularProgressIndicator(
|
||||||
@@ -220,6 +238,8 @@ fun ServerSetupScreen(onSetupComplete: () -> Unit) {
|
|||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
Text("Validating...")
|
Text("Validating...")
|
||||||
|
} else if (validationResult == true) {
|
||||||
|
Text("Continue")
|
||||||
} else {
|
} else {
|
||||||
Text("Connect")
|
Text("Connect")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user