Update order to initialize

This commit is contained in:
Victor Shcherb 2015-07-28 22:22:28 +02:00
parent 3eb12eefca
commit 55dc79e118
3 changed files with 42 additions and 32 deletions

View file

@ -44,41 +44,45 @@ public class Algorithms {
return def;
}
private static String simplifyName(String fn) {
String lc = fn.toLowerCase();
if (lc.indexOf(".") != -1) {
lc = lc.substring(0, lc.indexOf("."));
}
if (lc.endsWith("_2")) {
lc = lc.substring(0, lc.length() - "_2".length());
}
boolean hasTimestampEnd = false;
for(int i = 0; i < lc.length(); i++) {
if(lc.charAt(i) >= '0' && lc.charAt(i) <= '9') {
hasTimestampEnd = true;
break;
}
}
if(!hasTimestampEnd) {
lc += "_00_00_00";
}
return lc;
}
public static File[] getSortedFilesVersions(File dir){
File[] listFiles = dir.listFiles();
if (listFiles != null) {
Arrays.sort(listFiles, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return -simplifyName(o1.getName()).compareTo(simplifyName(o2.getName()));
}
});
Arrays.sort(listFiles, getFileVersionComparator());
}
return listFiles;
}
public static Comparator<File> getFileVersionComparator() {
return new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return -simplifyFileName(o1.getName()).compareTo(simplifyFileName(o2.getName()));
}
public String simplifyFileName(String fn) {
String lc = fn.toLowerCase();
if (lc.indexOf(".") != -1) {
lc = lc.substring(0, lc.indexOf("."));
}
if (lc.endsWith("_2")) {
lc = lc.substring(0, lc.length() - "_2".length());
}
boolean hasTimestampEnd = false;
for(int i = 0; i < lc.length(); i++) {
if(lc.charAt(i) >= '0' && lc.charAt(i) <= '9') {
hasTimestampEnd = true;
break;
}
}
if(!hasTimestampEnd) {
lc += "_00_00_00";
}
return lc;
}
};
}
private static final char CHAR_TOSPLIT = 0x01;

View file

@ -14,6 +14,7 @@ import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
@ -39,7 +40,6 @@ import net.osmand.data.QuadPointDouble;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.map.MapTileDownloader;
import net.osmand.map.MapTileDownloader.IMapDownloaderCallback;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
@ -75,7 +75,7 @@ public class MapRenderRepositories {
private final static int zoomOnlyForBasemaps = 11;
static int zoomForBaseRouteRendering = 14;
private Handler handler;
private Map<String, BinaryMapIndexReader> files = new ConcurrentHashMap<String, BinaryMapIndexReader>();
private Map<String, BinaryMapIndexReader> files = new LinkedHashMap<String, BinaryMapIndexReader>();
private Set<String> nativeFiles = new HashSet<String>();
private OsmandRenderer renderer;
@ -131,7 +131,9 @@ public class MapRenderRepositories {
closeConnection(files.get(file.getAbsolutePath()), file.getAbsolutePath());
}
files.put(file.getAbsolutePath(), reader);
LinkedHashMap<String, BinaryMapIndexReader> cpfiles = new LinkedHashMap<String, BinaryMapIndexReader>(files);
cpfiles.put(file.getAbsolutePath(), reader);
files = cpfiles;
}
public RotatedTileBox getBitmapLocation() {
@ -143,7 +145,9 @@ public class MapRenderRepositories {
}
protected void closeConnection(BinaryMapIndexReader c, String file) {
files.remove(file);
LinkedHashMap<String, BinaryMapIndexReader> cpfiles = new LinkedHashMap<String, BinaryMapIndexReader>(files);
cpfiles.remove(file);
files = cpfiles;
if(nativeFiles.contains(file)){
NativeOsmandLibrary lib = NativeOsmandLibrary.getLoadedLibrary();
if(lib != null) {

View file

@ -11,6 +11,7 @@ import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -601,6 +602,7 @@ public class ResourceManager {
if(OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) {
collectFiles(context.getAppPath(IndexConstants.SRTM_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
}
Collections.sort(files, Algorithms.getFileVersionComparator());
List<String> warnings = new ArrayList<String>();
renderer.clearAllResources();
CachedOsmandIndexes cachedOsmandIndexes = new CachedOsmandIndexes();