optimize getting the last files modified timestamp

This commit is contained in:
tibbi 2017-05-25 23:37:16 +02:00
parent 448fa72017
commit 4a4a054314

View file

@ -195,16 +195,15 @@ fun Context.getNoMediaFolders(): ArrayList<String> {
return folders return folders
} }
fun Context.getLastMediaModified(): Int { fun Context.getLastMediaModified(): Int {
val max = "max"
val uri = MediaStore.Files.getContentUri("external") val uri = MediaStore.Files.getContentUri("external")
val projection = arrayOf(MediaStore.Images.Media._ID, MediaStore.Images.Media.DATE_MODIFIED) val projection = arrayOf(MediaStore.Images.Media._ID, "MAX(${MediaStore.Images.Media.DATE_MODIFIED}) AS $max")
val order = "${MediaStore.Images.Media.DATE_MODIFIED} DESC"
var cursor: Cursor? = null var cursor: Cursor? = null
try { try {
cursor = contentResolver.query(uri, projection, null, null, order) cursor = contentResolver.query(uri, projection, null, null, null)
if (cursor?.moveToFirst() == true) { if (cursor?.moveToFirst() == true) {
return cursor.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) return cursor.getIntValue(max)
} }
} finally { } finally {
cursor?.close() cursor?.close()