This commit is contained in:
Victor Shcherb 2015-02-28 12:15:13 +02:00
parent 4db2decaf4
commit d2b77b3726

View file

@ -4,7 +4,9 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
@ -357,9 +359,32 @@ public class GpxUiHelper {
return dlg; return dlg;
} }
private static List<String> getSortedGPXFilenames(File dir,String sub) { public static List<String> getSortedGPXFilenamesByDate(File dir) {
final List<String> list = new ArrayList<String>(); final Map<String, Long> mp = new HashMap<String, Long>();
readGpxDirectory(dir, list, ""); readGpxDirectory(dir, mp, "");
ArrayList<String> list = new ArrayList<String>(mp.keySet());
Collections.sort(list, new Comparator<String>() {
@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;
}
public static List<String> getSortedGPXFilenames(File dir) {
final Map<String, Long> mp = new HashMap<String, Long>();
readGpxDirectory(dir, mp, "");
ArrayList<String> list = new ArrayList<String>(mp.keySet());
Collections.sort(list, new Comparator<String>() { Collections.sort(list, new Comparator<String>() {
@Override @Override
public int compare(String object1, String object2) { public int compare(String object1, String object2) {
@ -375,23 +400,20 @@ public class GpxUiHelper {
return list; return list;
} }
private static void readGpxDirectory(File dir, final List<String> list, String parent) { private static void readGpxDirectory(File dir, final Map<String, Long> map, String parent) {
if (dir != null && dir.canRead()) { if (dir != null && dir.canRead()) {
File[] files = dir.listFiles(); File[] files = dir.listFiles();
if (files != null) { if (files != null) {
for (File f : files) { for (File f : files) {
if (f.getName().toLowerCase().endsWith(".gpx")) { //$NON-NLS-1$ 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()) { } else if (f.isDirectory()) {
readGpxDirectory(f, list, parent + f.getName() + "/"); readGpxDirectory(f, map, parent + f.getName() + "/");
} }
} }
} }
} }
} }
public static List<String> getSortedGPXFilenames(File dir) {
return getSortedGPXFilenames(dir, null);
}
private static void loadGPXFileInDifferentThread(final Activity activity, final CallbackWithObject<GPXFile[]> callbackWithObject, private static void loadGPXFileInDifferentThread(final Activity activity, final CallbackWithObject<GPXFile[]> callbackWithObject,
final File dir, final GPXFile currentFile, final String... filename) { final File dir, final GPXFile currentFile, final String... filename) {