speed up some folder visibility checks

This commit is contained in:
tibbi 2020-04-24 11:22:38 +02:00
parent 0a98fd0536
commit 26e96418b6
6 changed files with 17 additions and 17 deletions

View file

@ -78,7 +78,7 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:5.26.24'
implementation 'com.simplemobiletools:commons:5.26.25'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'it.sephiroth.android.exif:library:1.0.1'

View file

@ -221,7 +221,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_media, menu)
val isFolderHidden = mPath.containsNoMedia()
val isFolderHidden = mPath.containsNoMedia(this)
menu.apply {
findItem(R.id.group).isVisible = !config.scrollHorizontally

View file

@ -149,8 +149,8 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
}
private fun checkHideBtnVisibility(menu: Menu, selectedPaths: ArrayList<String>) {
menu.findItem(R.id.cab_hide).isVisible = selectedPaths.any { !it.doesThisOrParentHaveNoMedia() }
menu.findItem(R.id.cab_unhide).isVisible = selectedPaths.any { it.doesThisOrParentHaveNoMedia() }
menu.findItem(R.id.cab_hide).isVisible = selectedPaths.any { !it.doesThisOrParentHaveNoMedia(activity) }
menu.findItem(R.id.cab_unhide).isVisible = selectedPaths.any { it.doesThisOrParentHaveNoMedia(activity) }
}
private fun checkPinBtnVisibility(menu: Menu, selectedPaths: ArrayList<String>) {
@ -240,7 +240,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
val path = it
activity.handleLockedFolderOpening(path) { success ->
if (success) {
if (path.containsNoMedia()) {
if (path.containsNoMedia(activity)) {
activity.removeNoMedia(path) {
if (activity.config.shouldShowHidden) {
updateFolderNames()
@ -320,7 +320,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
val affectedPositions = ArrayList<Int>()
val includedFolders = activity.config.includedFolders
val newDirs = dirs.filterIndexed { index, directory ->
val removeDir = directory.path.doesThisOrParentHaveNoMedia() && !includedFolders.contains(directory.path)
val removeDir = directory.path.doesThisOrParentHaveNoMedia(activity) && !includedFolders.contains(directory.path)
if (removeDir) {
affectedPositions.add(index)
}

View file

@ -370,7 +370,7 @@ fun Context.storeDirectoryItems(items: ArrayList<Directory>) {
fun Context.checkAppendingHidden(path: String, hidden: String, includedFolders: MutableSet<String>): String {
val dirName = getFolderNameFromPath(path)
return if (path.doesThisOrParentHaveNoMedia() && !path.isThisOrParentIncluded(includedFolders)) {
return if (path.doesThisOrParentHaveNoMedia(this) && !path.isThisOrParentIncluded(includedFolders)) {
"$dirName $hidden"
} else {
dirName
@ -516,7 +516,7 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly:
val shouldShowHidden = config.shouldShowHidden || forceShowHidden
val excludedPaths = config.excludedFolders
val includedPaths = config.includedFolders
var filteredDirectories = directories.filter { it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden) } as ArrayList<Directory>
var filteredDirectories = directories.filter { it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden, this) } as ArrayList<Directory>
val filterMedia = config.filterMedia
filteredDirectories = (when {
@ -534,7 +534,7 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly:
val hiddenString = resources.getString(R.string.hidden)
filteredDirectories.forEach {
it.name = if (it.path.doesThisOrParentHaveNoMedia() && !it.path.isThisOrParentIncluded(includedPaths)) {
it.name = if (it.path.doesThisOrParentHaveNoMedia(this) && !it.path.isThisOrParentIncluded(includedPaths)) {
"${it.name.removeSuffix(hiddenString).trim()} $hiddenString"
} else {
it.name.removeSuffix(hiddenString).trim()
@ -543,7 +543,6 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly:
val clone = filteredDirectories.clone() as ArrayList<Directory>
callback(clone.distinctBy { it.path.getDistinctPath() } as ArrayList<Directory>)
removeInvalidDBDirectories(filteredDirectories)
}
}

View file

@ -1,9 +1,10 @@
package com.simplemobiletools.gallery.pro.extensions
import android.content.Context
import android.media.MediaMetadataRetriever
import android.os.Environment
import com.simplemobiletools.commons.extensions.doesThisOrParentHaveNoMedia
import com.simplemobiletools.commons.helpers.NOMEDIA
import com.simplemobiletools.commons.extensions.containsNoMedia
import com.simplemobiletools.commons.extensions.doesParentHaveNoMedia
import java.io.File
import java.io.IOException
@ -11,7 +12,7 @@ fun String.isThisOrParentIncluded(includedPaths: MutableSet<String>) = includedP
fun String.isThisOrParentExcluded(excludedPaths: MutableSet<String>) = excludedPaths.any { equals(it, true) } || excludedPaths.any { "$this/".startsWith("$it/", true) }
fun String.shouldFolderBeVisible(excludedPaths: MutableSet<String>, includedPaths: MutableSet<String>, showHidden: Boolean): Boolean {
fun String.shouldFolderBeVisible(excludedPaths: MutableSet<String>, includedPaths: MutableSet<String>, showHidden: Boolean, context: Context): Boolean {
if (isEmpty()) {
return false
}
@ -35,7 +36,7 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet<String>, includedPath
val containsNoMedia = if (showHidden) {
false
} else {
File(this, NOMEDIA).exists()
file.containsNoMedia(context)
}
return if (!showHidden && containsNoMedia) {
@ -49,7 +50,7 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet<String>, includedPath
} else if (!showHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) {
var containsNoMediaOrDot = containsNoMedia || contains("/.")
if (!containsNoMediaOrDot) {
containsNoMediaOrDot = file.doesThisOrParentHaveNoMedia()
containsNoMediaOrDot = file.doesParentHaveNoMedia(context)
}
!containsNoMediaOrDot
} else {

View file

@ -66,7 +66,7 @@ class MediaFetcher(val context: Context) {
val shouldShowHidden = config.shouldShowHidden
val excludedPaths = config.excludedFolders
val includedPaths = config.includedFolders
folders.filter { it.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden) }.toMutableList() as ArrayList<String>
folders.filter { it.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden, context) }.toMutableList() as ArrayList<String>
} catch (e: Exception) {
ArrayList()
}
@ -192,7 +192,7 @@ class MediaFetcher(val context: Context) {
val showHidden = config.shouldShowHidden
val excludedFolders = config.excludedFolders
foldersToScan = foldersToScan.filter { it.shouldFolderBeVisible(excludedFolders, includedFolders, showHidden) }.toHashSet()
foldersToScan = foldersToScan.filter { it.shouldFolderBeVisible(excludedFolders, includedFolders, showHidden, context) }.toHashSet()
return foldersToScan.distinctBy { it.getDistinctPath() }.toMutableSet() as LinkedHashSet<String>
}