visually speed up file deletion from fullscreen view by storing ignored paths

This commit is contained in:
tibbi 2019-05-13 21:11:47 +02:00
parent 594c198cf2
commit 1e697e75d6

View file

@ -70,6 +70,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private var mMediaFiles = ArrayList<Medium>() private var mMediaFiles = ArrayList<Medium>()
private var mFavoritePaths = ArrayList<String>() private var mFavoritePaths = ArrayList<String>()
private var mIgnoredPaths = ArrayList<String>()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -908,17 +909,22 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
if (config.useRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) { if (config.useRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) {
movePathsInRecycleBin(arrayListOf(path)) { movePathsInRecycleBin(arrayListOf(path)) {
if (it) { if (it) {
tryDeleteFileDirItem(fileDirItem, false, false) { handleDeletion(fileDirItem, false)
refreshViewPager()
}
} else { } else {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
} }
} }
} else { } else {
tryDeleteFileDirItem(fileDirItem, false, true) { handleDeletion(fileDirItem, true)
refreshViewPager() }
} }
private fun handleDeletion(fileDirItem: FileDirItem, deleteFromDatabase: Boolean) {
mIgnoredPaths.add(fileDirItem.path)
val media = mMediaFiles.filter { !mIgnoredPaths.contains(it.path) } as ArrayList<ThumbnailItem>
gotMedia(media)
tryDeleteFileDirItem(fileDirItem, false, deleteFromDatabase) {
mIgnoredPaths.remove(fileDirItem.path)
} }
} }
@ -961,7 +967,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
private fun gotMedia(thumbnailItems: ArrayList<ThumbnailItem>) { private fun gotMedia(thumbnailItems: ArrayList<ThumbnailItem>) {
val media = thumbnailItems.asSequence().filter { it is Medium }.map { it as Medium }.toMutableList() as ArrayList<Medium> val media = thumbnailItems.asSequence().filter { it is Medium && !mIgnoredPaths.contains(it.path) }.map { it as Medium }.toMutableList() as ArrayList<Medium>
if (isDirEmpty(media) || media.hashCode() == mPrevHashcode) { if (isDirEmpty(media) || media.hashCode() == mPrevHashcode) {
return return
} }