-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the ability to require biometric authentication to view a custom list. This feature includes UI updates to add and remove authentication for a list, as well as a prompt for authentication when accessing a secured list.
- Loading branch information
jacobrein
committed
Oct 3, 2024
1 parent
5daeee2
commit 7055786
Showing
8 changed files
with
237 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
UIViews/src/main/java/com/programmersbox/uiviews/utils/BiometricUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.programmersbox.uiviews.utils | ||
|
||
import android.content.Context | ||
import androidx.biometric.BiometricPrompt | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberUpdatedState | ||
|
||
fun biometricPrompting( | ||
context: Context, | ||
authenticationCallback: BiometricPrompt.AuthenticationCallback, | ||
) = BiometricPrompt( | ||
context.findActivity(), | ||
context.mainExecutor, | ||
authenticationCallback | ||
) | ||
|
||
@Composable | ||
fun rememberBiometricPrompt( | ||
onAuthenticationSucceeded: () -> Unit, | ||
onAuthenticationFailed: () -> Unit = {}, | ||
): BiometricPrompt.AuthenticationCallback { | ||
val succeed by rememberUpdatedState(onAuthenticationSucceeded) | ||
val failed by rememberUpdatedState(onAuthenticationFailed) | ||
return remember(succeed, failed) { | ||
object : BiometricPrompt.AuthenticationCallback() { | ||
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) { | ||
super.onAuthenticationError(errorCode, errString) | ||
failed() | ||
} | ||
|
||
override fun onAuthenticationSucceeded( | ||
result: BiometricPrompt.AuthenticationResult, | ||
) { | ||
super.onAuthenticationSucceeded(result) | ||
println("Authentication succeeded $result") | ||
succeed() | ||
} | ||
|
||
override fun onAuthenticationFailed() { | ||
super.onAuthenticationFailed() | ||
println("Authentication failed") | ||
failed() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.