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