lets make the parent nomedia check nicer
This commit is contained in:
parent
a70ac7c825
commit
c108e09ccf
3 changed files with 18 additions and 16 deletions
|
@ -8,7 +8,7 @@ import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.extensions.config
|
import com.simplemobiletools.gallery.extensions.config
|
||||||
import com.simplemobiletools.gallery.extensions.containsNoMedia
|
import com.simplemobiletools.gallery.extensions.doesParentHaveNoMedia
|
||||||
import com.simplemobiletools.gallery.extensions.sumByLong
|
import com.simplemobiletools.gallery.extensions.sumByLong
|
||||||
import com.simplemobiletools.gallery.helpers.MediaFetcher
|
import com.simplemobiletools.gallery.helpers.MediaFetcher
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
|
@ -62,7 +62,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (File(parentDir).containsNoMedia() || File(parentDir).parentFile?.containsNoMedia() == true || File(parentDir).parentFile?.parentFile?.containsNoMedia() == true) {
|
if (File(parentDir).doesParentHaveNoMedia()) {
|
||||||
dirName += " $hidden"
|
dirName += " $hidden"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,3 +4,17 @@ import com.simplemobiletools.gallery.helpers.NOMEDIA
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
fun File.containsNoMedia() = isDirectory && File(this, NOMEDIA).exists()
|
fun File.containsNoMedia() = isDirectory && File(this, NOMEDIA).exists()
|
||||||
|
|
||||||
|
fun File.doesParentHaveNoMedia(): Boolean {
|
||||||
|
var curFile = this
|
||||||
|
while (true) {
|
||||||
|
if (curFile.containsNoMedia()) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
curFile = curFile.parentFile
|
||||||
|
if (curFile.absolutePath == "/") {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import com.simplemobiletools.gallery.extensions.config
|
import com.simplemobiletools.gallery.extensions.config
|
||||||
import com.simplemobiletools.gallery.extensions.containsNoMedia
|
import com.simplemobiletools.gallery.extensions.containsNoMedia
|
||||||
|
import com.simplemobiletools.gallery.extensions.doesParentHaveNoMedia
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.LinkedHashMap
|
import java.util.LinkedHashMap
|
||||||
|
@ -244,7 +245,7 @@ class MediaFetcher(val context: Context) {
|
||||||
} else if (!showHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) {
|
} else if (!showHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) {
|
||||||
var containsNoMediaOrDot = file.containsNoMedia() || path.contains("/.")
|
var containsNoMediaOrDot = file.containsNoMedia() || path.contains("/.")
|
||||||
if (!containsNoMediaOrDot) {
|
if (!containsNoMediaOrDot) {
|
||||||
containsNoMediaOrDot = checkParentHasNoMedia(file.parentFile)
|
containsNoMediaOrDot = file.doesParentHaveNoMedia()
|
||||||
}
|
}
|
||||||
!containsNoMediaOrDot
|
!containsNoMediaOrDot
|
||||||
} else {
|
} else {
|
||||||
|
@ -252,19 +253,6 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkParentHasNoMedia(file: File): Boolean {
|
|
||||||
var curFile = file
|
|
||||||
while (true) {
|
|
||||||
if (curFile.containsNoMedia()) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
curFile = curFile.parentFile
|
|
||||||
if (curFile.absolutePath == "/")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isThisOrParentExcluded(path: String, excludedPaths: MutableSet<String>, includedPaths: MutableSet<String>) =
|
private fun isThisOrParentExcluded(path: String, excludedPaths: MutableSet<String>, includedPaths: MutableSet<String>) =
|
||||||
includedPaths.none { path.startsWith(it) } && excludedPaths.any { path.startsWith(it) }
|
includedPaths.none { path.startsWith(it) } && excludedPaths.any { path.startsWith(it) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue