1
0

106 lines
3.7 KiB
Kotlin
Raw Normal View History

2025-04-21 17:44:40 +03:00
/*
* Created by sweetbread
* Copyright (c) 2025. All rights reserved.
*/
2025-04-21 15:48:45 +03:00
package ru.risdeveau.geotracker
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Box
2025-04-21 22:32:36 +03:00
import androidx.compose.foundation.layout.Column
2025-04-21 15:48:45 +03:00
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
2025-04-21 17:44:40 +03:00
import androidx.compose.material3.CircularProgressIndicator
2025-04-22 03:11:25 +03:00
import androidx.compose.material3.MaterialTheme
2025-04-21 17:44:40 +03:00
import androidx.compose.material3.OutlinedTextField
2025-04-21 15:48:45 +03:00
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
2025-04-21 17:44:40 +03:00
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
2025-04-21 15:48:45 +03:00
import androidx.compose.ui.Modifier
2025-04-22 03:11:25 +03:00
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.style.TextDecoration
2025-04-21 17:44:40 +03:00
import kotlinx.coroutines.launch
2025-04-21 15:48:45 +03:00
import ru.risdeveau.geotracker.ui.theme.GeoTrackerTheme
2025-04-22 03:11:25 +03:00
import splitties.resources.appColor
import splitties.resources.appStr
2025-04-21 15:48:45 +03:00
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
GeoTrackerTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
2025-04-21 17:44:40 +03:00
Box(
Modifier
.padding(innerPadding)
.fillMaxSize()) {
2025-04-21 22:32:36 +03:00
var screen by remember { mutableStateOf<Screen>(Screen.Loading) }
2025-04-21 15:48:45 +03:00
2025-04-21 22:32:36 +03:00
when (screen) {
Screen.Main -> TODO()
Screen.Settings -> {
Settings(Modifier.align(Alignment.Center))
}
Screen.Loading -> {
var loading by remember { mutableStateOf(true) }
if (loading) {
CircularProgressIndicator(Modifier.align(Alignment.Center))
LaunchedEffect(true) {
launch {
screen = if (health(SettingsPreferences.url))
Screen.Main
else
Screen.Settings
}
2025-04-21 17:44:40 +03:00
}
}
}
}
2025-04-21 15:48:45 +03:00
}
}
}
}
}
}
2025-04-21 17:44:40 +03:00
sealed class Screen {
object Main : Screen()
object Settings : Screen()
2025-04-21 22:32:36 +03:00
object Loading : Screen()
2025-04-21 15:48:45 +03:00
}
@Composable
2025-04-21 17:44:40 +03:00
fun Settings(modifier: Modifier = Modifier) {
var username by remember { mutableStateOf("") }
var url by remember { mutableStateOf("") }
2025-04-21 22:32:36 +03:00
Column (modifier = modifier) {
2025-04-21 17:44:40 +03:00
OutlinedTextField(
value = username,
onValueChange = { username = it },
2025-04-22 03:11:25 +03:00
label = { Text(appStr(R.string.username)) }
2025-04-21 17:44:40 +03:00
)
OutlinedTextField(
value = url,
onValueChange = { url = it },
2025-04-22 03:11:25 +03:00
placeholder = { Text("https://geo.example.com", style = TextStyle(color = MaterialTheme.colorScheme.onSurfaceVariant)) },
label = { Text(appStr(R.string.server_url)) }
2025-04-21 17:44:40 +03:00
)
2025-04-21 15:48:45 +03:00
}
}