add timestamp to media

This commit is contained in:
tibbi 2016-06-18 12:59:04 +02:00
parent 2fb8fc2dc7
commit b47e13c4b5
5 changed files with 16 additions and 7 deletions

View file

@ -124,19 +124,21 @@ public class MediaActivity extends AppCompatActivity
} }
final String where = MediaStore.Images.Media.DATA + " like ? "; final String where = MediaStore.Images.Media.DATA + " like ? ";
final String[] args = new String[]{path + "%"}; 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 String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC";
final Cursor cursor = getContentResolver().query(uri, columns, where, args, order); final Cursor cursor = getContentResolver().query(uri, columns, where, args, order);
final String pattern = Pattern.quote(path) + "/[^/]*"; final String pattern = Pattern.quote(path) + "/[^/]*";
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA); final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
final int dateIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN);
do { do {
final String curPath = cursor.getString(pathIndex); final String curPath = cursor.getString(pathIndex);
if (curPath.matches(pattern) && !toBeDeleted.contains(curPath)) { if (curPath.matches(pattern) && !toBeDeleted.contains(curPath)) {
final File file = new File(curPath); final File file = new File(curPath);
if (file.exists()) { 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 { } else {
invalidFiles.add(file.getAbsolutePath()); invalidFiles.add(file.getAbsolutePath());
} }

View file

@ -34,7 +34,7 @@ public class PhotoActivity extends AppCompatActivity implements ViewPagerFragmen
hideSystemUI(); hideSystemUI();
final Bundle bundle = new Bundle(); 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); bundle.putSerializable(Constants.MEDIUM, medium);
final ViewPagerFragment fragment = new PhotoFragment(); final ViewPagerFragment fragment = new PhotoFragment();
fragment.setListener(this); fragment.setListener(this);

View file

@ -34,7 +34,7 @@ public class VideoActivity extends AppCompatActivity implements ViewPagerFragmen
hideSystemUI(); hideSystemUI();
final Bundle bundle = new Bundle(); 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); bundle.putSerializable(Constants.MEDIUM, medium);
final ViewPagerFragment fragment = new VideoFragment(); final ViewPagerFragment fragment = new VideoFragment();
fragment.setListener(this); fragment.setListener(this);

View file

@ -229,7 +229,7 @@ public class ViewPagerActivity extends AppCompatActivity
if (file.renameTo(newFile)) { if (file.renameTo(newFile)) {
final int currItem = pager.getCurrentItem(); 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()}; final String[] changedFiles = {file.getAbsolutePath(), newFile.getAbsolutePath()};
MediaScannerConnection.scanFile(getApplicationContext(), changedFiles, null, null); MediaScannerConnection.scanFile(getApplicationContext(), changedFiles, null, null);
@ -288,7 +288,7 @@ public class ViewPagerActivity extends AppCompatActivity
do { do {
final String curPath = cursor.getString(pathIndex); final String curPath = cursor.getString(pathIndex);
if (curPath.matches(pattern) && !curPath.equals(toBeDeleted) && !curPath.equals(beingDeleted)) { 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)) { if (curPath.equals(path)) {
pos = j; pos = j;

View file

@ -6,10 +6,12 @@ public class Medium implements Serializable {
private static final long serialVersionUID = -6543139465975455L; private static final long serialVersionUID = -6543139465975455L;
private final String path; private final String path;
private final boolean isVideo; 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.path = path;
this.isVideo = isVideo; this.isVideo = isVideo;
this.timestamp = timestamp;
} }
public String getPath() { public String getPath() {
@ -20,10 +22,15 @@ public class Medium implements Serializable {
return isVideo; return isVideo;
} }
public int getTimestamp() {
return timestamp;
}
@Override @Override
public String toString() { public String toString() {
return "Medium {" + return "Medium {" +
"isVideo=" + getIsVideo() + "isVideo=" + getIsVideo() +
", timestamp=" + getTimestamp() +
", path=" + getPath() + "}"; ", path=" + getPath() + "}";
} }
} }