Moved credentials dialog to a different file

This commit is contained in:
Abdelilah El Aissaoui 2021-10-21 23:55:08 +02:00
parent d27161eb98
commit a4f0820857
2 changed files with 89 additions and 40 deletions

View File

@ -0,0 +1,82 @@
package app.git.dialogs
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.OutlinedTextField
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusOrder
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
@Composable
fun UserPasswordDialog(
onReject: () -> Unit,
onAccept: (user: String, password: String) -> Unit
) {
var userField by remember { mutableStateOf("") }
var passwordField by remember { mutableStateOf("") }
val userFieldFocusRequester = remember { FocusRequester() }
val passwordFieldFocusRequester = remember { FocusRequester() }
val buttonFieldFocusRequester = remember { FocusRequester() }
Dialog(
onCloseRequest = onReject,
title = "",
) {
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
Text("Introduce your remote server credentials")
OutlinedTextField(
modifier = Modifier.focusOrder(userFieldFocusRequester) {
this.next = passwordFieldFocusRequester
},
value = userField,
label = { Text("User", fontSize = 14.sp) },
textStyle = TextStyle(fontSize = 14.sp),
onValueChange = {
userField = it
},
)
OutlinedTextField(
modifier = Modifier.padding(bottom = 8.dp)
.focusOrder(passwordFieldFocusRequester) {
this.previous = userFieldFocusRequester
this.next = buttonFieldFocusRequester
},
value = passwordField,
label = { Text("Password", fontSize = 14.sp) },
textStyle = TextStyle(fontSize = 14.sp),
onValueChange = {
passwordField = it
},
visualTransformation = PasswordVisualTransformation()
)
Button(
modifier = Modifier.focusOrder(buttonFieldFocusRequester) {
this.previous = passwordFieldFocusRequester
this.next = userFieldFocusRequester
},
onClick = {
onAccept(userField, passwordField)
}
) {
Text("Ok")
}
}
}
}

View File

@ -14,6 +14,7 @@ import androidx.compose.ui.window.Dialog
import app.credentials.CredentialsState
import app.git.DiffEntryType
import app.git.GitManager
import app.git.dialogs.UserPasswordDialog
import openRepositoryDialog
import org.eclipse.jgit.revwalk.RevCommit
@ -36,50 +37,16 @@ fun RepositoryOpenPage(gitManager: GitManager) {
val credentialsState by gitManager.credentialsState.collectAsState()
if (credentialsState == CredentialsState.CredentialsRequested) {
var userField by remember { mutableStateOf("") }
var passwordField by remember { mutableStateOf("") }
Dialog(
onCloseRequest = {
UserPasswordDialog(
onReject = {
gitManager.credentialsDenied()
},
title = "",
) {
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
Text("Introduce your remote server credentials")
OutlinedTextField(
value = userField,
label = { Text("User", fontSize = 14.sp) },
textStyle = TextStyle(fontSize = 14.sp),
onValueChange = {
userField = it
},
)
OutlinedTextField(
modifier = Modifier.padding(bottom = 8.dp),
value = passwordField,
label = { Text("Password", fontSize = 14.sp) },
textStyle = TextStyle(fontSize = 14.sp),
onValueChange = {
passwordField = it
},
visualTransformation = PasswordVisualTransformation()
)
Button(onClick = { gitManager.credentialsAccepted(userField, passwordField) }) {
Text("Ok")
}
onAccept = { user, password ->
gitManager.credentialsAccepted(user, password)
}
}
)
}
Column {
GMenu(
onRepositoryOpen = {
@ -163,4 +130,4 @@ fun RepositoryOpenPage(gitManager: GitManager) {
}
}
}
}
}