feat: add apply button and input handler
This commit is contained in:
@@ -30,8 +30,10 @@ data class GeoData(
|
||||
* @return true if baseurl is valid
|
||||
*/
|
||||
suspend fun health(baseurl: String): Boolean {
|
||||
val r = client.get("$baseurl/health")
|
||||
return r.status == HttpStatusCode.OK
|
||||
try {
|
||||
val r = client.get("$baseurl/health")
|
||||
return r.status == HttpStatusCode.OK
|
||||
} catch (_: Exception) { return false }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,10 @@ import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
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.material3.Button
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
@@ -29,10 +32,14 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontStyle
|
||||
import androidx.compose.ui.text.style.TextDecoration
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import org.intellij.lang.annotations.JdkConstants
|
||||
import ru.risdeveau.geotracker.ui.theme.GeoTrackerTheme
|
||||
import splitties.resources.appColor
|
||||
import splitties.resources.appStr
|
||||
import kotlin.apply
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -87,9 +94,19 @@ sealed class Screen {
|
||||
fun Settings(modifier: Modifier = Modifier) {
|
||||
var username by remember { mutableStateOf("") }
|
||||
var url by remember { mutableStateOf("") }
|
||||
var urlIsValid by remember { mutableStateOf(false) }
|
||||
var loading by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(url) {
|
||||
if (url.isNotEmpty()) {
|
||||
delay(1000)
|
||||
loading = true
|
||||
urlIsValid = health(url)
|
||||
loading = false
|
||||
}
|
||||
}
|
||||
|
||||
Column (modifier = modifier) {
|
||||
Column (modifier = modifier, horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
OutlinedTextField(
|
||||
value = username,
|
||||
onValueChange = { username = it },
|
||||
@@ -100,7 +117,12 @@ fun Settings(modifier: Modifier = Modifier) {
|
||||
value = url,
|
||||
onValueChange = { url = it },
|
||||
placeholder = { Text("https://geo.example.com", style = TextStyle(color = MaterialTheme.colorScheme.onSurfaceVariant)) },
|
||||
label = { Text(appStr(R.string.server_url)) }
|
||||
label = { Text(appStr(R.string.server_url)) },
|
||||
trailingIcon = { if (loading) CircularProgressIndicator() }
|
||||
)
|
||||
|
||||
Button({}, enabled = urlIsValid) {
|
||||
Text(appStr(R.string.apply))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user