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 095d8f348..e22a90243 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -89,8 +89,8 @@ fun Context.getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boo MediaStore.Images.Media.DATA, MediaStore.Images.Media.SIZE) val uri = MediaStore.Files.getContentUri("external") - val selection = if (curPath.isEmpty()) null else "(${MediaStore.Images.Media.DATA} LIKE ? AND ${MediaStore.Images.Media.DATA} NOT LIKE ?)" - val selectionArgs = if (curPath.isEmpty()) null else arrayOf("$curPath/%", "$curPath/%/%") + val selection = getSelectionQuery(curPath) + val selectionArgs = getSelectionArgsQuery(curPath) return try { val cur = contentResolver.query(uri, projection, selection, selectionArgs, getSortingForFolder(curPath)) @@ -100,6 +100,27 @@ fun Context.getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boo } } +fun Context.getSelectionQuery(path: String): String { + val dataQuery = "${MediaStore.Images.Media.DATA} LIKE ?" + return if (path.isEmpty()) { + var query = "($dataQuery)" + if (hasExternalSDCard()) { + query += " OR ($dataQuery)" + } + query + } else { + "($dataQuery AND ${MediaStore.Images.Media.DATA} NOT LIKE ?)" + } +} + +fun Context.getSelectionArgsQuery(path: String): Array { + return if (path.isEmpty()) { + if (hasExternalSDCard()) arrayOf("$internalStoragePath/%", "$sdCardPath/%") else arrayOf("$internalStoragePath/%") + } else { + arrayOf("$path/%", "$path/%/%") + } +} + private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isPickVideo: Boolean, curPath: String): ArrayList { val curMedia = ArrayList() val config = context.config