speed up some folder visibility checks
This commit is contained in:
parent
0a98fd0536
commit
26e96418b6
|
@ -78,7 +78,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
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 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
|
||||||
implementation 'androidx.multidex:multidex:2.0.1'
|
implementation 'androidx.multidex:multidex:2.0.1'
|
||||||
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
||||||
|
|
|
@ -221,7 +221,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
menuInflater.inflate(R.menu.menu_media, menu)
|
menuInflater.inflate(R.menu.menu_media, menu)
|
||||||
|
|
||||||
val isFolderHidden = mPath.containsNoMedia()
|
val isFolderHidden = mPath.containsNoMedia(this)
|
||||||
menu.apply {
|
menu.apply {
|
||||||
findItem(R.id.group).isVisible = !config.scrollHorizontally
|
findItem(R.id.group).isVisible = !config.scrollHorizontally
|
||||||
|
|
||||||
|
|
|
@ -149,8 +149,8 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkHideBtnVisibility(menu: Menu, selectedPaths: ArrayList<String>) {
|
private fun checkHideBtnVisibility(menu: Menu, selectedPaths: ArrayList<String>) {
|
||||||
menu.findItem(R.id.cab_hide).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() }
|
menu.findItem(R.id.cab_unhide).isVisible = selectedPaths.any { it.doesThisOrParentHaveNoMedia(activity) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkPinBtnVisibility(menu: Menu, selectedPaths: ArrayList<String>) {
|
private fun checkPinBtnVisibility(menu: Menu, selectedPaths: ArrayList<String>) {
|
||||||
|
@ -240,7 +240,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
val path = it
|
val path = it
|
||||||
activity.handleLockedFolderOpening(path) { success ->
|
activity.handleLockedFolderOpening(path) { success ->
|
||||||
if (success) {
|
if (success) {
|
||||||
if (path.containsNoMedia()) {
|
if (path.containsNoMedia(activity)) {
|
||||||
activity.removeNoMedia(path) {
|
activity.removeNoMedia(path) {
|
||||||
if (activity.config.shouldShowHidden) {
|
if (activity.config.shouldShowHidden) {
|
||||||
updateFolderNames()
|
updateFolderNames()
|
||||||
|
@ -320,7 +320,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
val affectedPositions = ArrayList<Int>()
|
val affectedPositions = ArrayList<Int>()
|
||||||
val includedFolders = activity.config.includedFolders
|
val includedFolders = activity.config.includedFolders
|
||||||
val newDirs = dirs.filterIndexed { index, directory ->
|
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) {
|
if (removeDir) {
|
||||||
affectedPositions.add(index)
|
affectedPositions.add(index)
|
||||||
}
|
}
|
||||||
|
|
|
@ -370,7 +370,7 @@ fun Context.storeDirectoryItems(items: ArrayList<Directory>) {
|
||||||
|
|
||||||
fun Context.checkAppendingHidden(path: String, hidden: String, includedFolders: MutableSet<String>): String {
|
fun Context.checkAppendingHidden(path: String, hidden: String, includedFolders: MutableSet<String>): String {
|
||||||
val dirName = getFolderNameFromPath(path)
|
val dirName = getFolderNameFromPath(path)
|
||||||
return if (path.doesThisOrParentHaveNoMedia() && !path.isThisOrParentIncluded(includedFolders)) {
|
return if (path.doesThisOrParentHaveNoMedia(this) && !path.isThisOrParentIncluded(includedFolders)) {
|
||||||
"$dirName $hidden"
|
"$dirName $hidden"
|
||||||
} else {
|
} else {
|
||||||
dirName
|
dirName
|
||||||
|
@ -516,7 +516,7 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly:
|
||||||
val shouldShowHidden = config.shouldShowHidden || forceShowHidden
|
val shouldShowHidden = config.shouldShowHidden || forceShowHidden
|
||||||
val excludedPaths = config.excludedFolders
|
val excludedPaths = config.excludedFolders
|
||||||
val includedPaths = config.includedFolders
|
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
|
val filterMedia = config.filterMedia
|
||||||
|
|
||||||
filteredDirectories = (when {
|
filteredDirectories = (when {
|
||||||
|
@ -534,7 +534,7 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly:
|
||||||
|
|
||||||
val hiddenString = resources.getString(R.string.hidden)
|
val hiddenString = resources.getString(R.string.hidden)
|
||||||
filteredDirectories.forEach {
|
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"
|
"${it.name.removeSuffix(hiddenString).trim()} $hiddenString"
|
||||||
} else {
|
} else {
|
||||||
it.name.removeSuffix(hiddenString).trim()
|
it.name.removeSuffix(hiddenString).trim()
|
||||||
|
@ -543,7 +543,6 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly:
|
||||||
|
|
||||||
val clone = filteredDirectories.clone() as ArrayList<Directory>
|
val clone = filteredDirectories.clone() as ArrayList<Directory>
|
||||||
callback(clone.distinctBy { it.path.getDistinctPath() } as ArrayList<Directory>)
|
callback(clone.distinctBy { it.path.getDistinctPath() } as ArrayList<Directory>)
|
||||||
|
|
||||||
removeInvalidDBDirectories(filteredDirectories)
|
removeInvalidDBDirectories(filteredDirectories)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package com.simplemobiletools.gallery.pro.extensions
|
package com.simplemobiletools.gallery.pro.extensions
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.media.MediaMetadataRetriever
|
import android.media.MediaMetadataRetriever
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import com.simplemobiletools.commons.extensions.doesThisOrParentHaveNoMedia
|
import com.simplemobiletools.commons.extensions.containsNoMedia
|
||||||
import com.simplemobiletools.commons.helpers.NOMEDIA
|
import com.simplemobiletools.commons.extensions.doesParentHaveNoMedia
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
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.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()) {
|
if (isEmpty()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -35,7 +36,7 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet<String>, includedPath
|
||||||
val containsNoMedia = if (showHidden) {
|
val containsNoMedia = if (showHidden) {
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
File(this, NOMEDIA).exists()
|
file.containsNoMedia(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (!showHidden && containsNoMedia) {
|
return if (!showHidden && containsNoMedia) {
|
||||||
|
@ -49,7 +50,7 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet<String>, includedPath
|
||||||
} else if (!showHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) {
|
} else if (!showHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) {
|
||||||
var containsNoMediaOrDot = containsNoMedia || contains("/.")
|
var containsNoMediaOrDot = containsNoMedia || contains("/.")
|
||||||
if (!containsNoMediaOrDot) {
|
if (!containsNoMediaOrDot) {
|
||||||
containsNoMediaOrDot = file.doesThisOrParentHaveNoMedia()
|
containsNoMediaOrDot = file.doesParentHaveNoMedia(context)
|
||||||
}
|
}
|
||||||
!containsNoMediaOrDot
|
!containsNoMediaOrDot
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -66,7 +66,7 @@ class MediaFetcher(val context: Context) {
|
||||||
val shouldShowHidden = config.shouldShowHidden
|
val shouldShowHidden = config.shouldShowHidden
|
||||||
val excludedPaths = config.excludedFolders
|
val excludedPaths = config.excludedFolders
|
||||||
val includedPaths = config.includedFolders
|
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) {
|
} catch (e: Exception) {
|
||||||
ArrayList()
|
ArrayList()
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ class MediaFetcher(val context: Context) {
|
||||||
|
|
||||||
val showHidden = config.shouldShowHidden
|
val showHidden = config.shouldShowHidden
|
||||||
val excludedFolders = config.excludedFolders
|
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>
|
return foldersToScan.distinctBy { it.getDistinctPath() }.toMutableSet() as LinkedHashSet<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue