From 4d00682ec6d7b988397d664968bdb8bb36b1acaa Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 30 Aug 2021 22:38:29 +0200 Subject: [PATCH] avoid rescanning paths in some cases This can make files not be recognized as media files in some other apps, but rescanning can also too easily delete files. Let's try playing it safe. --- app/build.gradle | 2 +- .../gallery/pro/activities/EditActivity.kt | 10 +++--- .../pro/activities/ViewPagerActivity.kt | 14 +++----- .../gallery/pro/adapters/DirectoryAdapter.kt | 4 +-- .../gallery/pro/adapters/MediaAdapter.kt | 35 +++++++++++-------- 5 files changed, 32 insertions(+), 33 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6d8c92e07..13da2e0b8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -78,7 +78,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:94ece2461b' + implementation 'com.github.SimpleMobileTools:Simple-Commons:03149a0586' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.22' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt index 8a082817f..9b59219e0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt @@ -887,11 +887,9 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener private fun scanFinalPath(path: String) { val paths = arrayListOf(path) - rescanPaths(paths) { - fixDateTaken(paths, false) - setResult(Activity.RESULT_OK, intent) - toast(R.string.file_saved) - finish() - } + fixDateTaken(paths, false) + setResult(Activity.RESULT_OK, intent) + toast(R.string.file_saved) + finish() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index 6aadafbd6..3a36cdea6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -625,9 +625,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View val fileDirItems = arrayListOf(FileDirItem(currPath, currPath.getFilenameFromPath())) tryCopyMoveFilesTo(fileDirItems, isCopyOperation) { val newPath = "$it/${currPath.getFilenameFromPath()}" - rescanPaths(arrayListOf(newPath)) { - fixDateTaken(arrayListOf(newPath), false) - } + fixDateTaken(arrayListOf(newPath), false) config.tempFolderPath = "" if (!isCopyOperation) { @@ -1019,13 +1017,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View toast(R.string.file_saved) val paths = arrayListOf(file.absolutePath) - rescanPaths(paths) { - fixDateTaken(paths, false) + fixDateTaken(paths, false) - if (config.keepLastModified) { - File(file.absolutePath).setLastModified(lastModified) - updateLastModified(file.absolutePath, lastModified) - } + if (config.keepLastModified) { + File(file.absolutePath).setLastModified(lastModified) + updateLastModified(file.absolutePath, lastModified) } out.close() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index 28401776a..1d96317cc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -523,9 +523,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList - activity.rescanPaths(newPaths) { - activity.fixDateTaken(newPaths, false) - } + activity.fixDateTaken(newPaths, false) config.tempFolderPath = "" listener?.refreshItems() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index d04509ef1..d558b1d24 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -40,8 +40,10 @@ import kotlinx.android.synthetic.main.video_item_grid.view.medium_name import kotlinx.android.synthetic.main.video_item_grid.view.medium_thumbnail import java.util.* -class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, - val allowMultiplePicks: Boolean, val path: String, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) : +class MediaAdapter( + activity: BaseSimpleActivity, var media: ArrayList, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, + val allowMultiplePicks: Boolean, val path: String, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit +) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { private val INSTANT_LOAD_DURATION = 2000L @@ -355,9 +357,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList - activity.rescanPaths(newPaths) { - activity.fixDateTaken(newPaths, false) - } + activity.fixDateTaken(newPaths, false) + if (!isCopyOperation) { listener?.refreshItems() activity.updateFavoritePaths(fileDirItems, destinationPath) @@ -531,11 +532,13 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList R.string.gif - TYPE_RAWS -> R.string.raw - else -> R.string.svg - }) + file_type.setText( + when (medium.type) { + TYPE_GIFS -> R.string.gif + TYPE_RAWS -> R.string.raw + else -> R.string.svg + } + ) file_type.beVisible() } else { file_type?.beGone() @@ -573,16 +576,20 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList