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 e221ee87f..5fee49423 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 @@ -1045,3 +1045,18 @@ fun Context.getFileDateTaken(path: String): Long { return 0L } + +fun Context.getFileUrisFromFileDirItems(fileDirItems: ArrayList): ArrayList { + val fileUris = ArrayList() + val allIds = MediaFetcher(this).getMediaStoreIds() + val filePaths = fileDirItems.map { it.path.lowercase(Locale.getDefault()) } + for ((filePath, mediaStoreId) in allIds) { + if (filePaths.contains(filePath.lowercase(Locale.getDefault()))) { + val baseUri = getFileUri(filePath) + val uri = ContentUris.withAppendedId(baseUri, mediaStoreId) + fileUris.add(uri) + } + } + + return fileUris +} 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 9ab822705..8eccf1215 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 @@ -606,6 +606,32 @@ class MediaFetcher(val context: Context) { return sizes } + fun getMediaStoreIds(): HashMap { + val ids = HashMap() + val projection = arrayOf( + Images.Media.DATA, + Images.Media._ID + ) + + val uri = Files.getContentUri("external") + + try { + context.queryCursor(uri, projection) { cursor -> + try { + val id = cursor.getLongValue(Images.Media._ID) + if (id != 0L) { + val path = cursor.getStringValue(Images.Media.DATA) + ids[path] = id + } + } catch (e: Exception) { + } + } + } catch (e: Exception) { + } + + return ids + } + fun sortMedia(media: ArrayList, sorting: Int) { if (sorting and SORT_BY_RANDOM != 0) { media.shuffle()