diff --git a/app/build.gradle b/app/build.gradle index d367229c7..83e982e47 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,7 +46,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.14.7' + implementation 'com.simplemobiletools:commons:3.14.12' implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0' implementation 'com.android.support:multidex:1.0.3' implementation 'com.google.code.gson:gson:2.8.2' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt index 248881172..1be5ed7d8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -11,6 +11,7 @@ import android.provider.MediaStore import android.view.WindowManager import com.simplemobiletools.commons.extensions.getStringValue import com.simplemobiletools.commons.extensions.humanizePath +import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.gallery.activities.SettingsActivity import com.simplemobiletools.gallery.helpers.Config import com.simplemobiletools.gallery.helpers.NOMEDIA @@ -110,3 +111,20 @@ fun Context.getNoMediaFolders(callback: (folders: ArrayList) -> Unit) { callback(folders) }.start() } + +fun Context.isPathInMediaStore(path: String): Boolean { + if (path.startsWith(OTG_PATH)) { + return false + } + + val projection = arrayOf(MediaStore.Images.Media.DATE_MODIFIED) + val uri = MediaStore.Files.getContentUri("external") + val selection = "${MediaStore.MediaColumns.DATA} = ?" + val selectionArgs = arrayOf(path) + val cursor = contentResolver.query(uri, projection, selection, selectionArgs, null) + + cursor?.use { + return cursor.moveToFirst() + } + return false +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index d4016c36b..c4ae2a234 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -9,6 +9,7 @@ import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.containsNoMedia import com.simplemobiletools.gallery.extensions.doesParentHaveNoMedia +import com.simplemobiletools.gallery.extensions.isPathInMediaStore import com.simplemobiletools.gallery.models.Medium import java.io.File import java.util.LinkedHashMap @@ -64,7 +65,7 @@ class MediaFetcher(val context: Context) { files.forEach { val filePath = it.absolutePath if ((showHidden || !it.name.startsWith(".")) && !dirPaths.contains(filePath)) { - if (it.exists() && it.length() > 0 && it.isImageVideoGif()) { + if (it.exists() && it.length() > 0 && it.isImageVideoGif() && !context.isPathInMediaStore(it.absolutePath)) { newPaths.add(it.absolutePath) } }