add the exclusion functionality

This commit is contained in:
tibbi 2017-02-26 19:31:20 +01:00
parent f354818b66
commit 4572295698
5 changed files with 27 additions and 2 deletions

View File

@ -179,7 +179,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
} }
private fun excludeFolder() { private fun excludeFolder() {
config.addExcludedFolder(mPath)
finish()
} }
private fun deleteDirectoryIfEmpty() { private fun deleteDirectoryIfEmpty() {

View File

@ -197,7 +197,9 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
} }
private fun excludeFolder() { private fun excludeFolder() {
activity.config.addExcludedFolders(getSelectedPaths())
listener?.refreshItems()
actMode?.finish()
} }
private fun noMediaHandled() { private fun noMediaHandled() {

View File

@ -23,6 +23,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
val showMedia = config.showMedia val showMedia = config.showMedia
val fileSorting = config.fileSorting val fileSorting = config.fileSorting
val parents = context.getParents() val parents = context.getParents()
removeExcludedFolders(parents)
parents.forEach { parents.forEach {
val filenames = File(it).list() val filenames = File(it).list()
@ -92,6 +93,12 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
return directories return directories
} }
private fun removeExcludedFolders(paths: MutableList<String>) {
val excludedPaths = config.excludedFolders
val ignorePaths = paths.filter { excludedPaths.contains(it) }
paths.removeAll(ignorePaths)
}
private fun movePinnedToFront(dirs: ArrayList<Directory>): ArrayList<Directory> { private fun movePinnedToFront(dirs: ArrayList<Directory>): ArrayList<Directory> {
val foundFolders = ArrayList<Directory>() val foundFolders = ArrayList<Directory>()
val pinnedFolders = config.pinnedFolders val pinnedFolders = config.pinnedFolders

View File

@ -54,6 +54,20 @@ class Config(context: Context) : BaseConfig(context) {
pinnedFolders = currPinnedFolders pinnedFolders = currPinnedFolders
} }
fun addExcludedFolder(path: String) {
addExcludedFolders(HashSet<String>(Arrays.asList(path)))
}
fun addExcludedFolders(paths: Set<String>) {
val currExcludedFolders = HashSet<String>(excludedFolders)
currExcludedFolders.addAll(paths)
excludedFolders = currExcludedFolders
}
var excludedFolders: MutableSet<String>
get() = prefs.getStringSet(EXCLUDED_FOLDERS, HashSet<String>())
set(excludedFolders) = prefs.edit().remove(EXCLUDED_FOLDERS).putStringSet(EXCLUDED_FOLDERS, excludedFolders).apply()
fun saveFolderMedia(path: String, json: String) { fun saveFolderMedia(path: String, json: String) {
prefs.edit().putString(SAVE_FOLDER_PREFIX + path, json).apply() prefs.edit().putString(SAVE_FOLDER_PREFIX + path, json).apply()
} }

View File

@ -16,6 +16,7 @@ val SHOW_MEDIA = "show_media"
val SAVE_FOLDER_PREFIX = "folder_" val SAVE_FOLDER_PREFIX = "folder_"
val HIDE_FOLDER_TOOLTIP_SHOWN = "hide_folder_tooltip_shown" val HIDE_FOLDER_TOOLTIP_SHOWN = "hide_folder_tooltip_shown"
val EXCLUDE_FOLDER_TOOLTIP_SHOWN = "exclude_folder_tooltip_shown" val EXCLUDE_FOLDER_TOOLTIP_SHOWN = "exclude_folder_tooltip_shown"
val EXCLUDED_FOLDERS = "excluded_folders"
val NOMEDIA = ".nomedia" val NOMEDIA = ".nomedia"