Rescan paths after updating modified time

This commit is contained in:
Naveen 2023-05-27 16:44:50 +05:30
parent 799689ab7e
commit 761ebee77b
No known key found for this signature in database
GPG key ID: 0E155DAD31671DA3
2 changed files with 24 additions and 18 deletions

View file

@ -12,6 +12,7 @@ import com.simplemobiletools.gallery.pro.extensions.resizeImage
import kotlinx.android.synthetic.main.dialog_resize_multiple_images.view.resize_factor_edit_text
import kotlinx.android.synthetic.main.dialog_resize_multiple_images.view.resize_factor_input_layout
import kotlinx.android.synthetic.main.dialog_resize_multiple_images.view.resize_progress
import java.io.File
import kotlin.math.roundToInt
private const val DEFAULT_RESIZE_FACTOR = "75"
@ -76,17 +77,20 @@ class ResizeMultipleImagesDialog(
val parentPath = imagePaths.first().getParentPath()
val pathsToRescan = arrayListOf<String>()
val pathLastModifiedMap = mutableMapOf<String, Long>()
ensureWriteAccess(parentPath) {
ensureBackgroundThread {
for (i in imagePaths.indices) {
val path = imagePaths[i]
val size = newSizes[i]
val lastModified = File(path).lastModified()
try {
resizeImage(path, size) {
if (it) {
pathsToRescan.add(path)
pathLastModifiedMap[path] = lastModified
runOnUiThread {
progressView.progress = i + 1
}
@ -106,10 +110,11 @@ class ResizeMultipleImagesDialog(
toast(R.string.images_resized_successfully)
}
rescanPathsAndUpdateLastModified(pathsToRescan)
activity.runOnUiThread {
dialog?.dismiss()
callback.invoke()
rescanPathsAndUpdateLastModified(pathsToRescan, pathLastModifiedMap) {
activity.runOnUiThread {
dialog?.dismiss()
callback.invoke()
}
}
}
}

View file

@ -796,16 +796,18 @@ fun BaseSimpleActivity.launchResizeImageDialog(path: String, callback: (() -> Un
val originalSize = path.getImageResolution(this) ?: return
ResizeWithPathDialog(this, originalSize, path) { newSize, newPath ->
ensureBackgroundThread {
val file = File(newPath)
val pathLastModifiedMap = mapOf(file.absolutePath to file.lastModified())
try {
resizeImage(newPath, newSize) { success ->
if (success) {
toast(R.string.file_saved)
val file = File(path)
val paths = arrayListOf(file.absolutePath)
rescanPathsAndUpdateLastModified(paths)
runOnUiThread {
callback?.invoke()
rescanPathsAndUpdateLastModified(paths, pathLastModifiedMap) {
runOnUiThread {
callback?.invoke()
}
}
} else {
toast(R.string.image_editing_failed)
@ -852,18 +854,17 @@ fun BaseSimpleActivity.resizeImage(path: String, size: Point, callback: (success
}
}
fun BaseSimpleActivity.rescanPathsAndUpdateLastModified(paths: ArrayList<String>) {
rescanPaths(paths) {
fixDateTaken(paths, false)
for (path in paths) {
val file = File(path)
val lastModified = file.lastModified()
if (config.keepLastModified && lastModified != 0L) {
File(file.absolutePath).setLastModified(lastModified)
updateLastModified(file.absolutePath, lastModified)
}
fun BaseSimpleActivity.rescanPathsAndUpdateLastModified(paths: ArrayList<String>, pathLastModifiedMap: Map<String, Long>, callback: () -> Unit) {
fixDateTaken(paths, false)
for (path in paths) {
val file = File(path)
val lastModified = pathLastModifiedMap[path]
if (config.keepLastModified && lastModified != null && lastModified != 0L) {
File(file.absolutePath).setLastModified(lastModified)
updateLastModified(file.absolutePath, lastModified)
}
}
rescanPaths(paths, callback)
}
fun saveFile(path: String, bitmap: Bitmap, out: FileOutputStream, degrees: Int) {