From 05b5a4282e5ab588be6d55a2cbdffb5412cffac2 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 30 Nov 2018 23:04:48 +0100 Subject: [PATCH] try getting the mediastore last_modified field at extended details, if available --- .../pro/fragments/ViewPagerFragment.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/ViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/ViewPagerFragment.kt index 26e42fcc2..8c2545ff7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/ViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/ViewPagerFragment.kt @@ -1,5 +1,6 @@ package com.simplemobiletools.gallery.pro.fragments +import android.provider.MediaStore import android.view.MotionEvent import androidx.fragment.app.Fragment import com.simplemobiletools.commons.extensions.* @@ -56,7 +57,7 @@ abstract class ViewPagerFragment : Fragment() { } if (detailsFlag and EXT_LAST_MODIFIED != 0) { - file.lastModified().formatDate().let { if (it.isNotEmpty()) details.appendln(it) } + getFileLastModified(file).let { if (it.isNotEmpty()) details.appendln(it) } } if (detailsFlag and EXT_DATE_TAKEN != 0) { @@ -75,6 +76,23 @@ abstract class ViewPagerFragment : Fragment() { fun getPathToLoad(medium: Medium) = if (medium.path.startsWith(OTG_PATH)) medium.path.getOTGPublicPath(context!!) else medium.path + private fun getFileLastModified(file: File): String { + val projection = arrayOf(MediaStore.Images.Media.DATE_MODIFIED) + val uri = MediaStore.Files.getContentUri("external") + val selection = "${MediaStore.MediaColumns.DATA} = ?" + val selectionArgs = arrayOf(file.absolutePath) + val cursor = context!!.contentResolver.query(uri, projection, selection, selectionArgs, null) + cursor?.use { + return if (cursor.moveToFirst()) { + val dateModified = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L + dateModified.formatDate() + } else { + file.lastModified().formatDate() + } + } + return "" + } + protected fun handleEvent(event: MotionEvent) { when (event.actionMasked) { MotionEvent.ACTION_DOWN -> {