From 969f0334f3cbe93a0b64c1a85367157f3a8c4b68 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 8 May 2022 09:33:56 +0200 Subject: [PATCH] check noMedia file existence only below Android 11 in some cases --- .../gallery/pro/extensions/Context.kt | 6 ------ .../gallery/pro/extensions/String.kt | 15 ++++++++++----- 2 files changed, 10 insertions(+), 11 deletions(-) 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 d3f8aeb26..bc9be9e52 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 @@ -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 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 2a4f646c6..ec0703087 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 @@ -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) = includedPaths.any { equals(it, true) } || includedPaths.any { "$this/".startsWith("$it/", true) } +fun String.isThisOrParentIncluded(includedPaths: MutableSet) = + includedPaths.any { equals(it, true) } || includedPaths.any { "$this/".startsWith("$it/", true) } -fun String.isThisOrParentExcluded(excludedPaths: MutableSet) = excludedPaths.any { equals(it, true) } || excludedPaths.any { "$this/".startsWith("$it/", true) } +fun String.isThisOrParentExcluded(excludedPaths: MutableSet) = + 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, includedPaths: MutableSet, showHidden: Boolean, - folderNoMediaStatuses: HashMap, callback: (path: String, hasNoMedia: Boolean) -> Unit): Boolean { +fun String.shouldFolderBeVisible( + excludedPaths: MutableSet, includedPaths: MutableSet, showHidden: Boolean, + folderNoMediaStatuses: HashMap, callback: (path: String, hasNoMedia: Boolean) -> Unit +): Boolean { if (isEmpty()) { return false } @@ -36,7 +41,7 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet, 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) {