From 4a4a054314efbab89901acb5e0a431c3a0ff12d5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 25 May 2017 23:37:16 +0200 Subject: [PATCH] optimize getting the last files modified timestamp --- .../com/simplemobiletools/gallery/extensions/context.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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()