From 4f79d196d62fdc543be7890a5f38505ed96bced4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 19 Feb 2021 16:29:47 +0100 Subject: [PATCH] moving folder deletion and image orientation fetching to background threads --- .../pro/activities/ViewPagerActivity.kt | 10 +++++++--- .../gallery/pro/fragments/PhotoFragment.kt | 20 +++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index 37fc55029..0ba0fcb63 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -1164,9 +1164,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun deleteDirectoryIfEmpty() { val fileDirItem = FileDirItem(mDirectory, mDirectory.getFilenameFromPath(), File(mDirectory).isDirectory) - if (config.deleteEmptyFolders && !fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory && fileDirItem.getProperFileCount(this, true) == 0) { - tryDeleteFileDirItem(fileDirItem, true, true) - scanPathRecursively(mDirectory) + if (config.deleteEmptyFolders && !fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory) { + ensureBackgroundThread { + if (fileDirItem.getProperFileCount(this, true) == 0) { + tryDeleteFileDirItem(fileDirItem, true, true) + scanPathRecursively(mDirectory) + } + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt index 4e22c5b14..e5a80b9e3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt @@ -351,11 +351,15 @@ class PhotoFragment : ViewPagerFragment() { showPortraitStripe() } - mImageOrientation = getImageOrientation() - when { - mMedium.isGIF() -> loadGif() - mMedium.isSVG() -> loadSVG() - else -> loadBitmap() + ensureBackgroundThread { + mImageOrientation = getImageOrientation() + activity?.runOnUiThread { + when { + mMedium.isGIF() -> loadGif() + mMedium.isSVG() -> loadSVG() + else -> loadBitmap() + } + } } } @@ -687,9 +691,9 @@ class PhotoFragment : ViewPagerFragment() { val inputStream = if (mMedium.path.startsWith("content:/")) context!!.contentResolver.openInputStream(Uri.parse(mMedium.path)) else File(mMedium.path).inputStream() val imageParser = JpegImageParser().getXmpXml(ByteSourceInputStream(inputStream, mMedium.name), HashMap()) imageParser.contains("GPano:UsePanoramaViewer=\"True\"", true) || - imageParser.contains("True", true) || - imageParser.contains("GPano:FullPanoWidthPixels=") || - imageParser.contains("GPano:ProjectionType>Equirectangular") + imageParser.contains("True", true) || + imageParser.contains("GPano:FullPanoWidthPixels=") || + imageParser.contains("GPano:ProjectionType>Equirectangular") } catch (e: Exception) { false } catch (e: OutOfMemoryError) {