Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 120b1c18 authored by tibbi's avatar tibbi
Browse files

add another helper function for getting latest media id by date taken

parent 6929b050
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ buildscript {
        propMinSdkVersion = 16
        propTargetSdkVersion = propCompileSdkVersion
        propVersionCode = 1
        propVersionName = '3.16.1'
        propVersionName = '3.16.2'
        kotlin_version = '1.2.30'
        support_libs = '27.1.0'
    }
+16 −0
Original line number Diff line number Diff line
@@ -109,6 +109,22 @@ fun Context.getLatestMediaId(uri: Uri = MediaStore.Files.getContentUri("external
    return 0
}

fun Context.getLatestMediaByDateId(uri: Uri = MediaStore.Files.getContentUri("external")): Long {
    val projection = arrayOf(BaseColumns._ID)
    val sortOrder = "${MediaStore.Images.ImageColumns.DATE_TAKEN} DESC"
    var cursor: Cursor? = null
    try {
        cursor = contentResolver.query(uri, projection, null, null, sortOrder)
        if (cursor?.moveToFirst() == true) {
            return cursor.getLongValue(BaseColumns._ID)
        }
    } finally {
        cursor?.close()
    }
    return 0
}


// some helper functions were taken from https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java
@SuppressLint("NewApi")
fun Context.getRealPathFromURI(uri: Uri): String? {