mirror of
https://github.com/yogeshpaliyal/KeyPass.git
synced 2026-02-16 01:34:25 -06:00
Add button unlock with biometric on login page (#710)
* Add button unlock with biometric on login page * spotless fixes
This commit is contained in:
committed by
GitHub
parent
fc1ec1a535
commit
fe4baf3554
@@ -20,7 +20,6 @@ import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.yogeshpaliyal.keypass.R
|
||||
import com.yogeshpaliyal.keypass.ui.auth.components.BiometricPrompt
|
||||
import com.yogeshpaliyal.keypass.ui.auth.components.ButtonBar
|
||||
import com.yogeshpaliyal.keypass.ui.auth.components.PasswordInputField
|
||||
import com.yogeshpaliyal.keypass.ui.nav.LocalUserSettings
|
||||
@@ -45,14 +44,6 @@ fun AuthScreen(state: AuthState) {
|
||||
mutableStateOf<Int?>(null)
|
||||
}
|
||||
|
||||
val (biometricEnable, setBiometricEnable) = remember(state) { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(key1 = context, state) {
|
||||
if (state is AuthState.Login) {
|
||||
setBiometricEnable(userSettings.isBiometricEnable)
|
||||
}
|
||||
}
|
||||
|
||||
BackHandler(state is AuthState.ConfirmPassword) {
|
||||
dispatchAction(NavigationAction(AuthState.CreatePassword, true))
|
||||
}
|
||||
@@ -93,6 +84,4 @@ fun AuthScreen(state: AuthState) {
|
||||
dispatchAction(it)
|
||||
}
|
||||
}
|
||||
|
||||
BiometricPrompt(show = biometricEnable)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import com.yogeshpaliyal.keypass.ui.redux.states.HomeState
|
||||
import org.reduxkotlin.compose.rememberTypedDispatcher
|
||||
|
||||
@Composable
|
||||
fun BiometricPrompt(show: Boolean) {
|
||||
fun BiometricPrompt(show: Boolean, onDismiss: () -> Unit) {
|
||||
if (!show) {
|
||||
return
|
||||
}
|
||||
@@ -37,6 +37,7 @@ fun BiometricPrompt(show: Boolean) {
|
||||
errString: CharSequence
|
||||
) {
|
||||
super.onAuthenticationError(errorCode, errString)
|
||||
onDismiss()
|
||||
dispatch(
|
||||
ToastActionStr(
|
||||
context.getString(
|
||||
@@ -56,6 +57,7 @@ fun BiometricPrompt(show: Boolean) {
|
||||
|
||||
override fun onAuthenticationFailed() {
|
||||
super.onAuthenticationFailed()
|
||||
onDismiss()
|
||||
dispatch(ToastAction(R.string.authentication_failed))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,11 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
@@ -29,6 +32,7 @@ fun ButtonBar(
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val context = LocalContext.current
|
||||
val userSettings = LocalUserSettings.current
|
||||
val (biometricEnable, setBiometricEnable) = remember(state) { mutableStateOf(false) }
|
||||
|
||||
Row(modifier = Modifier.fillMaxWidth(1f), Arrangement.SpaceEvenly) {
|
||||
AnimatedVisibility(state is AuthState.ConfirmPassword) {
|
||||
@@ -39,6 +43,18 @@ fun ButtonBar(
|
||||
}
|
||||
}
|
||||
|
||||
if (userSettings.isBiometricEnable && state is AuthState.Login) {
|
||||
OutlinedButton(onClick = {
|
||||
setBiometricEnable(true)
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.unlock_with_biometric))
|
||||
}
|
||||
|
||||
BiometricPrompt(show = biometricEnable) {
|
||||
setBiometricEnable(false)
|
||||
}
|
||||
}
|
||||
|
||||
Button(onClick = {
|
||||
when (state) {
|
||||
is AuthState.CreatePassword -> {
|
||||
|
||||
Reference in New Issue
Block a user