Compare commits

...

1 commit

View file

@ -54,16 +54,23 @@ class DownloadWizardMethodSelectFragment : DownloadWizardActivity.DownloadWizard
}
private suspend fun onGalleryResult(result: Uri?) {
var bmp: Bitmap? = null
try {
bmp = requireContext().contentResolver.openInputStream(result ?: return)
fun <T> Bitmap.use(block: Bitmap.() -> T): T = try {
block()
} finally {
recycle()
}
val decoded = try {
requireContext().contentResolver.openInputStream(result ?: return)
.use(BitmapFactory::decodeStream)
val decoded = decodeQrFromBitmap(bmp)
withContext(Dispatchers.Main) { processLpaString(decoded) }
.use(::decodeQrFromBitmap)
} catch (e: Exception) {
Log.e(TAG, "Failed to decode QR code from gallery", e)
} finally {
bmp?.recycle()
return
}
withContext(Dispatchers.Main) {
processLpaString(decoded)
}
}