From 74b0d534a06351e4d0accdf6a9b11165577bfacb Mon Sep 17 00:00:00 2001 From: Leandro Schaguhn Date: Fri, 13 Jun 2025 10:58:19 +0200 Subject: [PATCH] current screen as String instead of int --- app/build.gradle.kts | 3 +- .../de/lelehier/keeper/screens/home_screen.kt | 101 +++++++++++++----- 2 files changed, 78 insertions(+), 26 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 29bc935..e900371 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -48,7 +48,8 @@ dependencies { implementation(libs.androidx.ui) implementation(libs.androidx.ui.graphics) implementation(libs.androidx.ui.tooling.preview) - implementation(libs.androidx.material3) + //implementation(libs.androidx.material3) + implementation("androidx.compose.material3:material3:1.4.0-alpha15") testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) diff --git a/app/src/main/java/de/lelehier/keeper/screens/home_screen.kt b/app/src/main/java/de/lelehier/keeper/screens/home_screen.kt index 97a6e43..4fe60a9 100644 --- a/app/src/main/java/de/lelehier/keeper/screens/home_screen.kt +++ b/app/src/main/java/de/lelehier/keeper/screens/home_screen.kt @@ -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) + } + ) + } } \ No newline at end of file