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.
This commit is contained in:
tibbi 2021-08-30 22:38:29 +02:00
parent d9194176ee
commit 4d00682ec6
5 changed files with 32 additions and 33 deletions

View File

@ -78,7 +78,7 @@ android {
} }
dependencies { 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 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.22' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.22'

View File

@ -887,11 +887,9 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
private fun scanFinalPath(path: String) { private fun scanFinalPath(path: String) {
val paths = arrayListOf(path) val paths = arrayListOf(path)
rescanPaths(paths) { fixDateTaken(paths, false)
fixDateTaken(paths, false) setResult(Activity.RESULT_OK, intent)
setResult(Activity.RESULT_OK, intent) toast(R.string.file_saved)
toast(R.string.file_saved) finish()
finish()
}
} }
} }

View File

@ -625,9 +625,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
val fileDirItems = arrayListOf(FileDirItem(currPath, currPath.getFilenameFromPath())) val fileDirItems = arrayListOf(FileDirItem(currPath, currPath.getFilenameFromPath()))
tryCopyMoveFilesTo(fileDirItems, isCopyOperation) { tryCopyMoveFilesTo(fileDirItems, isCopyOperation) {
val newPath = "$it/${currPath.getFilenameFromPath()}" val newPath = "$it/${currPath.getFilenameFromPath()}"
rescanPaths(arrayListOf(newPath)) { fixDateTaken(arrayListOf(newPath), false)
fixDateTaken(arrayListOf(newPath), false)
}
config.tempFolderPath = "" config.tempFolderPath = ""
if (!isCopyOperation) { if (!isCopyOperation) {
@ -1019,13 +1017,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
toast(R.string.file_saved) toast(R.string.file_saved)
val paths = arrayListOf(file.absolutePath) val paths = arrayListOf(file.absolutePath)
rescanPaths(paths) { fixDateTaken(paths, false)
fixDateTaken(paths, false)
if (config.keepLastModified) { if (config.keepLastModified) {
File(file.absolutePath).setLastModified(lastModified) File(file.absolutePath).setLastModified(lastModified)
updateLastModified(file.absolutePath, lastModified) updateLastModified(file.absolutePath, lastModified)
}
} }
out.close() out.close()
} }

View File

@ -523,9 +523,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
activity.tryCopyMoveFilesTo(fileDirItems, isCopyOperation) { activity.tryCopyMoveFilesTo(fileDirItems, isCopyOperation) {
val destinationPath = it val destinationPath = it
val newPaths = fileDirItems.map { "$destinationPath/${it.name}" }.toMutableList() as java.util.ArrayList<String> val newPaths = fileDirItems.map { "$destinationPath/${it.name}" }.toMutableList() as java.util.ArrayList<String>
activity.rescanPaths(newPaths) { activity.fixDateTaken(newPaths, false)
activity.fixDateTaken(newPaths, false)
}
config.tempFolderPath = "" config.tempFolderPath = ""
listener?.refreshItems() listener?.refreshItems()

View File

@ -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 kotlinx.android.synthetic.main.video_item_grid.view.medium_thumbnail
import java.util.* import java.util.*
class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailItem>, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, class MediaAdapter(
val allowMultiplePicks: Boolean, val path: String, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) : activity: BaseSimpleActivity, var media: ArrayList<ThumbnailItem>, 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) { MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
private val INSTANT_LOAD_DURATION = 2000L private val INSTANT_LOAD_DURATION = 2000L
@ -355,9 +357,8 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailI
activity.applicationContext.rescanFolderMedia(fileDirItems.first().getParentPath()) activity.applicationContext.rescanFolderMedia(fileDirItems.first().getParentPath())
val newPaths = fileDirItems.map { "$destinationPath/${it.name}" }.toMutableList() as ArrayList<String> val newPaths = fileDirItems.map { "$destinationPath/${it.name}" }.toMutableList() as ArrayList<String>
activity.rescanPaths(newPaths) { activity.fixDateTaken(newPaths, false)
activity.fixDateTaken(newPaths, false)
}
if (!isCopyOperation) { if (!isCopyOperation) {
listener?.refreshItems() listener?.refreshItems()
activity.updateFavoritePaths(fileDirItems, destinationPath) activity.updateFavoritePaths(fileDirItems, destinationPath)
@ -531,11 +532,13 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailI
} }
if (showFileTypes && (medium.isGIF() || medium.isRaw() || medium.isSVG())) { if (showFileTypes && (medium.isGIF() || medium.isRaw() || medium.isSVG())) {
file_type.setText(when (medium.type) { file_type.setText(
TYPE_GIFS -> R.string.gif when (medium.type) {
TYPE_RAWS -> R.string.raw TYPE_GIFS -> R.string.gif
else -> R.string.svg TYPE_RAWS -> R.string.raw
}) else -> R.string.svg
}
)
file_type.beVisible() file_type.beVisible()
} else { } else {
file_type?.beGone() file_type?.beGone()
@ -573,16 +576,20 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailI
} }
if (loadImageInstantly) { if (loadImageInstantly) {
activity.loadImage(medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, roundedCorners, medium.getKey(), activity.loadImage(
rotatedImagePaths) medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, roundedCorners, medium.getKey(),
rotatedImagePaths
)
} else { } else {
medium_thumbnail.setImageDrawable(null) medium_thumbnail.setImageDrawable(null)
medium_thumbnail.isHorizontalScrolling = scrollHorizontally medium_thumbnail.isHorizontalScrolling = scrollHorizontally
delayHandler.postDelayed({ delayHandler.postDelayed({
val isVisible = visibleItemPaths.contains(medium.path) val isVisible = visibleItemPaths.contains(medium.path)
if (isVisible) { if (isVisible) {
activity.loadImage(medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, roundedCorners, activity.loadImage(
medium.getKey(), rotatedImagePaths) medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, roundedCorners,
medium.getKey(), rotatedImagePaths
)
} }
}, IMAGE_LOAD_DELAY) }, IMAGE_LOAD_DELAY)
} }