Rescan paths after updating modified time
This commit is contained in:
parent
799689ab7e
commit
761ebee77b
2 changed files with 24 additions and 18 deletions
|
@ -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_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_factor_input_layout
|
||||||
import kotlinx.android.synthetic.main.dialog_resize_multiple_images.view.resize_progress
|
import kotlinx.android.synthetic.main.dialog_resize_multiple_images.view.resize_progress
|
||||||
|
import java.io.File
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
private const val DEFAULT_RESIZE_FACTOR = "75"
|
private const val DEFAULT_RESIZE_FACTOR = "75"
|
||||||
|
@ -76,17 +77,20 @@ class ResizeMultipleImagesDialog(
|
||||||
|
|
||||||
val parentPath = imagePaths.first().getParentPath()
|
val parentPath = imagePaths.first().getParentPath()
|
||||||
val pathsToRescan = arrayListOf<String>()
|
val pathsToRescan = arrayListOf<String>()
|
||||||
|
val pathLastModifiedMap = mutableMapOf<String, Long>()
|
||||||
|
|
||||||
ensureWriteAccess(parentPath) {
|
ensureWriteAccess(parentPath) {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
for (i in imagePaths.indices) {
|
for (i in imagePaths.indices) {
|
||||||
val path = imagePaths[i]
|
val path = imagePaths[i]
|
||||||
val size = newSizes[i]
|
val size = newSizes[i]
|
||||||
|
val lastModified = File(path).lastModified()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
resizeImage(path, size) {
|
resizeImage(path, size) {
|
||||||
if (it) {
|
if (it) {
|
||||||
pathsToRescan.add(path)
|
pathsToRescan.add(path)
|
||||||
|
pathLastModifiedMap[path] = lastModified
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
progressView.progress = i + 1
|
progressView.progress = i + 1
|
||||||
}
|
}
|
||||||
|
@ -106,10 +110,11 @@ class ResizeMultipleImagesDialog(
|
||||||
toast(R.string.images_resized_successfully)
|
toast(R.string.images_resized_successfully)
|
||||||
}
|
}
|
||||||
|
|
||||||
rescanPathsAndUpdateLastModified(pathsToRescan)
|
rescanPathsAndUpdateLastModified(pathsToRescan, pathLastModifiedMap) {
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
callback.invoke()
|
callback.invoke()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -796,16 +796,18 @@ fun BaseSimpleActivity.launchResizeImageDialog(path: String, callback: (() -> Un
|
||||||
val originalSize = path.getImageResolution(this) ?: return
|
val originalSize = path.getImageResolution(this) ?: return
|
||||||
ResizeWithPathDialog(this, originalSize, path) { newSize, newPath ->
|
ResizeWithPathDialog(this, originalSize, path) { newSize, newPath ->
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
|
val file = File(newPath)
|
||||||
|
val pathLastModifiedMap = mapOf(file.absolutePath to file.lastModified())
|
||||||
try {
|
try {
|
||||||
resizeImage(newPath, newSize) { success ->
|
resizeImage(newPath, newSize) { success ->
|
||||||
if (success) {
|
if (success) {
|
||||||
toast(R.string.file_saved)
|
toast(R.string.file_saved)
|
||||||
|
|
||||||
val file = File(path)
|
|
||||||
val paths = arrayListOf(file.absolutePath)
|
val paths = arrayListOf(file.absolutePath)
|
||||||
rescanPathsAndUpdateLastModified(paths)
|
rescanPathsAndUpdateLastModified(paths, pathLastModifiedMap) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
callback?.invoke()
|
callback?.invoke()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.image_editing_failed)
|
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>) {
|
fun BaseSimpleActivity.rescanPathsAndUpdateLastModified(paths: ArrayList<String>, pathLastModifiedMap: Map<String, Long>, callback: () -> Unit) {
|
||||||
rescanPaths(paths) {
|
fixDateTaken(paths, false)
|
||||||
fixDateTaken(paths, false)
|
for (path in paths) {
|
||||||
for (path in paths) {
|
val file = File(path)
|
||||||
val file = File(path)
|
val lastModified = pathLastModifiedMap[path]
|
||||||
val lastModified = file.lastModified()
|
if (config.keepLastModified && lastModified != null && lastModified != 0L) {
|
||||||
if (config.keepLastModified && lastModified != 0L) {
|
File(file.absolutePath).setLastModified(lastModified)
|
||||||
File(file.absolutePath).setLastModified(lastModified)
|
updateLastModified(file.absolutePath, lastModified)
|
||||||
updateLastModified(file.absolutePath, lastModified)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
rescanPaths(paths, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveFile(path: String, bitmap: Bitmap, out: FileOutputStream, degrees: Int) {
|
fun saveFile(path: String, bitmap: Bitmap, out: FileOutputStream, degrees: Int) {
|
||||||
|
|
Loading…
Reference in a new issue