From c2aea6b5fbedb34e7b62e4badb5391a07929226e Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 18 Jun 2016 13:22:54 +0200 Subject: [PATCH] sort media before displaying --- .../gallery/activities/MediaActivity.java | 3 +++ .../simplemobiletools/gallery/models/Medium.java | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) 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 10e2c012e..a5b8b17b6 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java @@ -30,6 +30,7 @@ import com.simplemobiletools.gallery.models.Medium; import java.io.File; import java.util.ArrayList; +import java.util.Collections; import java.util.List; 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()]); MediaScannerConnection.scanFile(getApplicationContext(), invalids, null, null); 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 c0df8e026..5b0b188f5 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/models/Medium.java +++ b/app/src/main/java/com/simplemobiletools/gallery/models/Medium.java @@ -2,7 +2,7 @@ package com.simplemobiletools.gallery.models; import java.io.Serializable; -public class Medium implements Serializable { +public class Medium implements Serializable, Comparable { private static final long serialVersionUID = -6543139465975455L; private final String path; private final boolean isVideo; @@ -26,6 +26,17 @@ public class Medium implements Serializable { 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 public String toString() { return "Medium {" +