From 8a24eeba8608b8fff56082356f7f3d3dac3525dd Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 5 Dec 2016 22:14:51 +0100 Subject: [PATCH] store the date_taken at media and directories --- .../gallery/activities/PhotoVideoActivity.kt | 2 +- .../gallery/asynctasks/GetDirectoriesAsynctask.kt | 7 ++++--- .../gallery/asynctasks/GetMediaAsynctask.kt | 8 +++++--- .../com/simplemobiletools/gallery/helpers/Constants.kt | 1 + .../com/simplemobiletools/gallery/models/Directory.kt | 6 ++++-- .../kotlin/com/simplemobiletools/gallery/models/Medium.kt | 4 ++-- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt index 69b011979..1e61763c7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -48,7 +48,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentClic val bundle = Bundle() val file = File(mUri.toString()) - mMedium = Medium(file.name, mUri.toString(), mIsVideo, 0, file.length()) + mMedium = Medium(file.name, mUri.toString(), mIsVideo, 0, 0, file.length()) bundle.putSerializable(MEDIUM, mMedium) if (savedInstanceState == null) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index 8080b0c94..96b8e14de 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -38,7 +38,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI } - val columns = arrayOf(MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_MODIFIED, MediaStore.Images.Media.SIZE) + val columns = arrayOf(MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_MODIFIED, MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.SIZE) val order = getSortOrder() var cursor: Cursor? = null @@ -69,8 +69,9 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va dirName += " ${context.resources.getString(R.string.hidden)}" } - val timestamp = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED) - directories.put(parentDir, Directory(parentDir, fullPath, dirName, 1, timestamp, size)) + val dateModified = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED) + val dateTaken = cursor.getLongValue(MediaStore.Images.Media.DATE_TAKEN) + directories.put(parentDir, Directory(parentDir, fullPath, dirName, 1, dateModified, dateTaken, size)) } } while (cursor.moveToNext()) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt index 80575533d..3e865e14f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -38,7 +38,8 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo } val where = "${MediaStore.Images.Media.DATA} LIKE ?" val args = arrayOf("$mPath%") - val columns = arrayOf(MediaStore.Images.Media.DATA, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATE_MODIFIED, MediaStore.Images.Media.SIZE) + val columns = arrayOf(MediaStore.Images.Media.DATA, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATE_MODIFIED, + MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.SIZE) var cursor: Cursor? = null try { @@ -62,8 +63,9 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo continue val name = cursor.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) - val timestamp = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED) - media.add(Medium(name, curPath, i == 1, timestamp, size)) + val dateModified = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED) + val dateTaken = cursor.getLongValue(MediaStore.Images.Media.DATE_TAKEN) + media.add(Medium(name, curPath, i == 1, dateModified, dateTaken, size)) } } while (cursor.moveToNext()) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 1dc4931d6..5ebb21ce4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -18,6 +18,7 @@ val PINNED_FOLDERS = "pinned_folders" val SORT_BY_NAME = 1 val SORT_BY_DATE_MODIFIED = 2 val SORT_BY_SIZE = 4 +val SORT_BY_DATE_TAKEN = 8 val SORT_DESCENDING = 1024 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt index 7a16a5fce..2b9c9d3d8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt @@ -4,7 +4,8 @@ import com.simplemobiletools.gallery.helpers.SORT_BY_DATE_MODIFIED import com.simplemobiletools.gallery.helpers.SORT_BY_NAME import com.simplemobiletools.gallery.helpers.SORT_DESCENDING -class Directory(val path: String, val thumbnail: String, val name: String, var mediaCnt: Int, val date_modified: Long, var size: Long) : Comparable { +class Directory(val path: String, val thumbnail: String, val name: String, var mediaCnt: Int, val date_modified: Long, val date_taken: Long, + var size: Long) : Comparable { companion object { var sorting: Int = 0 } @@ -39,5 +40,6 @@ class Directory(val path: String, val thumbnail: String, val name: String, var m return res } - override fun toString() = "Directory {path=$path, thumbnail=$thumbnail, name=$name, mediaCnt=$mediaCnt, date_modified=$date_modified, size $size}" + override fun toString() = "Directory {path=$path, thumbnail=$thumbnail, name=$name, mediaCnt=$mediaCnt, date_modified=$date_modified, " + + "date_taken=$date_taken, size $size}" } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt index a98d583b7..68e6111ab 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -5,7 +5,7 @@ import com.simplemobiletools.gallery.helpers.SORT_BY_NAME import com.simplemobiletools.gallery.helpers.SORT_DESCENDING import java.io.Serializable -class Medium(val name: String, var path: String, val isVideo: Boolean, val date_modified: Long, val size: Long) : Serializable, Comparable { +class Medium(val name: String, var path: String, val isVideo: Boolean, val date_modified: Long, val date_taken: Long, val size: Long) : Serializable, Comparable { companion object { private val serialVersionUID = -6553149466975455L var sorting: Int = 0 @@ -45,5 +45,5 @@ class Medium(val name: String, var path: String, val isVideo: Boolean, val date_ return res } - override fun toString() = "Medium {name=$name, path=$path, isVideo=$isVideo, date_modified=$date_modified, size=$size}" + override fun toString() = "Medium {name=$name, path=$path, isVideo=$isVideo, date_modified=$date_modified, date_taken=$date_taken, size=$size}" }