improve cache clearing at rotating a file

This commit is contained in:
tibbi 2019-01-13 21:16:20 +01:00
parent 89a8d740b5
commit f8d39f61af
3 changed files with 23 additions and 18 deletions

View file

@ -27,6 +27,7 @@ import com.simplemobiletools.gallery.pro.dialogs.PickDirectoryDialog
import com.simplemobiletools.gallery.pro.helpers.NOMEDIA import com.simplemobiletools.gallery.pro.helpers.NOMEDIA
import com.simplemobiletools.gallery.pro.helpers.RECYCLE_BIN import com.simplemobiletools.gallery.pro.helpers.RECYCLE_BIN
import com.simplemobiletools.gallery.pro.interfaces.MediumDao import com.simplemobiletools.gallery.pro.interfaces.MediumDao
import com.squareup.picasso.Picasso
import java.io.File import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
import java.io.InputStream import java.io.InputStream
@ -406,22 +407,11 @@ fun BaseSimpleActivity.saveRotatedImageToFile(oldPath: String, newPath: String,
copyFile(tmpPath, newPath) copyFile(tmpPath, newPath)
scanPathRecursively(newPath) scanPathRecursively(newPath)
toast(R.string.file_saved) toast(R.string.file_saved)
fileRotatedSuccessfully(newPath, oldLastModified)
if (config.keepLastModified) {
File(newPath).setLastModified(oldLastModified)
updateLastModified(newPath, oldLastModified)
}
it.flush() it.flush()
it.close() it.close()
callback.invoke() callback.invoke()
// we cannot refresh a specific image in Glide Cache, so just clear it all
val glide = Glide.get(applicationContext)
glide.clearDiskCache()
runOnUiThread {
glide.clearMemory()
}
} }
} catch (e: OutOfMemoryError) { } catch (e: OutOfMemoryError) {
toast(R.string.out_of_memory_error) toast(R.string.out_of_memory_error)
@ -438,10 +428,7 @@ fun Activity.tryRotateByExif(path: String, degrees: Int, callback: () -> Unit):
val file = File(path) val file = File(path)
val oldLastModified = file.lastModified() val oldLastModified = file.lastModified()
if (saveImageRotation(path, degrees)) { if (saveImageRotation(path, degrees)) {
if (config.keepLastModified) { fileRotatedSuccessfully(path, oldLastModified)
file.setLastModified(oldLastModified)
updateLastModified(path, oldLastModified)
}
callback.invoke() callback.invoke()
toast(R.string.file_saved) toast(R.string.file_saved)
true true
@ -454,6 +441,21 @@ fun Activity.tryRotateByExif(path: String, degrees: Int, callback: () -> Unit):
} }
} }
fun Activity.fileRotatedSuccessfully(path: String, lastModified: Long) {
if (config.keepLastModified) {
File(path).setLastModified(lastModified)
updateLastModified(path, lastModified)
}
Picasso.get().invalidate(path.getFileKey())
// we cannot refresh a specific image in Glide Cache, so just clear it all
val glide = Glide.get(applicationContext)
glide.clearDiskCache()
runOnUiThread {
glide.clearMemory()
}
}
fun BaseSimpleActivity.copyFile(source: String, destination: String) { fun BaseSimpleActivity.copyFile(source: String, destination: String) {
var inputStream: InputStream? = null var inputStream: InputStream? = null
var out: OutputStream? = null var out: OutputStream? = null

View file

@ -6,9 +6,11 @@ import com.simplemobiletools.commons.helpers.OTG_PATH
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
fun String.getFileSignature(): ObjectKey { fun String.getFileSignature() = ObjectKey(getFileKey())
fun String.getFileKey(): String {
val file = File(this) val file = File(this)
return ObjectKey("${file.absolutePath}${file.lastModified()}") return "${file.absolutePath}${file.lastModified()}"
} }
fun String.isThisOrParentIncluded(includedPaths: MutableSet<String>) = includedPaths.any { startsWith(it, true) } fun String.isThisOrParentIncluded(includedPaths: MutableSet<String>) = includedPaths.any { startsWith(it, true) }

View file

@ -336,6 +336,7 @@ class PhotoFragment : ViewPagerFragment() {
val picasso = Picasso.get() val picasso = Picasso.get()
.load(pathToLoad) .load(pathToLoad)
.centerInside() .centerInside()
.stableKey(mMedium.path.getFileKey())
.resize(mScreenWidth, mScreenHeight) .resize(mScreenWidth, mScreenHeight)
if (degrees != 0) { if (degrees != 0) {