fetch nomedia files from MediaStore, use them for quick check
This commit is contained in:
parent
a4c590ddd3
commit
eb9ca5df77
3 changed files with 38 additions and 31 deletions
|
@ -304,6 +304,11 @@ fun Context.updateSubfolderCounts(children: ArrayList<Directory>, parentDirs: Ar
|
|||
|
||||
fun Context.getNoMediaFolders(callback: (folders: ArrayList<String>) -> Unit) {
|
||||
ensureBackgroundThread {
|
||||
callback(getNoMediaFoldersSync())
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.getNoMediaFoldersSync(): ArrayList<String> {
|
||||
val folders = ArrayList<String>()
|
||||
|
||||
val uri = Files.getContentUri("external")
|
||||
|
@ -321,7 +326,7 @@ fun Context.getNoMediaFolders(callback: (folders: ArrayList<String>) -> Unit) {
|
|||
val path = cursor.getStringValue(Files.FileColumns.DATA) ?: continue
|
||||
val noMediaFile = File(path)
|
||||
if (getDoesFilePathExist(noMediaFile.absolutePath, OTGPath) && noMediaFile.name == NOMEDIA) {
|
||||
folders.add("${noMediaFile.parent}/")
|
||||
folders.add("${noMediaFile.parent}")
|
||||
}
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
|
@ -329,8 +334,7 @@ fun Context.getNoMediaFolders(callback: (folders: ArrayList<String>) -> Unit) {
|
|||
cursor?.close()
|
||||
}
|
||||
|
||||
callback(folders)
|
||||
}
|
||||
return folders
|
||||
}
|
||||
|
||||
fun Context.rescanFolderMedia(path: String) {
|
||||
|
@ -519,9 +523,10 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly:
|
|||
val excludedPaths = config.excludedFolders
|
||||
val includedPaths = config.includedFolders
|
||||
|
||||
val noMediaFolders = getNoMediaFoldersSync()
|
||||
val folderNomediaStatuses = HashMap<String, Boolean>()
|
||||
var filteredDirectories = directories.filter {
|
||||
it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden, folderNomediaStatuses) { path, hasNoMedia ->
|
||||
it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden, folderNomediaStatuses, noMediaFolders) { path, hasNoMedia ->
|
||||
folderNomediaStatuses[path] = hasNoMedia
|
||||
}
|
||||
} as ArrayList<Directory>
|
||||
|
|
|
@ -11,7 +11,8 @@ fun String.isThisOrParentExcluded(excludedPaths: MutableSet<String>) = excludedP
|
|||
|
||||
// cache which folders contain .nomedia files to avoid checking them over and over again
|
||||
fun String.shouldFolderBeVisible(excludedPaths: MutableSet<String>, includedPaths: MutableSet<String>, showHidden: Boolean,
|
||||
folderNomediaStatuses: HashMap<String, Boolean>, callback: (path: String, hasNoMedia: Boolean) -> Unit): Boolean {
|
||||
folderNomediaStatuses: HashMap<String, Boolean>, noMediaFolders: ArrayList<String> = ArrayList(),
|
||||
callback: (path: String, hasNoMedia: Boolean) -> Unit): Boolean {
|
||||
if (isEmpty()) {
|
||||
return false
|
||||
}
|
||||
|
@ -36,7 +37,7 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet<String>, includedPath
|
|||
val containsNoMedia = if (showHidden) {
|
||||
false
|
||||
} else {
|
||||
File(this, NOMEDIA).exists()
|
||||
noMediaFolders.contains(this) || File(this, NOMEDIA).exists()
|
||||
}
|
||||
|
||||
return if (!showHidden && containsNoMedia) {
|
||||
|
@ -60,7 +61,7 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet<String>, includedPath
|
|||
break
|
||||
}
|
||||
} else {
|
||||
val noMediaExists = File(pathToCheck).exists()
|
||||
val noMediaExists = noMediaFolders.contains(pathToCheck) || File(pathToCheck).exists()
|
||||
callback(pathToCheck, noMediaExists)
|
||||
if (noMediaExists) {
|
||||
containsNoMediaOrDot = true
|
||||
|
|
|
@ -82,8 +82,9 @@ class MediaFetcher(val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
val noMediaFolders = context.getNoMediaFoldersSync()
|
||||
distinctPaths.filter {
|
||||
it.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden, folderNomediaStatuses) { path, hasNoMedia ->
|
||||
it.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden, folderNomediaStatuses, noMediaFolders) { path, hasNoMedia ->
|
||||
folderNomediaStatuses[path] = hasNoMedia
|
||||
}
|
||||
}.toMutableList() as ArrayList<String>
|
||||
|
|
Loading…
Reference in a new issue