check noMedia file existence only below Android 11 in some cases

This commit is contained in:
tibbi 2022-05-08 09:33:56 +02:00
parent 0b2f0da4be
commit 969f0334f3
2 changed files with 10 additions and 11 deletions

View file

@ -1,6 +1,5 @@
package com.simplemobiletools.gallery.pro.extensions
import android.app.Activity
import android.appwidget.AppWidgetManager
import android.content.ComponentName
import android.content.Context
@ -30,7 +29,6 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.views.MySquareImageView
import com.simplemobiletools.gallery.pro.R
import com.simplemobiletools.gallery.pro.activities.SettingsActivity
import com.simplemobiletools.gallery.pro.asynctasks.GetMediaAsynctask
import com.simplemobiletools.gallery.pro.databases.GalleryDatabase
import com.simplemobiletools.gallery.pro.helpers.*
@ -43,10 +41,6 @@ import java.io.File
import java.io.FileInputStream
import java.nio.ByteBuffer
import java.nio.channels.FileChannel
import java.util.*
import kotlin.Comparator
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.collections.set
val Context.audioManager get() = getSystemService(Context.AUDIO_SERVICE) as AudioManager

View file

@ -2,16 +2,21 @@ package com.simplemobiletools.gallery.pro.extensions
import android.os.Environment
import com.simplemobiletools.commons.helpers.NOMEDIA
import com.simplemobiletools.commons.helpers.isRPlus
import java.io.File
import java.io.IOException
fun String.isThisOrParentIncluded(includedPaths: MutableSet<String>) = includedPaths.any { equals(it, true) } || includedPaths.any { "$this/".startsWith("$it/", true) }
fun String.isThisOrParentIncluded(includedPaths: MutableSet<String>) =
includedPaths.any { equals(it, true) } || includedPaths.any { "$this/".startsWith("$it/", true) }
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) }
// 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 {
fun String.shouldFolderBeVisible(
excludedPaths: MutableSet<String>, includedPaths: MutableSet<String>, showHidden: Boolean,
folderNoMediaStatuses: HashMap<String, Boolean>, callback: (path: String, hasNoMedia: Boolean) -> Unit
): Boolean {
if (isEmpty()) {
return false
}
@ -36,7 +41,7 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet<String>, includedPath
val containsNoMedia = if (showHidden) {
false
} else {
folderNoMediaStatuses.getOrElse("$this/$NOMEDIA", { false }) || File(this, NOMEDIA).exists()
folderNoMediaStatuses.getOrElse("$this/$NOMEDIA", { false }) || (!isRPlus() && File(this, NOMEDIA).exists())
}
return if (!showHidden && containsNoMedia) {