From e98f8a42b9550b7fbd7a59271756c3d2af3113bb Mon Sep 17 00:00:00 2001 From: Aistra <55940744+aistra0528@users.noreply.github.com> Date: Tue, 18 Jul 2023 10:09:20 +0800 Subject: [PATCH] fix: biometric login close #114 --- .../com/aistra/hail/ui/main/MainActivity.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/aistra/hail/ui/main/MainActivity.kt b/app/src/main/kotlin/com/aistra/hail/ui/main/MainActivity.kt index 6dcdb2cb..cc8eab0d 100644 --- a/app/src/main/kotlin/com/aistra/hail/ui/main/MainActivity.kt +++ b/app/src/main/kotlin/com/aistra/hail/ui/main/MainActivity.kt @@ -41,19 +41,24 @@ class MainActivity : AppCompatActivity(), NavController.OnDestinationChangedList val biometricPrompt = BiometricPrompt(this, ContextCompat.getMainExecutor(this), object : BiometricPrompt.AuthenticationCallback() { + private fun unlock() { + binding.root.isVisible = true + binding.appBarMain.toolbar.setBackgroundColor( + MaterialColors.getColor(binding.root, R.attr.colorPrimaryDark) + ) + showGuide() + } + override fun onAuthenticationError(errorCode: Int, errString: CharSequence) { super.onAuthenticationError(errorCode, errString) HUI.showToast(errString) - finishAndRemoveTask() + if (errorCode == BiometricPrompt.ERROR_NO_BIOMETRICS) unlock() + else finishAndRemoveTask() } override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) { super.onAuthenticationSucceeded(result) - binding.root.isVisible = true - binding.appBarMain.toolbar.setBackgroundColor( - MaterialColors.getColor(binding.root, R.attr.colorPrimaryDark) - ) - showGuide() + unlock() } }) val promptInfo =