Compare commits

...

1 commit

View file

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