sort media before displaying

This commit is contained in:
tibbi 2016-06-18 13:22:54 +02:00
parent b47e13c4b5
commit c2aea6b5fb
2 changed files with 15 additions and 1 deletions

View file

@ -30,6 +30,7 @@ import com.simplemobiletools.gallery.models.Medium;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -148,6 +149,8 @@ public class MediaActivity extends AppCompatActivity
} }
} }
Collections.sort(myMedia);
final String[] invalids = invalidFiles.toArray(new String[invalidFiles.size()]); final String[] invalids = invalidFiles.toArray(new String[invalidFiles.size()]);
MediaScannerConnection.scanFile(getApplicationContext(), invalids, null, null); MediaScannerConnection.scanFile(getApplicationContext(), invalids, null, null);

View file

@ -2,7 +2,7 @@ package com.simplemobiletools.gallery.models;
import java.io.Serializable; import java.io.Serializable;
public class Medium implements Serializable { public class Medium implements Serializable, Comparable {
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;
@ -26,6 +26,17 @@ public class Medium implements Serializable {
return timestamp; return timestamp;
} }
@Override
public int compareTo(Object object) {
Medium medium = (Medium) object;
if (this.timestamp < medium.getTimestamp()) {
return 1;
} else if (this.timestamp > medium.getTimestamp()) {
return -1;
}
return 0;
}
@Override @Override
public String toString() { public String toString() {
return "Medium {" + return "Medium {" +