Skip to content

Commit

Permalink
🛂 Complete biometrics page
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamparter committed Jul 17, 2024
1 parent fe76096 commit 22c7ccd
Showing 1 changed file with 15 additions and 47 deletions.
62 changes: 15 additions & 47 deletions app/src/main/java/dev/riverside/credit/Biometrics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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) {
Expand All @@ -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)
}
Expand All @@ -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
// }
//}
}

0 comments on commit 22c7ccd

Please sign in to comment.