From b47e13c4b5cbe8f639cc435bd64871886f4b5cea Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 18 Jun 2016 12:59:04 +0200 Subject: [PATCH] add timestamp to media --- .../gallery/activities/MediaActivity.java | 6 ++++-- .../gallery/activities/PhotoActivity.java | 2 +- .../gallery/activities/VideoActivity.java | 2 +- .../gallery/activities/ViewPagerActivity.java | 4 ++-- .../com/simplemobiletools/gallery/models/Medium.java | 9 ++++++++- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java index ee2c9c842..10e2c012e 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java @@ -124,19 +124,21 @@ public class MediaActivity extends AppCompatActivity } final String where = MediaStore.Images.Media.DATA + " like ? "; final String[] args = new String[]{path + "%"}; - final String[] columns = {MediaStore.Images.Media.DATA}; + final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_TAKEN}; final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC"; final Cursor cursor = getContentResolver().query(uri, columns, where, args, order); final String pattern = Pattern.quote(path) + "/[^/]*"; if (cursor != null && cursor.moveToFirst()) { final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA); + final int dateIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN); do { final String curPath = cursor.getString(pathIndex); if (curPath.matches(pattern) && !toBeDeleted.contains(curPath)) { final File file = new File(curPath); if (file.exists()) { - myMedia.add(new Medium(curPath, (i == 1))); + final int timestamp = cursor.getInt(dateIndex); + myMedia.add(new Medium(curPath, (i == 1), timestamp)); } else { invalidFiles.add(file.getAbsolutePath()); } diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/PhotoActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/PhotoActivity.java index 31435c2cb..337d37f2c 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/PhotoActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/PhotoActivity.java @@ -34,7 +34,7 @@ public class PhotoActivity extends AppCompatActivity implements ViewPagerFragmen hideSystemUI(); final Bundle bundle = new Bundle(); - final Medium medium = new Medium(uri.toString(), false); + final Medium medium = new Medium(uri.toString(), false, 0); bundle.putSerializable(Constants.MEDIUM, medium); final ViewPagerFragment fragment = new PhotoFragment(); fragment.setListener(this); diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/VideoActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/VideoActivity.java index f1f53c02d..77b0d973f 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/VideoActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/VideoActivity.java @@ -34,7 +34,7 @@ public class VideoActivity extends AppCompatActivity implements ViewPagerFragmen hideSystemUI(); final Bundle bundle = new Bundle(); - final Medium medium = new Medium(uri.toString(), true); + final Medium medium = new Medium(uri.toString(), true, 0); bundle.putSerializable(Constants.MEDIUM, medium); final ViewPagerFragment fragment = new VideoFragment(); fragment.setListener(this); diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java index 41bdfc6b3..a539c2200 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java @@ -229,7 +229,7 @@ public class ViewPagerActivity extends AppCompatActivity if (file.renameTo(newFile)) { final int currItem = pager.getCurrentItem(); - media.set(currItem, new Medium(newFile.getAbsolutePath(), media.get(currItem).getIsVideo())); + media.set(currItem, new Medium(newFile.getAbsolutePath(), media.get(currItem).getIsVideo(), 0)); final String[] changedFiles = {file.getAbsolutePath(), newFile.getAbsolutePath()}; MediaScannerConnection.scanFile(getApplicationContext(), changedFiles, null, null); @@ -288,7 +288,7 @@ public class ViewPagerActivity extends AppCompatActivity do { final String curPath = cursor.getString(pathIndex); if (curPath.matches(pattern) && !curPath.equals(toBeDeleted) && !curPath.equals(beingDeleted)) { - myMedia.add(new Medium(curPath, i == 1)); + myMedia.add(new Medium(curPath, i == 1, 0)); if (curPath.equals(path)) { pos = j; diff --git a/app/src/main/java/com/simplemobiletools/gallery/models/Medium.java b/app/src/main/java/com/simplemobiletools/gallery/models/Medium.java index c2af0ed68..c0df8e026 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/models/Medium.java +++ b/app/src/main/java/com/simplemobiletools/gallery/models/Medium.java @@ -6,10 +6,12 @@ public class Medium implements Serializable { private static final long serialVersionUID = -6543139465975455L; private final String path; private final boolean isVideo; + private final int timestamp; - public Medium(String path, boolean isVideo) { + public Medium(String path, boolean isVideo, int timestamp) { this.path = path; this.isVideo = isVideo; + this.timestamp = timestamp; } public String getPath() { @@ -20,10 +22,15 @@ public class Medium implements Serializable { return isVideo; } + public int getTimestamp() { + return timestamp; + } + @Override public String toString() { return "Medium {" + "isVideo=" + getIsVideo() + + ", timestamp=" + getTimestamp() + ", path=" + getPath() + "}"; } }