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?) {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue