1
0

feat: add apply button and input handler

This commit is contained in:
Sweetbread 2025-04-22 15:37:56 +03:00
parent 86bceffa95
commit 5d81e98b02
Signed by: Sweetbread
GPG Key ID: 17A5CB9A7DD85319
5 changed files with 30 additions and 5 deletions

1
.idea/misc.xml generated
View File

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK" /> <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK" />

View File

@ -30,8 +30,10 @@ data class GeoData(
* @return true if baseurl is valid * @return true if baseurl is valid
*/ */
suspend fun health(baseurl: String): Boolean { suspend fun health(baseurl: String): Boolean {
try {
val r = client.get("$baseurl/health") val r = client.get("$baseurl/health")
return r.status == HttpStatusCode.OK return r.status == HttpStatusCode.OK
} catch (_: Exception) { return false }
} }
/** /**

View File

@ -12,7 +12,10 @@ import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding 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.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField 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.TextStyle
import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.intellij.lang.annotations.JdkConstants
import ru.risdeveau.geotracker.ui.theme.GeoTrackerTheme import ru.risdeveau.geotracker.ui.theme.GeoTrackerTheme
import splitties.resources.appColor import splitties.resources.appColor
import splitties.resources.appStr import splitties.resources.appStr
import kotlin.apply
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -87,9 +94,19 @@ sealed class Screen {
fun Settings(modifier: Modifier = Modifier) { fun Settings(modifier: Modifier = Modifier) {
var username by remember { mutableStateOf("") } var username by remember { mutableStateOf("") }
var url 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( OutlinedTextField(
value = username, value = username,
onValueChange = { username = it }, onValueChange = { username = it },
@ -100,7 +117,12 @@ fun Settings(modifier: Modifier = Modifier) {
value = url, value = url,
onValueChange = { url = it }, onValueChange = { url = it },
placeholder = { Text("https://geo.example.com", style = TextStyle(color = MaterialTheme.colorScheme.onSurfaceVariant)) }, 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))
}
} }
} }

View File

@ -2,4 +2,5 @@
<resources> <resources>
<string name="username">Псевдоним</string> <string name="username">Псевдоним</string>
<string name="server_url">URL Сервера</string> <string name="server_url">URL Сервера</string>
<string name="apply">Применить</string>
</resources> </resources>

View File

@ -2,4 +2,5 @@
<string name="app_name" translatable="false">GeoTracker</string> <string name="app_name" translatable="false">GeoTracker</string>
<string name="username">Username</string> <string name="username">Username</string>
<string name="server_url">Server URL</string> <string name="server_url">Server URL</string>
<string name="apply">Apply</string>
</resources> </resources>