couple improvements related to saving edited images
This commit is contained in:
parent
bfc1d3d0fd
commit
3f097a409b
|
@ -45,7 +45,10 @@ import com.simplemobiletools.gallery.fragments.ViewPagerFragment
|
||||||
import com.simplemobiletools.gallery.helpers.*
|
import com.simplemobiletools.gallery.helpers.*
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import kotlinx.android.synthetic.main.activity_medium.*
|
import kotlinx.android.synthetic.main.activity_medium.*
|
||||||
import java.io.*
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.io.OutputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, ViewPagerFragment.FragmentListener {
|
class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, ViewPagerFragment.FragmentListener {
|
||||||
|
@ -527,7 +530,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val newFile = File(newPath)
|
|
||||||
val tmpFile = File(filesDir, ".tmp_${newPath.getFilenameFromPath()}")
|
val tmpFile = File(filesDir, ".tmp_${newPath.getFilenameFromPath()}")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -539,22 +541,24 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
|
|
||||||
val oldLastModified = getCurrentFile().lastModified()
|
val oldLastModified = getCurrentFile().lastModified()
|
||||||
if (oldPath.isJpg()) {
|
if (oldPath.isJpg()) {
|
||||||
copyFile(getCurrentFile(), tmpFile)
|
copyFile(getCurrentPath(), tmpFile.absolutePath)
|
||||||
saveExifRotation(ExifInterface(tmpFile.absolutePath), mRotationDegrees)
|
saveExifRotation(ExifInterface(tmpFile.absolutePath), mRotationDegrees)
|
||||||
} else {
|
} else {
|
||||||
val bitmap = BitmapFactory.decodeFile(oldPath)
|
val inputstream = getFileInputStreamSync(oldPath)
|
||||||
|
val bitmap = BitmapFactory.decodeStream(inputstream)
|
||||||
saveFile(tmpFile, bitmap, it as FileOutputStream)
|
saveFile(tmpFile, bitmap, it as FileOutputStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmpFile.length() > 0 && getDoesFilePathExist(newPath)) {
|
if (tmpFile.length() > 0 && getDoesFilePathExist(newPath)) {
|
||||||
tryDeleteFileDirItem(FileDirItem(newPath, newPath.getFilenameFromPath()))
|
tryDeleteFileDirItem(FileDirItem(newPath, newPath.getFilenameFromPath()))
|
||||||
}
|
}
|
||||||
copyFile(tmpFile, newFile)
|
|
||||||
|
copyFile(tmpFile.absolutePath, newPath)
|
||||||
scanPath(newPath)
|
scanPath(newPath)
|
||||||
toast(R.string.file_saved)
|
toast(R.string.file_saved)
|
||||||
|
|
||||||
if (config.keepLastModified) {
|
if (config.keepLastModified) {
|
||||||
newFile.setLastModified(oldLastModified)
|
File(newPath).setLastModified(oldLastModified)
|
||||||
updateLastModified(newPath, oldLastModified)
|
updateLastModified(newPath, oldLastModified)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,14 +600,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun copyFile(source: File, destination: File) {
|
private fun copyFile(source: String, destination: String) {
|
||||||
var inputStream: InputStream? = null
|
var inputStream: InputStream? = null
|
||||||
var out: OutputStream? = null
|
var out: OutputStream? = null
|
||||||
try {
|
try {
|
||||||
val fileDocument = if (isPathOnSD(destination.absolutePath)) getDocumentFile(destination.parent) else null
|
out = getFileOutputStreamSync(destination, source.getMimeType())
|
||||||
out = getFileOutputStreamSync(destination.absolutePath, source.getMimeType(), fileDocument)
|
inputStream = getFileInputStreamSync(source)
|
||||||
inputStream = FileInputStream(source)
|
inputStream?.copyTo(out!!)
|
||||||
inputStream.copyTo(out!!)
|
|
||||||
} finally {
|
} finally {
|
||||||
inputStream?.close()
|
inputStream?.close()
|
||||||
out?.close()
|
out?.close()
|
||||||
|
|
Loading…
Reference in New Issue