Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
last cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
seldon1000 committed Jul 29, 2021
1 parent 4fcf9a9 commit b7a8bf2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
18 changes: 7 additions & 11 deletions app/src/main/java/eu/seldon1000/nextpass/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
private var unlocked = false
private var pendingUnlockAction: (() -> Unit)? = null
private var promptInfo: BiometricPrompt.PromptInfo
private lateinit var biometricPrompt: BiometricPrompt
private lateinit var autofillIntent: Intent

private val disablePinAction = {
Expand Down Expand Up @@ -242,7 +241,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
if (pinProtected.value) {
unlocked = false
refreshing.value = false
if (biometricProtected.value) biometricDismissed.value = false
biometricDismissed.value = false
dismissDialog()

navigate(route = Routes.AccessPin.getRoute(arg = shouldRaiseBiometric))
Expand Down Expand Up @@ -284,11 +283,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
fun changePin() {
pendingUnlockAction = { navigate(route = Routes.Pin.route) }

if (pinProtected.value) lock()
else {
pendingUnlockAction!!()
pendingUnlockAction = null
}
lock()
}

fun setPin(pin: String) {
Expand Down Expand Up @@ -321,7 +316,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
}

fun showBiometricPrompt(toEnable: Boolean = false) {
biometricPrompt = BiometricPrompt(
BiometricPrompt(
(navController.value.context as MainActivity),
object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
Expand All @@ -331,21 +326,22 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
override fun onAuthenticationSucceeded(
result: BiometricPrompt.AuthenticationResult
) {
biometricDismissed.value = true

if (toEnable) {
sharedPreferences.edit().putBoolean("biometric", true).apply()
biometricProtected.value = true
} else {
unlocked = true
unlock()
unlock(shouldRememberScreen = true)
}
}

override fun onAuthenticationFailed() {
biometricDismissed.value = true
}
}
)
biometricPrompt.authenticate(promptInfo)
).authenticate(promptInfo)
}

fun setLockTimeout(timeout: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

@Composable
fun MySnackbar(snackbarHostState: SnackbarHostState) {
Expand All @@ -37,6 +38,13 @@ fun MySnackbar(snackbarHostState: SnackbarHostState) {
backgroundColor = Color.DarkGray,
shape = RoundedCornerShape(size = 8.dp),
modifier = Modifier.padding(start = 16.dp, end = 16.dp, bottom = 96.dp)
) { Text(text = data.message, fontWeight = FontWeight.SemiBold, color = Color.White) }
) {
Text(
text = data.message,
fontSize = 15.sp,
fontWeight = FontWeight.SemiBold,
color = Color.White
)
}
})
}
15 changes: 1 addition & 14 deletions app/src/main/java/eu/seldon1000/nextpass/ui/screens/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,7 @@ fun Settings(viewModel: MainViewModel) {
modifier = Modifier.padding(end = 16.dp)
)
}
) {
if (protected) viewModel.changePin()
else
viewModel.showDialog(
title = context.getString(R.string.pin_not_enabled),
body = {
Text(
text = context.getString(R.string.pin_not_enabled_body),
fontSize = 14.sp
)
},
confirm = true
) { viewModel.navigate(route = Routes.Pin.route) }
}
) { viewModel.changePin() }
}
item {
GenericColumnItem(
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
<string name="security">Security</string>
<string name="pin_authentication">PIN authentication</string>
<string name="pin_authentication_tip">Protect the app using a PIN code, at least 4-digit long. Click here to modify the current pin.</string>
<string name="pin_not_enabled">PIN authentication is not enabled</string>
<string name="pin_not_enabled_body">Do you want to enable it now?</string>
<string name="biometric_authentication">Biometric authentication</string>
<string name="biometric_authentication_tip">Protect the app using biometric authentication (if supported by the device). PIN authentication must be enabled as fallback.</string>
<string name="url">URL</string>
Expand Down

0 comments on commit b7a8bf2

Please sign in to comment.