Compare commits
1 commit
d490d6f239
...
7b5de0ee0f
Author | SHA1 | Date | |
---|---|---|---|
7b5de0ee0f |
1 changed files with 14 additions and 7 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue