From d2b77b37268fc0038a9a1ec3bc8ba37aad8508b6 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 28 Feb 2015 12:15:13 +0200 Subject: [PATCH] Fix date --- .../net/osmand/plus/helpers/GpxUiHelper.java | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index becab0ced1..928d2bc08d 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -4,7 +4,9 @@ import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; import net.osmand.CallbackWithObject; import net.osmand.IndexConstants; @@ -356,10 +358,33 @@ public class GpxUiHelper { } return dlg; } + + public static List getSortedGPXFilenamesByDate(File dir) { + final Map mp = new HashMap(); + readGpxDirectory(dir, mp, ""); + ArrayList list = new ArrayList(mp.keySet()); + Collections.sort(list, new Comparator() { + @Override + public int compare(String object1, String object2) { + Long l1 = mp.get(object1); + Long l2 = mp.get(object2); + if(l2 == null) { + l2 = 0l; + } + if(l1== null) { + l1 = 0l; + } + return l1 < l2 ? 1 : (l1 == l2 ? 0 : -1); + } + }); + return list; + } + - private static List getSortedGPXFilenames(File dir,String sub) { - final List list = new ArrayList(); - readGpxDirectory(dir, list, ""); + public static List getSortedGPXFilenames(File dir) { + final Map mp = new HashMap(); + readGpxDirectory(dir, mp, ""); + ArrayList list = new ArrayList(mp.keySet()); Collections.sort(list, new Comparator() { @Override public int compare(String object1, String object2) { @@ -375,23 +400,20 @@ public class GpxUiHelper { return list; } - private static void readGpxDirectory(File dir, final List list, String parent) { + private static void readGpxDirectory(File dir, final Map map, String parent) { if (dir != null && dir.canRead()) { File[] files = dir.listFiles(); if (files != null) { for (File f : files) { if (f.getName().toLowerCase().endsWith(".gpx")) { //$NON-NLS-1$ - list.add(parent + f.getName()); + map.put(parent + f.getName(), f.lastModified()); } else if (f.isDirectory()) { - readGpxDirectory(f, list, parent + f.getName() + "/"); + readGpxDirectory(f, map, parent + f.getName() + "/"); } } } } } - public static List getSortedGPXFilenames(File dir) { - return getSortedGPXFilenames(dir, null); - } private static void loadGPXFileInDifferentThread(final Activity activity, final CallbackWithObject callbackWithObject, final File dir, final GPXFile currentFile, final String... filename) {