diff --git a/build.gradle b/build.gradle index 385c37ef5..a6166707e 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { propMinSdkVersion = 21 propTargetSdkVersion = propCompileSdkVersion propVersionCode = 1 - propVersionName = '5.27.7' + propVersionName = '5.27.8' kotlin_version = '1.3.72' } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt index 116a4223f..776d42bcd 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt @@ -815,6 +815,27 @@ fun Context.getAlbum(path: String): String? { } } +fun Context.getMediaStoreLastModified(path: String): Long { + val projection = arrayOf( + MediaColumns.DATE_MODIFIED + ) + + val uri = getFileUri(path) + val selection = "${BaseColumns._ID} = ?" + val selectionArgs = arrayOf(path.substringAfterLast("/")) + + try { + val cursor = contentResolver.query(uri, projection, selection, selectionArgs, null) + cursor?.use { + if (cursor.moveToFirst()) { + return cursor.getLongValue(MediaColumns.DATE_MODIFIED) * 1000 + } + } + } catch (ignored: Exception) { + } + return 0 +} + fun Context.getStringsPackageName() = getString(R.string.package_name) fun Context.getFontSizeText() = getString(when (baseConfig.fontSize) { diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/models/FileDirItem.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/models/FileDirItem.kt index 9d5debbb0..fdc0077ce 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/models/FileDirItem.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/models/FileDirItem.kt @@ -2,8 +2,6 @@ package com.simplemobiletools.commons.models import android.content.Context import android.net.Uri -import android.provider.BaseColumns -import android.provider.MediaStore import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* import java.io.File @@ -85,29 +83,12 @@ open class FileDirItem(val path: String, val name: String = "", var isDirectory: } fun getLastModified(context: Context): Long { - if (context.isPathOnOTG(path)) { - return context.getFastDocumentFile(path)?.lastModified() ?: 0L + return if (context.isPathOnOTG(path)) { + context.getFastDocumentFile(path)?.lastModified() ?: 0L } else if (isNougatPlus() && path.startsWith("content://")) { - val projection = arrayOf( - MediaStore.MediaColumns.DATE_MODIFIED - ) - - val uri = context.getFileUri(path) - val selection = "${BaseColumns._ID} = ?" - val selectionArgs = arrayOf(path.substringAfterLast("/")) - - try { - val cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null) - cursor?.use { - if (cursor.moveToFirst()) { - return cursor.getLongValue(MediaStore.MediaColumns.DATE_MODIFIED) * 1000 - } - } - } catch (ignored: Exception) { - } - return 0 + context.getMediaStoreLastModified(path) } else { - return File(path).lastModified() + File(path).lastModified() } }