Add `rescanPathsAndUpdateLastModified` extension
This commit is contained in:
parent
428a157f7f
commit
ce898ba1cc
|
@ -10,15 +10,13 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
|||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.gallery.pro.R
|
||||
import com.simplemobiletools.gallery.pro.extensions.config
|
||||
import com.simplemobiletools.gallery.pro.extensions.ensureWriteAccess
|
||||
import com.simplemobiletools.gallery.pro.extensions.fixDateTaken
|
||||
import com.simplemobiletools.gallery.pro.extensions.rescanPathsAndUpdateLastModified
|
||||
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_info
|
||||
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"
|
||||
|
@ -113,17 +111,7 @@ class ResizeMultipleImagesDialog(
|
|||
toast(R.string.images_resized_successfully)
|
||||
}
|
||||
|
||||
rescanPaths(pathsToRescan) {
|
||||
fixDateTaken(pathsToRescan, false)
|
||||
for (path in pathsToRescan) {
|
||||
val file = File(path)
|
||||
val lastModified = file.lastModified()
|
||||
if (config.keepLastModified && lastModified != 0L) {
|
||||
File(file.absolutePath).setLastModified(lastModified)
|
||||
updateLastModified(file.absolutePath, lastModified)
|
||||
}
|
||||
}
|
||||
}
|
||||
rescanPathsAndUpdateLastModified(pathsToRescan)
|
||||
activity.runOnUiThread {
|
||||
dialog?.dismiss()
|
||||
callback.invoke()
|
||||
|
|
|
@ -747,6 +747,7 @@ fun BaseSimpleActivity.ensureWriteAccess(path: String, callback: () -> Unit) {
|
|||
callback.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
needsStupidWritePermissions(path) -> {
|
||||
handleSAFDialog(path) {
|
||||
if (!it) {
|
||||
|
@ -755,6 +756,7 @@ fun BaseSimpleActivity.ensureWriteAccess(path: String, callback: () -> Unit) {
|
|||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
isAccessibleWithSAFSdk30(path) -> {
|
||||
handleSAFDialogSdk30(path) {
|
||||
if (!it) {
|
||||
|
@ -763,6 +765,7 @@ fun BaseSimpleActivity.ensureWriteAccess(path: String, callback: () -> Unit) {
|
|||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
callback()
|
||||
}
|
||||
|
@ -797,16 +800,8 @@ fun BaseSimpleActivity.launchResizeImageDialog(path: String, callback: (() -> Un
|
|||
toast(R.string.file_saved)
|
||||
|
||||
val file = File(path)
|
||||
val lastModified = file.lastModified()
|
||||
val paths = arrayListOf(file.absolutePath)
|
||||
rescanPaths(paths) {
|
||||
fixDateTaken(paths, false)
|
||||
if (config.keepLastModified && lastModified != 0L) {
|
||||
File(file.absolutePath).setLastModified(lastModified)
|
||||
updateLastModified(file.absolutePath, lastModified)
|
||||
}
|
||||
}
|
||||
|
||||
rescanPathsAndUpdateLastModified(paths)
|
||||
runOnUiThread {
|
||||
callback?.invoke()
|
||||
}
|
||||
|
@ -855,6 +850,20 @@ 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 saveFile(path: String, bitmap: Bitmap, out: FileOutputStream, degrees: Int) {
|
||||
val matrix = Matrix()
|
||||
matrix.postRotate(degrees.toFloat())
|
||||
|
|
Loading…
Reference in New Issue