try un/hiding nomedia folders immediately after updating

This commit is contained in:
tibbi 2018-04-09 11:27:20 +02:00
parent b6d24492ed
commit 71127d45d1
2 changed files with 50 additions and 33 deletions

View file

@ -30,7 +30,7 @@ import java.io.File
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Directory>, val listener: DirOperationsListener?, recyclerView: MyRecyclerView, class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directory>, val listener: DirOperationsListener?, recyclerView: MyRecyclerView,
val isPickIntent: Boolean, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) : val isPickIntent: Boolean, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) :
MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
@ -192,8 +192,21 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
} }
} else { } else {
activity.removeNoMedia(it) { activity.removeNoMedia(it) {
activity.scanPath(it) if (activity.config.shouldShowHidden) {
noMediaHandled() dirs.forEachIndexed { index, directory ->
if (directory.path.startsWith(it, true)) {
val hidden = activity.getString(R.string.hidden)
directory.name = directory.name.removeSuffix(hidden).trim()
}
}
updateDirs(dirs)
listener?.updateDirectories(dirs.toList() as ArrayList, true)
} else {
activity.runOnUiThread {
listener?.refreshItems()
finishActMode()
}
}
} }
} }
} }
@ -201,31 +214,42 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
private fun hideFolder(path: String) { private fun hideFolder(path: String) {
activity.addNoMedia(path) { activity.addNoMedia(path) {
val positionsToRemove = ArrayList<Int>() if (activity.config.shouldShowHidden) {
val newDirs = dirs.filterIndexed { index, directory -> val hidden = activity.getString(R.string.hidden)
val removeDir = directory.path.startsWith(path, true) dirs.forEachIndexed { index, directory ->
if (removeDir) { if (directory.path.startsWith(path, true)) {
positionsToRemove.add(index) directory.name += " $hidden"
}
} }
!removeDir updateDirs(dirs)
} as ArrayList<Directory> listener?.updateDirectories(dirs.toList() as ArrayList, true)
} else {
val affectedPositions = ArrayList<Int>()
val newDirs = dirs.filterIndexed { index, directory ->
val removeDir = directory.path.startsWith(path, true)
if (removeDir) {
affectedPositions.add(index)
}
!removeDir
} as ArrayList<Directory>
activity.runOnUiThread { activity.runOnUiThread {
positionsToRemove.sortedDescending().forEach { affectedPositions.sortedDescending().forEach {
notifyItemRemoved(it + positionOffset) notifyItemRemoved(it + positionOffset)
itemViews.put(it, null) itemViews.put(it, null)
}
val newItems = SparseArray<View>()
(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)
} }
val newItems = SparseArray<View>()
(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)
} }
} }
} }
@ -244,13 +268,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
} }
} }
private fun noMediaHandled() {
activity.runOnUiThread {
listener?.refreshItems()
finishActMode()
}
}
private fun pinFolders(pin: Boolean) { private fun pinFolders(pin: Boolean) {
if (pin) { if (pin) {
config.addPinnedFolders(getSelectedPaths()) config.addPinnedFolders(getSelectedPaths())

View file

@ -27,7 +27,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
val config = context.config val config = context.config
val groupedMedia = mediaFetcher.getMediaByDirectories(isPickVideo, isPickImage) val groupedMedia = mediaFetcher.getMediaByDirectories(isPickVideo, isPickImage)
val directories = ArrayList<Directory>() val directories = ArrayList<Directory>()
val hidden = context.resources.getString(R.string.hidden) val hidden = context.getString(R.string.hidden)
val albumCovers = config.parseAlbumCovers() val albumCovers = config.parseAlbumCovers()
val hasOTG = context.hasOTGConnected() && context.config.OTGBasePath.isNotEmpty() val hasOTG = context.hasOTGConnected() && context.config.OTGBasePath.isNotEmpty()
val includedFolders = config.includedFolders val includedFolders = config.includedFolders