mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
Improve code
This commit is contained in:
+12
-10
@@ -20,17 +20,19 @@ internal class QRCodeAnalyzer(
|
|||||||
private val reader by lazy { BarcodeReader() }
|
private val reader by lazy { BarcodeReader() }
|
||||||
|
|
||||||
override fun analyze(image: ImageProxy) {
|
override fun analyze(image: ImageProxy) {
|
||||||
if (image.format in SUPPORTED_IMAGE_FORMATS) {
|
image.use {
|
||||||
try {
|
if (image.format in SUPPORTED_IMAGE_FORMATS) {
|
||||||
val bytes = reader.read(image).firstNotNullOfOrNull { it.bytes }
|
try {
|
||||||
if (bytes != null) {
|
val bytes = reader.read(image).firstNotNullOfOrNull { it.bytes }
|
||||||
Timber.d("QR code scanned!")
|
if (bytes != null) {
|
||||||
onScanQrCode(bytes)
|
Timber.d("QR code scanned!")
|
||||||
|
onScanQrCode(bytes)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Timber.w(e, "Error decoding QR code")
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} else {
|
||||||
Timber.w(e, "Error decoding QR code")
|
Timber.w("Unsupported image format: ${image.format}")
|
||||||
} finally {
|
|
||||||
image.close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user