do not autosave rotated images, related to #372

This commit is contained in:
tibbi 2017-09-25 23:53:15 +02:00
parent 64f8d37544
commit 80f6df5e29
2 changed files with 5 additions and 32 deletions

View File

@ -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'

View File

@ -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)