current screen as String instead of int
This commit is contained in:
parent
7668743a1f
commit
74b0d534a0
2 changed files with 78 additions and 26 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package de.lelehier.keeper.screens
|
||||
|
||||
import KeeperLargeFontFamily
|
||||
import android.print.PrintAttributes.Margins
|
||||
import android.util.Patterns
|
||||
import androidx.compose.animation.AnimatedContent
|
||||
import androidx.compose.animation.AnimatedContentTransitionScope
|
||||
|
|
@ -15,9 +14,15 @@ import androidx.compose.foundation.layout.Arrangement
|
|||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.imePadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
|
|
@ -41,11 +46,12 @@ import androidx.compose.ui.text.input.KeyboardType
|
|||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
|
||||
@Composable
|
||||
fun HomeScreen(paddingValues: PaddingValues) {
|
||||
var currentScreen by rememberSaveable { mutableIntStateOf(0) }
|
||||
var nextScreen by rememberSaveable { mutableIntStateOf(1) }
|
||||
var currentScreen by rememberSaveable { mutableStateOf("serverDialog") }
|
||||
var serverURL by rememberSaveable { mutableStateOf("") }
|
||||
var username by rememberSaveable { mutableStateOf("") }
|
||||
var password by rememberSaveable { mutableStateOf("") }
|
||||
|
|
@ -55,7 +61,8 @@ fun HomeScreen(paddingValues: PaddingValues) {
|
|||
modifier = Modifier
|
||||
.padding(paddingValues)
|
||||
.fillMaxSize()
|
||||
.imePadding(),
|
||||
.imePadding()
|
||||
.padding(all = 56.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center) {
|
||||
Greeting(serverURL, currentScreen);
|
||||
|
|
@ -68,43 +75,67 @@ fun HomeScreen(paddingValues: PaddingValues) {
|
|||
},
|
||||
|
||||
) { targetState -> when(targetState) {
|
||||
0 -> ServerDialog(serverURL, {newServerURL -> serverURL = newServerURL })
|
||||
1 -> PasswordDialog(username, password, {newUsername -> username = newUsername}, {newPassword -> password = newPassword })
|
||||
"serverDialog" -> ServerDialog(serverURL, {newServerURL -> serverURL = newServerURL })
|
||||
"passwordDialog" -> PasswordDialog(username, password, {newUsername -> username = newUsername}, {newPassword -> password = newPassword })
|
||||
"apiDialog" -> ApiDialog(apiKey) {newApiKey -> apiKey = newApiKey}
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
AnimatedVisibility(currentScreen == 1) {
|
||||
Row (
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
AnimatedVisibility(currentScreen == "passwordDialog") {
|
||||
OutlinedButton (
|
||||
onClick = {currentScreen = nextScreen},
|
||||
onClick = {currentScreen = "serverDialog"},
|
||||
modifier = Modifier.padding(top = 24.dp)
|
||||
) {
|
||||
Row() {
|
||||
Text(text = "Use API Key")
|
||||
Text(text = "Change Server")
|
||||
}
|
||||
}
|
||||
}
|
||||
Button(
|
||||
onClick = {currentScreen = nextScreen},
|
||||
modifier = Modifier.padding(top = 24.dp),
|
||||
enabled = when(currentScreen) {
|
||||
0 -> isValidUrl(serverURL)
|
||||
1 -> username.isNotEmpty() && password.isNotEmpty()
|
||||
else -> false
|
||||
},
|
||||
) {
|
||||
Row() {
|
||||
Text(text = "Next")
|
||||
Spacer(modifier = Modifier.width(12.dp))
|
||||
AnimatedVisibility(currentScreen == "passwordDialog") {
|
||||
OutlinedButton (
|
||||
onClick = {},
|
||||
modifier = Modifier.padding(top = 24.dp)
|
||||
) {
|
||||
Row() {
|
||||
when(currentScreen) {
|
||||
"passwordDialog" -> Text(text = "Use API Key")
|
||||
"apiDialog" -> Text(text = "Use Password")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Button(
|
||||
onClick = {when(currentScreen) {
|
||||
"serverDialog" -> currentScreen = "passwordDialog"
|
||||
"passwordDialog" -> currentScreen = "LoadingDialog"
|
||||
"apiDialog" -> currentScreen = "LoadingDialog"
|
||||
}},
|
||||
modifier = Modifier.padding(top = 24.dp)
|
||||
.fillMaxWidth()
|
||||
.height(128.dp),
|
||||
enabled = when(currentScreen) {
|
||||
"serverDialog" -> isValidUrl(serverURL)
|
||||
"passwordDialog" -> username.isNotEmpty() && password.isNotEmpty()
|
||||
"apiDialog" -> apiKey.isNotEmpty()
|
||||
else -> false
|
||||
},
|
||||
) {
|
||||
Row() {
|
||||
Text(text = "Next")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Greeting(serverURL: String, currentScreen: Int) {
|
||||
fun Greeting(serverURL: String, currentScreen: String) {
|
||||
Column (horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.padding(bottom = 24.dp)) {
|
||||
AnimatedVisibility (currentScreen == 0) {
|
||||
AnimatedVisibility (currentScreen == "serverDialog") {
|
||||
Text(
|
||||
text = "Welcome to",
|
||||
style = MaterialTheme.typography.headlineLarge,
|
||||
|
|
@ -119,7 +150,7 @@ fun Greeting(serverURL: String, currentScreen: Int) {
|
|||
brush = Brush.linearGradient(listOf(MaterialTheme.colorScheme.onPrimaryContainer, MaterialTheme.colorScheme.onSecondaryContainer))),
|
||||
textAlign = TextAlign.Center,
|
||||
)
|
||||
AnimatedVisibility(currentScreen != 0) {
|
||||
AnimatedVisibility(currentScreen != "serverDialog") {
|
||||
Text(
|
||||
text = "@$serverURL",
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
|
|
@ -130,11 +161,11 @@ fun Greeting(serverURL: String, currentScreen: Int) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
fun ServerDialog(serverURL: String, updateServerURL: (newServerURL: String) -> Unit) {
|
||||
var dialogServerURL by remember { mutableStateOf("") }
|
||||
OutlinedTextField(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
label = { Text(text = "Server URL") },
|
||||
textStyle = MaterialTheme.typography.bodySmall,
|
||||
value = serverURL,
|
||||
|
|
@ -170,6 +201,7 @@ fun PasswordDialog(username: String, password: String, updateUsername: (newUsern
|
|||
var dialogPassword by remember { mutableStateOf("") }
|
||||
Column {
|
||||
OutlinedTextField(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
label = { Text(text = "Username") },
|
||||
textStyle = MaterialTheme.typography.bodySmall,
|
||||
value = username,
|
||||
|
|
@ -178,6 +210,7 @@ fun PasswordDialog(username: String, password: String, updateUsername: (newUsern
|
|||
updateUsername(dialogUsername)
|
||||
});
|
||||
OutlinedTextField(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
label = { Text(text = "Password") },
|
||||
textStyle = MaterialTheme.typography.bodySmall,
|
||||
value = password,
|
||||
|
|
@ -187,5 +220,23 @@ fun PasswordDialog(username: String, password: String, updateUsername: (newUsern
|
|||
}
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ApiDialog(apiKey: String, updateApiKey: (newApiKey: String) -> Unit) {
|
||||
var dialogApiKey by remember { mutableStateOf("") }
|
||||
Column {
|
||||
OutlinedTextField(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
label = { Text(text = "Password") },
|
||||
textStyle = MaterialTheme.typography.bodySmall,
|
||||
value = dialogApiKey,
|
||||
onValueChange = { text ->
|
||||
dialogApiKey = text
|
||||
updateApiKey(dialogApiKey)
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue