From 67c9f875ae3dd91486cb04121cc4def865aa1824 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 15 Mar 2018 18:58:21 +0100 Subject: [PATCH] move the EXIF rotating attempt in a separate function --- .../gallery/activities/ViewPagerActivity.kt | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 69103665f..f65de839c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -522,31 +522,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } - @TargetApi(Build.VERSION_CODES.N) private fun saveImageToFile(oldPath: String, newPath: String) { toast(R.string.saving) if (oldPath == newPath && oldPath.isJpg()) { - try { - if (!isPathOnSD(oldPath)) { - saveExifRotation(ExifInterface(oldPath)) - mRotationDegrees = 0f - invalidateOptionsMenu() - toast(R.string.file_saved) - return - } else if (isNougatPlus()) { - val documentFile = getSomeDocumentFile(oldPath) - if (documentFile != null) { - val parcelFileDescriptor = contentResolver.openFileDescriptor(documentFile.uri, "rw") - val fileDescriptor = parcelFileDescriptor.fileDescriptor - saveExifRotation(ExifInterface(fileDescriptor)) - mRotationDegrees = 0f - invalidateOptionsMenu() - toast(R.string.file_saved) - return - } - } - } catch (e: Exception) { - showErrorToast(e) + if (tryRotateByExif(oldPath)) { return } } @@ -603,6 +582,33 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } + @TargetApi(Build.VERSION_CODES.N) + private fun tryRotateByExif(path: String): Boolean { + try { + if (!isPathOnSD(path)) { + saveExifRotation(ExifInterface(path)) + mRotationDegrees = 0f + invalidateOptionsMenu() + toast(R.string.file_saved) + return true + } else if (isNougatPlus()) { + val documentFile = getSomeDocumentFile(path) + if (documentFile != null) { + val parcelFileDescriptor = contentResolver.openFileDescriptor(documentFile.uri, "rw") + val fileDescriptor = parcelFileDescriptor.fileDescriptor + saveExifRotation(ExifInterface(fileDescriptor)) + mRotationDegrees = 0f + invalidateOptionsMenu() + toast(R.string.file_saved) + return true + } + } + } catch (e: Exception) { + showErrorToast(e) + } + return false + } + private fun copyFile(source: File, destination: File) { var inputStream: InputStream? = null var out: OutputStream? = null