fix saving rotated otg files

This commit is contained in:
tibbi 2018-04-24 22:19:11 +02:00
parent 68412e8480
commit 55d7ccfe03
2 changed files with 12 additions and 12 deletions

View file

@ -47,7 +47,7 @@ ext {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:3.19.15' implementation 'com.simplemobiletools:commons:3.19.17'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
implementation 'com.android.support:multidex:1.0.3' implementation 'com.android.support:multidex:1.0.3'
implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1'

View file

@ -530,10 +530,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
} }
val tmpFile = File(filesDir, ".tmp_${newPath.getFilenameFromPath()}") val tmpPath = "$filesDir/.tmp_${newPath.getFilenameFromPath()}"
val tmpFileDirItem = FileDirItem(tmpPath, tmpPath.getFilenameFromPath())
try { try {
getFileOutputStream(tmpFile.toFileDirItem(applicationContext)) { getFileOutputStream(tmpFileDirItem) {
if (it == null) { if (it == null) {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
return@getFileOutputStream return@getFileOutputStream
@ -541,19 +541,19 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
val oldLastModified = getCurrentFile().lastModified() val oldLastModified = getCurrentFile().lastModified()
if (oldPath.isJpg()) { if (oldPath.isJpg()) {
copyFile(getCurrentPath(), tmpFile.absolutePath) copyFile(getCurrentPath(), tmpPath)
saveExifRotation(ExifInterface(tmpFile.absolutePath), mRotationDegrees) saveExifRotation(ExifInterface(tmpPath), mRotationDegrees)
} else { } else {
val inputstream = getFileInputStreamSync(oldPath) val inputstream = getFileInputStreamSync(oldPath)
val bitmap = BitmapFactory.decodeStream(inputstream) val bitmap = BitmapFactory.decodeStream(inputstream)
saveFile(tmpFile, bitmap, it as FileOutputStream) saveFile(tmpPath, bitmap, it as FileOutputStream)
} }
if (tmpFile.length() > 0 && getDoesFilePathExist(newPath)) { if (getDoesFilePathExist(newPath)) {
tryDeleteFileDirItem(FileDirItem(newPath, newPath.getFilenameFromPath())) tryDeleteFileDirItem(FileDirItem(newPath, newPath.getFilenameFromPath()))
} }
copyFile(tmpFile.absolutePath, newPath) copyFile(tmpPath, newPath)
scanPath(newPath) scanPath(newPath)
toast(R.string.file_saved) toast(R.string.file_saved)
@ -579,7 +579,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} catch (e: Exception) { } catch (e: Exception) {
showErrorToast(e) showErrorToast(e)
} finally { } finally {
tryDeleteFileDirItem(FileDirItem(tmpFile.absolutePath, tmpFile.absolutePath.getFilenameFromPath())) tryDeleteFileDirItem(tmpFileDirItem)
} }
} }
@ -613,11 +613,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
} }
private fun saveFile(file: File, bitmap: Bitmap, out: FileOutputStream) { private fun saveFile(path: String, bitmap: Bitmap, out: FileOutputStream) {
val matrix = Matrix() val matrix = Matrix()
matrix.postRotate(mRotationDegrees.toFloat()) matrix.postRotate(mRotationDegrees.toFloat())
val bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true) val bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
bmp.compress(file.absolutePath.getCompressionFormat(), 90, out) bmp.compress(path.getCompressionFormat(), 90, out)
} }
private fun isShowHiddenFlagNeeded(): Boolean { private fun isShowHiddenFlagNeeded(): Boolean {