From 22c7ccd0211a7b007576f7096a876e445768b71a Mon Sep 17 00:00:00 2001 From: Lamparter Date: Wed, 17 Jul 2024 19:22:54 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=82=20Complete=20biometrics=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/riverside/credit/Biometrics.kt | 62 +++++-------------- 1 file changed, 15 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/dev/riverside/credit/Biometrics.kt b/app/src/main/java/dev/riverside/credit/Biometrics.kt index ba78746..11b1c9b 100644 --- a/app/src/main/java/dev/riverside/credit/Biometrics.kt +++ b/app/src/main/java/dev/riverside/credit/Biometrics.kt @@ -15,12 +15,17 @@ import androidx.navigation.fragment.findNavController import dev.riverside.credit.databinding.AuthBiometricBinding import java.util.concurrent.Executor import kotlin.system.exitProcess +import android.content.DialogInterface +import androidx.appcompat.app.AlertDialog +import android.app.Activity class Biometrics : Fragment() { private var _binding: AuthBiometricBinding? = null private val binding get() = _binding!! + private var biometricPrompt: BiometricPrompt? = null + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -35,11 +40,18 @@ class Biometrics : Fragment() { // Get an instance of the main executor val executor: Executor = ContextCompat.getMainExecutor(requireContext()) + val promptInfo = BiometricPrompt.PromptInfo.Builder() + .setTitle("Verify that it's you") + .setSubtitle("For your security, you need to verify that it's you before using Smart Tap") + .setNegativeButtonText(" ") + .setConfirmationRequired(true) + .build() + // Create the callback val callback = object : BiometricPrompt.AuthenticationCallback() { override fun onAuthenticationError(errorCode: Int, errString: CharSequence) { super.onAuthenticationError(errorCode, errString) - // TODO: Handle error + (activity as Activity).finish() } override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) { @@ -50,21 +62,12 @@ class Biometrics : Fragment() { override fun onAuthenticationFailed() { super.onAuthenticationFailed() - // TODO: Handle failure - exitProcess(77) + } } - // Initialize BiometricPrompt instance val biometricPrompt = BiometricPrompt(this, executor, callback) - val promptInfo = BiometricPrompt.PromptInfo.Builder() - .setTitle("Verify that it's you") - .setDescription("For your security, you need to verify that it's you before using Smart Tap") - .setNegativeButtonText(" ") - .setConfirmationRequired(true) - .build() - // Start authentication biometricPrompt.authenticate(promptInfo) } @@ -73,39 +76,4 @@ class Biometrics : Fragment() { super.onDestroyView() _binding = null } -} - -///** -// * A simple [Fragment] subclass as the default destination in the navigation. -// */ -//class Biometrics : Fragment() { -// -// private var _binding: AuthBiometricBinding? = null -// -// // This property is only valid between onCreateView and -// // onDestroyView. -// private val binding get() = _binding!! -// -// override fun onCreateView( -// inflater: LayoutInflater, container: ViewGroup?, -// savedInstanceState: Bundle? -// ): View { -// -// _binding = AuthBiometricBinding.inflate(inflater, container, false) -// return binding.root -// -// } -// -// override fun onViewCreated(view: View, savedInstanceState: Bundle?) { -// super.onViewCreated(view, savedInstanceState) -// -//// binding.buttonFirst.setOnClickListener { -//// findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment) -//// } -// } -// -// override fun onDestroyView() { -// super.onDestroyView() -// _binding = null -// } -//} \ No newline at end of file +} \ No newline at end of file