hide .nomedia subfolders too

This commit is contained in:
tibbi 2017-02-26 23:17:56 +01:00
parent d60ee0b387
commit e38ec1c5e3

View file

@ -67,35 +67,31 @@ fun Context.getParents(): ArrayList<String> {
cursor?.close() cursor?.close()
} }
val noMediaFolders = getNoMediaFolders()
val parents = ArrayList<String>() val parents = ArrayList<String>()
parentsSet.filterTo(parents, { File(it).isDirectory }) parentsSet.filterTo(parents, {
if (File(it).isDirectory) {
if (!config.showHiddenFolders) {
isFolderVisible(it, noMediaFolders)
} else
true
} else {
false
}
})
if (config.showHiddenFolders) { if (config.showHiddenFolders) {
parents.addAll(getNoMediaFolders()) parents.addAll(noMediaFolders)
} else {
removeHiddenFolders(parents)
} }
return parents return parents
} }
private fun removeHiddenFolders(paths: MutableList<String>) { private fun isFolderVisible(path: String, noMediaFolders: ArrayList<String>): Boolean {
val ignorePaths = ArrayList<String>() val parts = path.split("/")
for (path in paths) { return if (parts.any { it.startsWith(".") }) {
val dir = File(path) false
if (dir.exists() && dir.isDirectory) { } else !noMediaFolders.any { path.startsWith(it) }
if (dir.name.startsWith(".")) {
ignorePaths.add((path))
continue
}
val res = dir.list { file, filename -> filename == NOMEDIA }
if (res?.isNotEmpty() == true)
ignorePaths.add(path)
}
}
paths.removeAll(ignorePaths)
} }
fun Context.getNoMediaFolders(): ArrayList<String> { fun Context.getNoMediaFolders(): ArrayList<String> {
@ -113,7 +109,9 @@ fun Context.getNoMediaFolders(): ArrayList<String> {
if (cursor?.moveToFirst() == true) { if (cursor?.moveToFirst() == true) {
do { do {
val path = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA)) ?: continue val path = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA)) ?: continue
folders.add(File(path).parent) val noMediaFile = File(path)
if (noMediaFile.exists())
folders.add(noMediaFile.parent)
} while (cursor.moveToNext()) } while (cursor.moveToNext())
} }
} finally { } finally {