From 388037f6b57dc880cece63ff15dea44ab6de6e04 Mon Sep 17 00:00:00 2001 From: Naveen Date: Wed, 24 May 2023 03:48:16 +0530 Subject: [PATCH] Always do resize operation on background thread --- .../gallery/pro/extensions/Activity.kt | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt index 1fdecf9e6..0d57b52e1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt @@ -823,33 +823,35 @@ fun BaseSimpleActivity.launchResizeImageDialog(path: String, callback: (() -> Un } fun BaseSimpleActivity.resizeImage(path: String, size: Point, callback: (success: Boolean) -> Unit) { - var oldExif: ExifInterface? = null - if (isNougatPlus()) { - val inputStream = contentResolver.openInputStream(Uri.fromFile(File(path))) - oldExif = ExifInterface(inputStream!!) - } + ensureBackgroundThread { + var oldExif: ExifInterface? = null + if (isNougatPlus()) { + val inputStream = contentResolver.openInputStream(Uri.fromFile(File(path))) + oldExif = ExifInterface(inputStream!!) + } - val newBitmap = Glide.with(applicationContext).asBitmap().load(path).submit(size.x, size.y).get() + val newBitmap = Glide.with(applicationContext).asBitmap().load(path).submit(size.x, size.y).get() - val newFile = File(path) - val newFileDirItem = FileDirItem(path, path.getFilenameFromPath()) - getFileOutputStream(newFileDirItem, true) { out -> - if (out != null) { - out.use { - try { - newBitmap.compress(newFile.absolutePath.getCompressionFormat(), 90, out) + val newFile = File(path) + val newFileDirItem = FileDirItem(path, path.getFilenameFromPath()) + getFileOutputStream(newFileDirItem, true) { out -> + if (out != null) { + out.use { + try { + newBitmap.compress(newFile.absolutePath.getCompressionFormat(), 90, out) - if (isNougatPlus()) { - val newExif = ExifInterface(newFile.absolutePath) - oldExif?.copyNonDimensionAttributesTo(newExif) + if (isNougatPlus()) { + val newExif = ExifInterface(newFile.absolutePath) + oldExif?.copyNonDimensionAttributesTo(newExif) + } + } catch (ignored: Exception) { } - } catch (ignored: Exception) { - } - callback(true) + callback(true) + } + } else { + callback(false) } - } else { - callback(false) } } }