feat: add apply button and input handler
This commit is contained in:
parent
86bceffa95
commit
5d81e98b02
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK" />
|
||||
|
@ -30,8 +30,10 @@ data class GeoData(
|
||||
* @return true if baseurl is valid
|
||||
*/
|
||||
suspend fun health(baseurl: String): Boolean {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
@ -2,4 +2,5 @@
|
||||
<resources>
|
||||
<string name="username">Псевдоним</string>
|
||||
<string name="server_url">URL Сервера</string>
|
||||
<string name="apply">Применить</string>
|
||||
</resources>
|
@ -2,4 +2,5 @@
|
||||
<string name="app_name" translatable="false">GeoTracker</string>
|
||||
<string name="username">Username</string>
|
||||
<string name="server_url">Server URL</string>
|
||||
<string name="apply">Apply</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user