Añadir la opcion de registrar el historico de un producto en un supermercado con su precio y manejo de notificaciones de stock bajo

This commit is contained in:
2026-08-10 09:10:46 +02:00
parent 57b545c243
commit 9554190f54
21 changed files with 715 additions and 60 deletions
@@ -0,0 +1,54 @@
package com.example.despensapp.util
import android.content.Context
import androidx.biometric.BiometricManager
import androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG
import androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_WEAK
import androidx.biometric.BiometricPrompt
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentActivity
import com.example.despensapp.R
object BiometricHelper {
fun isBiometricAvailable(context: Context): Boolean {
val biometricManager = BiometricManager.from(context)
return when (biometricManager.canAuthenticate(BIOMETRIC_STRONG or BIOMETRIC_WEAK)) {
BiometricManager.BIOMETRIC_SUCCESS -> true
else -> false
}
}
fun showBiometricPrompt(
activity: FragmentActivity,
onResult: (Boolean, String?) -> Unit
) {
val executor = ContextCompat.getMainExecutor(activity)
val biometricPrompt = BiometricPrompt(activity, executor,
object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
onResult(false, errString.toString())
}
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
super.onAuthenticationSucceeded(result)
onResult(true, null)
}
override fun onAuthenticationFailed() {
super.onAuthenticationFailed()
onResult(false, activity.getString(R.string.biometric_error_failed))
}
})
val promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle(activity.getString(R.string.biometric_title))
.setSubtitle(activity.getString(R.string.biometric_subtitle))
.setNegativeButtonText(activity.getString(R.string.biometric_negative_button))
.setAllowedAuthenticators(BIOMETRIC_STRONG or BIOMETRIC_WEAK)
.build()
biometricPrompt.authenticate(promptInfo)
}
}