diff --git a/app/build.gradle b/app/build.gradle index 9eba648fd..770a85eb6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt index 8ba0ec26c..d68db8212 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index 224c6556c..230216da3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -149,8 +149,8 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList) { - 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) { @@ -240,7 +240,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList 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() 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) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt index 239deeb9b..5c4bfabd2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt @@ -370,7 +370,7 @@ fun Context.storeDirectoryItems(items: ArrayList) { fun Context.checkAppendingHidden(path: String, hidden: String, includedFolders: MutableSet): 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 + var filteredDirectories = directories.filter { it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden, this) } as ArrayList 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 callback(clone.distinctBy { it.path.getDistinctPath() } as ArrayList) - removeInvalidDBDirectories(filteredDirectories) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt index 2c0420b9a..1408d33fc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt @@ -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) = includedP fun String.isThisOrParentExcluded(excludedPaths: MutableSet) = excludedPaths.any { equals(it, true) } || excludedPaths.any { "$this/".startsWith("$it/", true) } -fun String.shouldFolderBeVisible(excludedPaths: MutableSet, includedPaths: MutableSet, showHidden: Boolean): Boolean { +fun String.shouldFolderBeVisible(excludedPaths: MutableSet, includedPaths: MutableSet, showHidden: Boolean, context: Context): Boolean { if (isEmpty()) { return false } @@ -35,7 +36,7 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet, 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, 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 { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt index 1e42aa243..ed11d0fe2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt @@ -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 + folders.filter { it.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden, context) }.toMutableList() as ArrayList } 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 }