Use PasswordDialog custom element for all password queries
This commit is contained in:
@@ -1164,11 +1164,13 @@ class AccountActivity : ComponentActivity() {
|
|||||||
keyboardController = keyboardController,
|
keyboardController = keyboardController,
|
||||||
title = getString(R.string.authentication_password),
|
title = getString(R.string.authentication_password),
|
||||||
okAction = {
|
okAction = {
|
||||||
BaresipService.aorPasswords[acc.aor] = password.value
|
if (password.value != "") {
|
||||||
Api.account_set_auth_pass(acc.accp, password.value)
|
BaresipService.aorPasswords[acc.aor] = password.value
|
||||||
password.value = ""
|
Api.account_set_auth_pass(acc.accp, password.value)
|
||||||
reRegister = true
|
password.value = ""
|
||||||
finishActivity()
|
reRegister = true
|
||||||
|
finishActivity()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
cancelAction = {
|
cancelAction = {
|
||||||
reRegister = true
|
reRegister = true
|
||||||
|
|||||||
@@ -268,6 +268,7 @@ object CustomElements {
|
|||||||
password: MutableState<String>,
|
password: MutableState<String>,
|
||||||
keyboardController:SoftwareKeyboardController?,
|
keyboardController:SoftwareKeyboardController?,
|
||||||
title: String,
|
title: String,
|
||||||
|
message: String = "",
|
||||||
okAction: () -> Unit,
|
okAction: () -> Unit,
|
||||||
cancelAction: () -> Unit
|
cancelAction: () -> Unit
|
||||||
) {
|
) {
|
||||||
@@ -295,6 +296,13 @@ object CustomElements {
|
|||||||
modifier = Modifier.padding(top = 16.dp, bottom = 16.dp),
|
modifier = Modifier.padding(top = 16.dp, bottom = 16.dp),
|
||||||
color = LocalCustomColors.current.alert,
|
color = LocalCustomColors.current.alert,
|
||||||
)
|
)
|
||||||
|
if (message != "")
|
||||||
|
Text(
|
||||||
|
text = message,
|
||||||
|
fontSize = 16.sp,
|
||||||
|
modifier = Modifier.padding(16.dp),
|
||||||
|
color = LocalCustomColors.current.itemText,
|
||||||
|
)
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = password.value,
|
value = password.value,
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
@@ -368,8 +376,7 @@ object CustomElements {
|
|||||||
).show()
|
).show()
|
||||||
password.value = ""
|
password.value = ""
|
||||||
}
|
}
|
||||||
if (password.value != "")
|
okAction()
|
||||||
okAction()
|
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
|
|||||||
@@ -91,7 +91,6 @@ import androidx.compose.material3.IconButton
|
|||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.OutlinedButton
|
import androidx.compose.material3.OutlinedButton
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.OutlinedTextFieldDefaults
|
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
@@ -124,13 +123,10 @@ import androidx.compose.ui.res.vectorResource
|
|||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
|
||||||
import androidx.compose.ui.text.input.VisualTransformation
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.compose.ui.viewinterop.AndroidView
|
import androidx.compose.ui.viewinterop.AndroidView
|
||||||
import androidx.compose.ui.window.DialogProperties
|
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
@@ -1815,131 +1811,22 @@ class MainActivity : ComponentActivity() {
|
|||||||
val params = account.substringAfter(">")
|
val params = account.substringAfter(">")
|
||||||
if (Utils.paramValue(params, "auth_user") != "" && Utils.paramValue(params, "auth_pass") == "") {
|
if (Utils.paramValue(params, "auth_user") != "" && Utils.paramValue(params, "auth_pass") == "") {
|
||||||
val aor = account.substringAfter("<").substringBefore(">")
|
val aor = account.substringAfter("<").substringBefore(">")
|
||||||
val showPassword = remember { mutableStateOf(false) }
|
CustomElements.PasswordDialog(
|
||||||
val focusRequester = remember { FocusRequester() }
|
ctx = ctx,
|
||||||
BasicAlertDialog(
|
showPasswordDialog = showPasswordsDialog,
|
||||||
properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false),
|
password = password,
|
||||||
onDismissRequest = {
|
keyboardController = keyboardController,
|
||||||
keyboardController?.hide()
|
title = getString(R.string.authentication_password),
|
||||||
showPasswordsDialog.value = false
|
message = getString(R.string.account) + " " + Utils.plainAor(aor),
|
||||||
|
okAction = {
|
||||||
|
if (password.value != "")
|
||||||
|
BaresipService.aorPasswords[aor] = password.value
|
||||||
|
showPasswordsDialog.value = true
|
||||||
|
},
|
||||||
|
cancelAction = {
|
||||||
|
showPasswordsDialog.value = true
|
||||||
}
|
}
|
||||||
) {
|
)
|
||||||
Surface(
|
|
||||||
modifier = Modifier
|
|
||||||
.wrapContentWidth()
|
|
||||||
.wrapContentHeight(),
|
|
||||||
color = LocalCustomColors.current.background,
|
|
||||||
shape = MaterialTheme.shapes.large,
|
|
||||||
tonalElevation = AlertDialogDefaults.TonalElevation
|
|
||||||
) {
|
|
||||||
Column(modifier = Modifier.padding(16.dp)) {
|
|
||||||
Text(
|
|
||||||
text = getString(R.string.authentication_password),
|
|
||||||
fontSize = 20.sp,
|
|
||||||
modifier = Modifier.padding(top = 16.dp, bottom = 16.dp),
|
|
||||||
color = LocalCustomColors.current.alert,
|
|
||||||
)
|
|
||||||
val message =
|
|
||||||
getString(R.string.account) + " " + Utils.plainAor(aor)
|
|
||||||
Text(
|
|
||||||
text = message,
|
|
||||||
fontSize = 16.sp,
|
|
||||||
modifier = Modifier.padding(16.dp),
|
|
||||||
color = LocalCustomColors.current.itemText,
|
|
||||||
)
|
|
||||||
var password by remember { mutableStateOf("") }
|
|
||||||
OutlinedTextField(
|
|
||||||
value = password,
|
|
||||||
singleLine = true,
|
|
||||||
colors = OutlinedTextFieldDefaults.colors(
|
|
||||||
focusedContainerColor = LocalCustomColors.current.textFieldBackground,
|
|
||||||
unfocusedContainerColor = LocalCustomColors.current.textFieldBackground,
|
|
||||||
cursorColor = LocalCustomColors.current.primary,
|
|
||||||
),
|
|
||||||
onValueChange = {
|
|
||||||
password = it
|
|
||||||
},
|
|
||||||
visualTransformation = if (showPassword.value)
|
|
||||||
VisualTransformation.None
|
|
||||||
else
|
|
||||||
PasswordVisualTransformation(),
|
|
||||||
trailingIcon = {
|
|
||||||
IconButton(onClick = {
|
|
||||||
showPassword.value = !showPassword.value
|
|
||||||
}) {
|
|
||||||
Icon(
|
|
||||||
if (showPassword.value)
|
|
||||||
ImageVector.vectorResource(R.drawable.visibility)
|
|
||||||
else
|
|
||||||
ImageVector.vectorResource(R.drawable.visibility_off),
|
|
||||||
contentDescription = "Visibility",
|
|
||||||
tint = LocalCustomColors.current.grayDark
|
|
||||||
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(start = 4.dp, end = 4.dp, top = 12.dp, bottom = 2.dp)
|
|
||||||
.focusRequester(focusRequester),
|
|
||||||
textStyle = TextStyle(
|
|
||||||
fontSize = 18.sp,
|
|
||||||
color = LocalCustomColors.current.dark
|
|
||||||
),
|
|
||||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text)
|
|
||||||
)
|
|
||||||
LaunchedEffect(key1 = Unit) {
|
|
||||||
focusRequester.requestFocus()
|
|
||||||
keyboardController?.show()
|
|
||||||
}
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.Start
|
|
||||||
) {
|
|
||||||
TextButton(
|
|
||||||
onClick = {
|
|
||||||
keyboardController?.hide()
|
|
||||||
showPasswordsDialog.value = false
|
|
||||||
showPasswordsDialog.value = true
|
|
||||||
},
|
|
||||||
modifier = Modifier.padding(8.dp),
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.cancel),
|
|
||||||
color = LocalCustomColors.current.gray
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
|
||||||
TextButton(
|
|
||||||
onClick = {
|
|
||||||
keyboardController?.hide()
|
|
||||||
showPasswordsDialog.value = false
|
|
||||||
password = password.trim()
|
|
||||||
if (!Account.checkAuthPass(password)) {
|
|
||||||
Toast.makeText(
|
|
||||||
ctx,
|
|
||||||
String.format(
|
|
||||||
getString(R.string.invalid_authentication_password),
|
|
||||||
password
|
|
||||||
),
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
password = ""
|
|
||||||
passwordAccounts.add(0, account)
|
|
||||||
} else
|
|
||||||
BaresipService.aorPasswords[aor] = password
|
|
||||||
showPasswordsDialog.value = true
|
|
||||||
},
|
|
||||||
modifier = Modifier.padding(8.dp),
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.ok),
|
|
||||||
color = LocalCustomColors.current.alert
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
showPasswordsDialog.value = false
|
showPasswordsDialog.value = false
|
||||||
@@ -1961,11 +1848,13 @@ class MainActivity : ComponentActivity() {
|
|||||||
keyboardController = keyboardController,
|
keyboardController = keyboardController,
|
||||||
title = passwordTitle,
|
title = passwordTitle,
|
||||||
okAction = {
|
okAction = {
|
||||||
if (passwordTitle == getString(R.string.encrypt_password))
|
if (password.value != "") {
|
||||||
backup(password.value)
|
if (passwordTitle == getString(R.string.encrypt_password))
|
||||||
else
|
backup(password.value)
|
||||||
restore(password.value)
|
else
|
||||||
password.value = ""
|
restore(password.value)
|
||||||
|
password.value = ""
|
||||||
|
}
|
||||||
},
|
},
|
||||||
cancelAction = {
|
cancelAction = {
|
||||||
if (downloadsOutputUri != null) {
|
if (downloadsOutputUri != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user