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
}
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()