moving the LastModified fetching from MediaStore into context extension

This commit is contained in:
tibbi 2020-05-06 11:48:24 +02:00
parent 8760213138
commit acb362ee2f
3 changed files with 26 additions and 24 deletions

View file

@ -7,7 +7,7 @@ buildscript {
propMinSdkVersion = 21
propTargetSdkVersion = propCompileSdkVersion
propVersionCode = 1
propVersionName = '5.27.7'
propVersionName = '5.27.8'
kotlin_version = '1.3.72'
}

View file

@ -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) {

View file

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