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 094879fac..c6dd1893c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -195,16 +195,15 @@ fun Context.getNoMediaFolders(): ArrayList { return folders } - fun Context.getLastMediaModified(): Int { + val max = "max" val uri = MediaStore.Files.getContentUri("external") - val projection = arrayOf(MediaStore.Images.Media._ID, MediaStore.Images.Media.DATE_MODIFIED) - val order = "${MediaStore.Images.Media.DATE_MODIFIED} DESC" + val projection = arrayOf(MediaStore.Images.Media._ID, "MAX(${MediaStore.Images.Media.DATE_MODIFIED}) AS $max") var cursor: Cursor? = null try { - cursor = contentResolver.query(uri, projection, null, null, order) + cursor = contentResolver.query(uri, projection, null, null, null) if (cursor?.moveToFirst() == true) { - return cursor.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) + return cursor.getIntValue(max) } } finally { cursor?.close()