From 80f6df5e2958337ac9fd806985508e716a1af900 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 25 Sep 2017 23:53:15 +0200 Subject: [PATCH] do not autosave rotated images, related to #372 --- app/build.gradle | 2 +- .../gallery/activities/ViewPagerActivity.kt | 35 +++---------------- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c50f15187..1dbbd4cac 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,7 +37,7 @@ android { } dependencies { - compile 'com.simplemobiletools:commons:2.28.4' + compile 'com.simplemobiletools:commons:2.28.5' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' 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 468e2d69c..8b1150d40 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -434,34 +434,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun rotateImage() { - val currentMedium = getCurrentMedium() ?: return - if (currentMedium.isJpg() && !isPathOnSD(currentMedium.path)) { - rotateByExif() - } else { - rotateByDegrees() - } - } - - private fun rotateByExif() { - val exif = ExifInterface(getCurrentPath()) - val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL) - val newOrientation = getNewOrientation(orientation) - exif.setAttribute(ExifInterface.TAG_ORIENTATION, newOrientation) - exif.saveAttributes() - File(getCurrentPath()).setLastModified(System.currentTimeMillis()) - (getCurrentFragment() as? PhotoFragment)?.refreshBitmap() - } - - private fun getNewOrientation(rotation: Int): String { - return when (rotation) { - ExifInterface.ORIENTATION_ROTATE_90 -> ExifInterface.ORIENTATION_ROTATE_180 - ExifInterface.ORIENTATION_ROTATE_180 -> ExifInterface.ORIENTATION_ROTATE_270 - ExifInterface.ORIENTATION_ROTATE_270 -> ExifInterface.ORIENTATION_NORMAL - else -> ExifInterface.ORIENTATION_ROTATE_90 - }.toString() - } - - private fun rotateByDegrees() { mRotationDegrees = (mRotationDegrees + 90) % 360 getCurrentFragment()?.let { (it as? PhotoFragment)?.rotateImageViewBy(mRotationDegrees) @@ -475,7 +447,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View Thread({ toast(R.string.saving) val selectedFile = File(it) - val tmpFile = File(selectedFile.parent, "tmp_${it.getFilenameFromPath()}") + val tmpFile = File(selectedFile.parent, ".tmp_${it.getFilenameFromPath()}") try { val bitmap = BitmapFactory.decodeFile(currPath) getFileOutputStream(tmpFile) { @@ -498,7 +470,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View toast(R.string.out_of_memory_error) deleteFile(tmpFile) {} } catch (e: Exception) { - toast(R.string.unknown_error_occurred) + showErrorToast(e) deleteFile(tmpFile) {} } }).start() @@ -513,9 +485,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View out.flush() out.close() toast(R.string.file_saved) + mRotationDegrees = 0f + invalidateOptionsMenu() } - private fun isShowHiddenFlagNeeded(): Boolean { val file = File(mPath) if (file.isHidden)