diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index c26f33a34..6de05308c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -681,8 +681,12 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { gotDirectories(movePinnedDirectoriesToFront(mDirs), true) } - override fun updateDirectories(directories: ArrayList) { - gotDirectories(directories, true) + override fun updateDirectories(directories: ArrayList, refreshList: Boolean) { + if (refreshList) { + gotDirectories(directories, true) + } else { + mDirs = directories + } } private fun checkWhatsNewDialog() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 6fa302bf9..fc39ff0c5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -1,5 +1,6 @@ package com.simplemobiletools.gallery.adapters +import android.util.SparseArray import android.view.Menu import android.view.View import android.view.ViewGroup @@ -170,11 +171,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList() + val newDirs = dirs.filterIndexed { index, directory -> + val removeDir = directory.path.startsWith(path, true) + if (removeDir) { + positionsToRemove.add(index) + } + !removeDir + } as ArrayList + + activity.runOnUiThread { + positionsToRemove.sortedDescending().forEach { + notifyItemRemoved(it + positionOffset) + itemViews.put(it, null) + } + + val newItems = SparseArray() + (0 until itemViews.size()) + .filter { itemViews[it] != null } + .forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) } + + currentDirectoriesHash = newDirs.hashCode() + itemViews = newItems + finishActMode() + fastScroller?.measureRecyclerView() + listener?.updateDirectories(newDirs, false) + } } } @@ -398,6 +423,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList) + fun updateDirectories(directories: ArrayList, refreshList: Boolean) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt index f15f4687e..534927e27 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Activity.kt @@ -110,8 +110,10 @@ fun AppCompatActivity.hideSystemUI() { fun BaseSimpleActivity.addNoMedia(path: String, callback: () -> Unit) { val file = File(path, NOMEDIA) - if (file.exists()) + if (file.exists()) { + callback() return + } if (needsStupidWritePermissions(path)) { handleSAFDialog(file.absolutePath) {