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,17 +214,27 @@ 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 hidden = activity.getString(R.string.hidden)
dirs.forEachIndexed { index, directory ->
if (directory.path.startsWith(path, true)) {
directory.name += " $hidden"
}
}
updateDirs(dirs)
listener?.updateDirectories(dirs.toList() as ArrayList, true)
} else {
val affectedPositions = ArrayList<Int>()
val newDirs = dirs.filterIndexed { index, directory -> val newDirs = dirs.filterIndexed { index, directory ->
val removeDir = directory.path.startsWith(path, true) val removeDir = directory.path.startsWith(path, true)
if (removeDir) { if (removeDir) {
positionsToRemove.add(index) affectedPositions.add(index)
} }
!removeDir !removeDir
} as ArrayList<Directory> } 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)
} }
@ -229,6 +252,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
} }
} }
} }
}
private fun tryExcludeFolder() { private fun tryExcludeFolder() {
val paths = getSelectedPaths() val paths = getSelectedPaths()
@ -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