Remove nullability

This commit is contained in:
Benoit Marty
2025-12-11 17:05:42 +01:00
parent cf00b799f2
commit 4f5ce5711d
2 changed files with 6 additions and 8 deletions

View File

@@ -15,7 +15,7 @@ import timber.log.Timber
import zxingcpp.BarcodeReader
internal class QRCodeAnalyzer(
private val onScanQrCode: (result: ByteArray?) -> Unit
private val onScanQrCode: (data: ByteArray) -> Unit
) : ImageAnalysis.Analyzer {
private val reader by lazy { BarcodeReader() }
@@ -23,7 +23,10 @@ internal class QRCodeAnalyzer(
if (image.format in SUPPORTED_IMAGE_FORMATS) {
try {
val bytes = reader.read(image).firstNotNullOfOrNull { it.bytes }
bytes?.let { onScanQrCode(it) }
if (bytes != null) {
Timber.d("QR code scanned!")
onScanQrCode(bytes)
}
} catch (e: Exception) {
Timber.w(e, "Error decoding QR code")
} finally {

View File

@@ -80,12 +80,7 @@ fun QrCodeCameraView(
.build()
imageAnalysis.setAnalyzer(
ContextCompat.getMainExecutor(previewView.context),
QRCodeAnalyzer { result ->
result?.let {
Timber.d("QR code scanned!")
onScanQrCode(it)
}
}
QRCodeAnalyzer(onScanQrCode)
)
try {
// Make sure we unbind all use cases before binding them again