travel obf resource manager reader added
This commit is contained in:
parent
c949f98329
commit
16ae7b28c1
2 changed files with 132 additions and 112 deletions
|
@ -19,8 +19,10 @@ import net.osmand.IndexConstants;
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.ResultMatcher;
|
import net.osmand.ResultMatcher;
|
||||||
|
import net.osmand.binary.BinaryIndexPart;
|
||||||
import net.osmand.binary.BinaryMapIndexReader;
|
import net.osmand.binary.BinaryMapIndexReader;
|
||||||
import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter;
|
import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter;
|
||||||
|
import net.osmand.binary.BinaryMapPoiReaderAdapter;
|
||||||
import net.osmand.binary.CachedOsmandIndexes;
|
import net.osmand.binary.CachedOsmandIndexes;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
import net.osmand.data.RotatedTileBox;
|
import net.osmand.data.RotatedTileBox;
|
||||||
|
@ -75,15 +77,14 @@ import java.util.Map.Entry;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
|
||||||
import static net.osmand.IndexConstants.VOICE_INDEX_DIR;
|
import static net.osmand.IndexConstants.VOICE_INDEX_DIR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resource manager is responsible to work with all resources
|
* Resource manager is responsible to work with all resources
|
||||||
* that could consume memory (especially with file resources).
|
* that could consume memory (especially with file resources).
|
||||||
* Such as indexes, tiles.
|
* Such as indexes, tiles.
|
||||||
* Also it is responsible to create cache for that resources if they
|
* Also it is responsible to create cache for that resources if they
|
||||||
* can't be loaded fully into memory & clear them on request.
|
* can't be loaded fully into memory & clear them on request.
|
||||||
*/
|
*/
|
||||||
public class ResourceManager {
|
public class ResourceManager {
|
||||||
|
|
||||||
|
@ -91,10 +92,10 @@ public class ResourceManager {
|
||||||
private static final String INDEXES_CACHE = "ind.cache";
|
private static final String INDEXES_CACHE = "ind.cache";
|
||||||
|
|
||||||
private static final Log log = PlatformUtil.getLog(ResourceManager.class);
|
private static final Log log = PlatformUtil.getLog(ResourceManager.class);
|
||||||
|
|
||||||
protected static ResourceManager manager = null;
|
protected static ResourceManager manager = null;
|
||||||
|
|
||||||
protected File dirWithTiles ;
|
protected File dirWithTiles;
|
||||||
|
|
||||||
private List<TilesCache> tilesCacheList = new ArrayList<>();
|
private List<TilesCache> tilesCacheList = new ArrayList<>();
|
||||||
private BitmapTilesCache bitmapTilesCache;
|
private BitmapTilesCache bitmapTilesCache;
|
||||||
|
@ -115,21 +116,22 @@ public class ResourceManager {
|
||||||
STREET_LOOKUP,
|
STREET_LOOKUP,
|
||||||
TRANSPORT,
|
TRANSPORT,
|
||||||
ADDRESS,
|
ADDRESS,
|
||||||
QUICK_SEARCH,
|
QUICK_SEARCH,
|
||||||
ROUTING,
|
ROUTING,
|
||||||
TRANSPORT_ROUTING
|
TRANSPORT_ROUTING
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class BinaryMapReaderResource {
|
public static class BinaryMapReaderResource {
|
||||||
private BinaryMapIndexReader initialReader;
|
private BinaryMapIndexReader initialReader;
|
||||||
private File filename;
|
private File filename;
|
||||||
private List<BinaryMapIndexReader> readers = new ArrayList<>(BinaryMapReaderResourceType.values().length);
|
private List<BinaryMapIndexReader> readers = new ArrayList<>(BinaryMapReaderResourceType.values().length);
|
||||||
private boolean useForRouting;
|
private boolean useForRouting;
|
||||||
private boolean useForPublicTransport;
|
private boolean useForPublicTransport;
|
||||||
|
|
||||||
public BinaryMapReaderResource(File f, BinaryMapIndexReader initialReader) {
|
public BinaryMapReaderResource(File f, BinaryMapIndexReader initialReader) {
|
||||||
this.filename = f;
|
this.filename = f;
|
||||||
this.initialReader = initialReader;
|
this.initialReader = initialReader;
|
||||||
while(readers.size() < BinaryMapReaderResourceType.values().length) {
|
while (readers.size() < BinaryMapReaderResourceType.values().length) {
|
||||||
readers.add(null);
|
readers.add(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,7 +175,7 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
initialReader = null;
|
initialReader = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isClosed() {
|
public boolean isClosed() {
|
||||||
return initialReader == null;
|
return initialReader == null;
|
||||||
}
|
}
|
||||||
|
@ -189,7 +191,7 @@ public class ResourceManager {
|
||||||
public void setUseForRouting(boolean useForRouting) {
|
public void setUseForRouting(boolean useForRouting) {
|
||||||
this.useForRouting = useForRouting;
|
this.useForRouting = useForRouting;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUseForRouting() {
|
public boolean isUseForRouting() {
|
||||||
return useForRouting;
|
return useForRouting;
|
||||||
}
|
}
|
||||||
|
@ -202,34 +204,34 @@ public class ResourceManager {
|
||||||
this.useForPublicTransport = useForPublicTransport;
|
this.useForPublicTransport = useForPublicTransport;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final Map<String, BinaryMapReaderResource> fileReaders = new ConcurrentHashMap<String, BinaryMapReaderResource>();
|
protected final Map<String, BinaryMapReaderResource> fileReaders = new ConcurrentHashMap<String, BinaryMapReaderResource>();
|
||||||
|
|
||||||
|
|
||||||
private final Map<String, RegionAddressRepository> addressMap = new ConcurrentHashMap<String, RegionAddressRepository>();
|
private final Map<String, RegionAddressRepository> addressMap = new ConcurrentHashMap<String, RegionAddressRepository>();
|
||||||
protected final Map<String, AmenityIndexRepository> amenityRepositories = new ConcurrentHashMap<String, AmenityIndexRepository>();
|
protected final Map<String, AmenityIndexRepository> amenityRepositories = new ConcurrentHashMap<String, AmenityIndexRepository>();
|
||||||
// protected final Map<String, BinaryMapIndexReader> routingMapFiles = new ConcurrentHashMap<String, BinaryMapIndexReader>();
|
// protected final Map<String, BinaryMapIndexReader> routingMapFiles = new ConcurrentHashMap<String, BinaryMapIndexReader>();
|
||||||
protected final Map<String, BinaryMapReaderResource> transportRepositories = new ConcurrentHashMap<String, BinaryMapReaderResource>();
|
protected final Map<String, BinaryMapReaderResource> transportRepositories = new ConcurrentHashMap<String, BinaryMapReaderResource>();
|
||||||
|
|
||||||
protected final Map<String, String> indexFileNames = new ConcurrentHashMap<String, String>();
|
protected final Map<String, String> indexFileNames = new ConcurrentHashMap<String, String>();
|
||||||
protected final Map<String, String> basemapFileNames = new ConcurrentHashMap<String, String>();
|
protected final Map<String, String> basemapFileNames = new ConcurrentHashMap<String, String>();
|
||||||
|
|
||||||
|
|
||||||
protected final IncrementalChangesManager changesManager = new IncrementalChangesManager(this);
|
protected final IncrementalChangesManager changesManager = new IncrementalChangesManager(this);
|
||||||
|
|
||||||
protected final MapRenderRepositories renderer;
|
protected final MapRenderRepositories renderer;
|
||||||
|
|
||||||
protected final MapTileDownloader tileDownloader;
|
protected final MapTileDownloader tileDownloader;
|
||||||
|
|
||||||
public final AsyncLoadingThread asyncLoadingThread = new AsyncLoadingThread(this);
|
public final AsyncLoadingThread asyncLoadingThread = new AsyncLoadingThread(this);
|
||||||
|
|
||||||
private HandlerThread renderingBufferImageThread;
|
private HandlerThread renderingBufferImageThread;
|
||||||
|
|
||||||
protected boolean internetIsNotAccessible = false;
|
protected boolean internetIsNotAccessible = false;
|
||||||
private boolean depthContours;
|
private boolean depthContours;
|
||||||
|
|
||||||
public ResourceManager(OsmandApplication context) {
|
public ResourceManager(OsmandApplication context) {
|
||||||
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.renderer = new MapRenderRepositories(context);
|
this.renderer = new MapRenderRepositories(context);
|
||||||
|
|
||||||
|
@ -271,7 +273,7 @@ public class ResourceManager {
|
||||||
public MapTileDownloader getMapTileDownloader() {
|
public MapTileDownloader getMapTileDownloader() {
|
||||||
return tileDownloader;
|
return tileDownloader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HandlerThread getRenderingBufferImageThread() {
|
public HandlerThread getRenderingBufferImageThread() {
|
||||||
return renderingBufferImageThread;
|
return renderingBufferImageThread;
|
||||||
}
|
}
|
||||||
|
@ -293,17 +295,17 @@ public class ResourceManager {
|
||||||
// ".nomedia" indicates there are no pictures and no music to list in this dir for the Gallery app
|
// ".nomedia" indicates there are no pictures and no music to list in this dir for the Gallery app
|
||||||
try {
|
try {
|
||||||
context.getAppPath(".nomedia").createNewFile(); //$NON-NLS-1$
|
context.getAppPath(".nomedia").createNewFile(); //$NON-NLS-1$
|
||||||
} catch( Exception e ) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
for (TilesCache tilesCache : tilesCacheList) {
|
for (TilesCache tilesCache : tilesCacheList) {
|
||||||
tilesCache.setDirWithTiles(dirWithTiles);
|
tilesCache.setDirWithTiles(dirWithTiles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public java.text.DateFormat getDateFormat() {
|
public java.text.DateFormat getDateFormat() {
|
||||||
return DateFormat.getDateFormat(context);
|
return DateFormat.getDateFormat(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OsmandApplication getContext() {
|
public OsmandApplication getContext() {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
@ -323,7 +325,7 @@ public class ResourceManager {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void tileDownloaded(DownloadRequest request){
|
public synchronized void tileDownloaded(DownloadRequest request) {
|
||||||
if (request instanceof TileLoadDownloadRequest) {
|
if (request instanceof TileLoadDownloadRequest) {
|
||||||
TileLoadDownloadRequest req = ((TileLoadDownloadRequest) request);
|
TileLoadDownloadRequest req = ((TileLoadDownloadRequest) request);
|
||||||
TilesCache cache = getTilesCache(req.tileSource);
|
TilesCache cache = getTilesCache(req.tileSource);
|
||||||
|
@ -332,13 +334,13 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean tileExistOnFileSystem(String file, ITileSource map, int x, int y, int zoom) {
|
public synchronized boolean tileExistOnFileSystem(String file, ITileSource map, int x, int y, int zoom) {
|
||||||
TilesCache cache = getTilesCache(map);
|
TilesCache cache = getTilesCache(map);
|
||||||
return cache != null && cache.tileExistOnFileSystem(file, map, x, y, zoom);
|
return cache != null && cache.tileExistOnFileSystem(file, map, x, y, zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearTileForMap(String file, ITileSource map, int x, int y, int zoom){
|
public void clearTileForMap(String file, ITileSource map, int x, int y, int zoom) {
|
||||||
TilesCache cache = getTilesCache(map);
|
TilesCache cache = getTilesCache(map);
|
||||||
if (cache != null) {
|
if (cache != null) {
|
||||||
cache.getTileForMap(file, map, x, y, zoom, true, false, true, true);
|
cache.getTileForMap(file, map, x, y, zoom, true, false, true, true);
|
||||||
|
@ -376,7 +378,7 @@ public class ResourceManager {
|
||||||
|
|
||||||
////////////////////////////////////////////// Working with indexes ////////////////////////////////////////////////
|
////////////////////////////////////////////// Working with indexes ////////////////////////////////////////////////
|
||||||
|
|
||||||
public List<String> reloadIndexesOnStart(AppInitializer progress, List<String> warnings){
|
public List<String> reloadIndexesOnStart(AppInitializer progress, List<String> warnings) {
|
||||||
close();
|
close();
|
||||||
// check we have some assets to copy to sdcard
|
// check we have some assets to copy to sdcard
|
||||||
warnings.addAll(checkAssets(progress, false));
|
warnings.addAll(checkAssets(progress, false));
|
||||||
|
@ -429,7 +431,7 @@ public class ResourceManager {
|
||||||
return warnings;
|
return warnings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> indexFontFiles(IProgress progress){
|
public List<String> indexFontFiles(IProgress progress) {
|
||||||
File file = context.getAppPath(IndexConstants.FONT_INDEX_DIR);
|
File file = context.getAppPath(IndexConstants.FONT_INDEX_DIR);
|
||||||
file.mkdirs();
|
file.mkdirs();
|
||||||
List<String> warnings = new ArrayList<String>();
|
List<String> warnings = new ArrayList<String>();
|
||||||
|
@ -473,10 +475,10 @@ public class ResourceManager {
|
||||||
log.error("Error while loading tts files from assets", e);
|
log.error("Error while loading tts files from assets", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> checkAssets(IProgress progress, boolean forceUpdate) {
|
public List<String> checkAssets(IProgress progress, boolean forceUpdate) {
|
||||||
String fv = Version.getFullVersion(context);
|
String fv = Version.getFullVersion(context);
|
||||||
if(context.getAppInitializer().isAppVersionChanged()) {
|
if (context.getAppInitializer().isAppVersionChanged()) {
|
||||||
copyMissingJSAssets();
|
copyMissingJSAssets();
|
||||||
}
|
}
|
||||||
if (!fv.equalsIgnoreCase(context.getSettings().PREVIOUS_INSTALLED_VERSION.get()) || forceUpdate) {
|
if (!fv.equalsIgnoreCase(context.getSettings().PREVIOUS_INSTALLED_VERSION.get()) || forceUpdate) {
|
||||||
|
@ -509,7 +511,7 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyRegionsBoundaries() {
|
private void copyRegionsBoundaries() {
|
||||||
try {
|
try {
|
||||||
File file = context.getAppPath("regions.ocbf");
|
File file = context.getAppPath("regions.ocbf");
|
||||||
|
@ -522,7 +524,7 @@ public class ResourceManager {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyPoiTypes() {
|
private void copyPoiTypes() {
|
||||||
try {
|
try {
|
||||||
File file = context.getAppPath(IndexConstants.SETTINGS_DIR + "poi_types.xml");
|
File file = context.getAppPath(IndexConstants.SETTINGS_DIR + "poi_types.xml");
|
||||||
|
@ -540,6 +542,7 @@ public class ResourceManager {
|
||||||
private final static String ASSET_COPY_MODE__overwriteOnlyIfExists = "overwriteOnlyIfExists";
|
private final static String ASSET_COPY_MODE__overwriteOnlyIfExists = "overwriteOnlyIfExists";
|
||||||
private final static String ASSET_COPY_MODE__alwaysOverwriteOrCopy = "alwaysOverwriteOrCopy";
|
private final static String ASSET_COPY_MODE__alwaysOverwriteOrCopy = "alwaysOverwriteOrCopy";
|
||||||
private final static String ASSET_COPY_MODE__copyOnlyIfDoesNotExist = "copyOnlyIfDoesNotExist";
|
private final static String ASSET_COPY_MODE__copyOnlyIfDoesNotExist = "copyOnlyIfDoesNotExist";
|
||||||
|
|
||||||
private void unpackBundledAssets(AssetManager assetManager, File appDataDir, IProgress progress, boolean isFirstInstall) throws IOException, XmlPullParserException {
|
private void unpackBundledAssets(AssetManager assetManager, File appDataDir, IProgress progress, boolean isFirstInstall) throws IOException, XmlPullParserException {
|
||||||
List<AssetEntry> assetEntries = DownloadOsmandIndexesHelper.getBundledAssets(assetManager);
|
List<AssetEntry> assetEntries = DownloadOsmandIndexesHelper.getBundledAssets(assetManager);
|
||||||
for (AssetEntry asset : assetEntries) {
|
for (AssetEntry asset : assetEntries) {
|
||||||
|
@ -581,7 +584,7 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyAssets(AssetManager assetManager, String assetName, File file) throws IOException {
|
public static void copyAssets(AssetManager assetManager, String assetName, File file) throws IOException {
|
||||||
if(file.exists()){
|
if (file.exists()) {
|
||||||
Algorithms.removeAllFiles(file);
|
Algorithms.removeAllFiles(file);
|
||||||
}
|
}
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
|
@ -593,9 +596,9 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<File> collectFiles(File dir, String ext, List<File> files) {
|
private List<File> collectFiles(File dir, String ext, List<File> files) {
|
||||||
if(dir.exists() && dir.canRead()) {
|
if (dir.exists() && dir.canRead()) {
|
||||||
File[] lf = dir.listFiles();
|
File[] lf = dir.listFiles();
|
||||||
if(lf == null || lf.length == 0) {
|
if (lf == null || lf.length == 0) {
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
for (File f : lf) {
|
for (File f : lf) {
|
||||||
|
@ -606,12 +609,11 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void renameRoadsFiles(ArrayList<File> files, File roadsPath) {
|
private void renameRoadsFiles(ArrayList<File> files, File roadsPath) {
|
||||||
Iterator<File> it = files.iterator();
|
Iterator<File> it = files.iterator();
|
||||||
while(it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
File f = it.next();
|
File f = it.next();
|
||||||
if (f.getName().endsWith("-roads" + IndexConstants.BINARY_MAP_INDEX_EXT)) {
|
if (f.getName().endsWith("-roads" + IndexConstants.BINARY_MAP_INDEX_EXT)) {
|
||||||
f.renameTo(new File(roadsPath, f.getName().replace("-roads" + IndexConstants.BINARY_MAP_INDEX_EXT,
|
f.renameTo(new File(roadsPath, f.getName().replace("-roads" + IndexConstants.BINARY_MAP_INDEX_EXT,
|
||||||
|
@ -628,17 +630,18 @@ public class ResourceManager {
|
||||||
File appPath = context.getAppPath(null);
|
File appPath = context.getAppPath(null);
|
||||||
File roadsPath = context.getAppPath(IndexConstants.ROADS_INDEX_DIR);
|
File roadsPath = context.getAppPath(IndexConstants.ROADS_INDEX_DIR);
|
||||||
roadsPath.mkdirs();
|
roadsPath.mkdirs();
|
||||||
|
|
||||||
collectFiles(appPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
collectFiles(appPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||||
renameRoadsFiles(files, roadsPath);
|
renameRoadsFiles(files, roadsPath);
|
||||||
collectFiles(roadsPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
collectFiles(roadsPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||||
if (Version.isPaidVersion(context)) {
|
if (Version.isPaidVersion(context)) {
|
||||||
collectFiles(context.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
collectFiles(context.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||||
|
collectFiles(context.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||||
}
|
}
|
||||||
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isSubscribedToLiveUpdates(context)) {
|
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isSubscribedToLiveUpdates(context)) {
|
||||||
collectFiles(context.getAppPath(IndexConstants.SRTM_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
collectFiles(context.getAppPath(IndexConstants.SRTM_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||||
}
|
}
|
||||||
|
|
||||||
changesManager.collectChangesFiles(context.getAppPath(IndexConstants.LIVE_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
changesManager.collectChangesFiles(context.getAppPath(IndexConstants.LIVE_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||||
|
|
||||||
Collections.sort(files, Algorithms.getFileVersionComparator());
|
Collections.sort(files, Algorithms.getFileVersionComparator());
|
||||||
|
@ -707,9 +710,9 @@ public class ResourceManager {
|
||||||
if (dateCreated == 0) {
|
if (dateCreated == 0) {
|
||||||
dateCreated = f.lastModified();
|
dateCreated = f.lastModified();
|
||||||
}
|
}
|
||||||
if(f.getParentFile().getName().equals(liveDir.getName())) {
|
if (f.getParentFile().getName().equals(liveDir.getName())) {
|
||||||
boolean toUse = changesManager.index(f, dateCreated, mapReader);
|
boolean toUse = changesManager.index(f, dateCreated, mapReader);
|
||||||
if(!toUse) {
|
if (!toUse) {
|
||||||
try {
|
try {
|
||||||
mapReader.close();
|
mapReader.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -717,7 +720,7 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if(!wikiMap && !srtmMap) {
|
} else if (!wikiMap && !srtmMap) {
|
||||||
changesManager.indexMainMap(f, dateCreated);
|
changesManager.indexMainMap(f, dateCreated);
|
||||||
}
|
}
|
||||||
indexFileNames.put(f.getName(), dateFormat.format(dateCreated)); //$NON-NLS-1$
|
indexFileNames.put(f.getName(), dateFormat.format(dateCreated)); //$NON-NLS-1$
|
||||||
|
@ -726,7 +729,7 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
renderer.initializeNewResource(progress, f, mapReader);
|
renderer.initializeNewResource(progress, f, mapReader);
|
||||||
BinaryMapReaderResource resource = new BinaryMapReaderResource(f, mapReader);
|
BinaryMapReaderResource resource = new BinaryMapReaderResource(f, mapReader);
|
||||||
|
|
||||||
fileReaders.put(f.getName(), resource);
|
fileReaders.put(f.getName(), resource);
|
||||||
if (!mapReader.getRegionNames().isEmpty()) {
|
if (!mapReader.getRegionNames().isEmpty()) {
|
||||||
RegionAddressRepositoryBinary rarb = new RegionAddressRepositoryBinary(this, resource);
|
RegionAddressRepositoryBinary rarb = new RegionAddressRepositoryBinary(this, resource);
|
||||||
|
@ -736,7 +739,7 @@ public class ResourceManager {
|
||||||
transportRepositories.put(f.getName(), resource);
|
transportRepositories.put(f.getName(), resource);
|
||||||
}
|
}
|
||||||
// disable osmc for routing temporarily due to some bugs
|
// disable osmc for routing temporarily due to some bugs
|
||||||
if (mapReader.containsRouteData() && (!f.getParentFile().equals(liveDir) ||
|
if (mapReader.containsRouteData() && (!f.getParentFile().equals(liveDir) ||
|
||||||
context.getSettings().USE_OSM_LIVE_FOR_ROUTING.get())) {
|
context.getSettings().USE_OSM_LIVE_FOR_ROUTING.get())) {
|
||||||
resource.setUseForRouting(true);
|
resource.setUseForRouting(true);
|
||||||
}
|
}
|
||||||
|
@ -779,7 +782,7 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Iterator<Entry<PoiCategory, Map<String, PoiType>>> it = toAddPoiTypes.entrySet().iterator();
|
Iterator<Entry<PoiCategory, Map<String, PoiType>>> it = toAddPoiTypes.entrySet().iterator();
|
||||||
while(it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Entry<PoiCategory, Map<String, PoiType>> next = it.next();
|
Entry<PoiCategory, Map<String, PoiType>> next = it.next();
|
||||||
PoiCategory category = next.getKey();
|
PoiCategory category = next.getKey();
|
||||||
category.addExtraPoiTypes(next.getValue());
|
category.addExtraPoiTypes(next.getValue());
|
||||||
|
@ -798,7 +801,6 @@ public class ResourceManager {
|
||||||
return warnings;
|
return warnings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void initMapBoundariesCacheNative() {
|
public void initMapBoundariesCacheNative() {
|
||||||
File indCache = context.getAppPath(INDEXES_CACHE);
|
File indCache = context.getAppPath(INDEXES_CACHE);
|
||||||
|
@ -809,7 +811,7 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////// Working with amenities ////////////////////////////////////////////////
|
////////////////////////////////////////////// Working with amenities ////////////////////////////////////////////////
|
||||||
|
|
||||||
public List<AmenityIndexRepository> getAmenityRepositories() {
|
public List<AmenityIndexRepository> getAmenityRepositories() {
|
||||||
|
@ -826,7 +828,7 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Amenity> searchAmenities(SearchPoiTypeFilter filter,
|
public List<Amenity> searchAmenities(SearchPoiTypeFilter filter,
|
||||||
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, final ResultMatcher<Amenity> matcher) {
|
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, final ResultMatcher<Amenity> matcher) {
|
||||||
final List<Amenity> amenities = new ArrayList<Amenity>();
|
final List<Amenity> amenities = new ArrayList<Amenity>();
|
||||||
searchAmenitiesInProgress = true;
|
searchAmenitiesInProgress = true;
|
||||||
try {
|
try {
|
||||||
|
@ -855,8 +857,8 @@ public class ResourceManager {
|
||||||
return amenities;
|
return amenities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Amenity> searchAmenitiesOnThePath(List<Location> locations, double radius, SearchPoiTypeFilter filter,
|
public List<Amenity> searchAmenitiesOnThePath(List<Location> locations, double radius, SearchPoiTypeFilter filter,
|
||||||
ResultMatcher<Amenity> matcher) {
|
ResultMatcher<Amenity> matcher) {
|
||||||
searchAmenitiesInProgress = true;
|
searchAmenitiesInProgress = true;
|
||||||
final List<Amenity> amenities = new ArrayList<Amenity>();
|
final List<Amenity> amenities = new ArrayList<Amenity>();
|
||||||
try {
|
try {
|
||||||
|
@ -875,9 +877,9 @@ public class ResourceManager {
|
||||||
if (!filter.isEmpty()) {
|
if (!filter.isEmpty()) {
|
||||||
for (AmenityIndexRepository index : getAmenityRepositories()) {
|
for (AmenityIndexRepository index : getAmenityRepositories()) {
|
||||||
if (index.checkContainsInt(
|
if (index.checkContainsInt(
|
||||||
MapUtils.get31TileNumberY(topLatitude),
|
MapUtils.get31TileNumberY(topLatitude),
|
||||||
MapUtils.get31TileNumberX(leftLongitude),
|
MapUtils.get31TileNumberX(leftLongitude),
|
||||||
MapUtils.get31TileNumberY(bottomLatitude),
|
MapUtils.get31TileNumberY(bottomLatitude),
|
||||||
MapUtils.get31TileNumberX(rightLongitude))) {
|
MapUtils.get31TileNumberX(rightLongitude))) {
|
||||||
repos.add(index);
|
repos.add(index);
|
||||||
}
|
}
|
||||||
|
@ -885,7 +887,7 @@ public class ResourceManager {
|
||||||
if (!repos.isEmpty()) {
|
if (!repos.isEmpty()) {
|
||||||
for (AmenityIndexRepository r : repos) {
|
for (AmenityIndexRepository r : repos) {
|
||||||
List<Amenity> res = r.searchAmenitiesOnThePath(locations, radius, filter, matcher);
|
List<Amenity> res = r.searchAmenitiesOnThePath(locations, radius, filter, matcher);
|
||||||
if(res != null) {
|
if (res != null) {
|
||||||
amenities.addAll(res);
|
amenities.addAll(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -897,12 +899,12 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
return amenities;
|
return amenities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean containsAmenityRepositoryToSearch(boolean searchByName){
|
public boolean containsAmenityRepositoryToSearch(boolean searchByName) {
|
||||||
for (AmenityIndexRepository index : getAmenityRepositories()) {
|
for (AmenityIndexRepository index : getAmenityRepositories()) {
|
||||||
if(searchByName){
|
if (searchByName) {
|
||||||
if(index instanceof AmenityIndexRepositoryBinary){
|
if (index instanceof AmenityIndexRepositoryBinary) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -911,10 +913,10 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Amenity> searchAmenitiesByName(String searchQuery,
|
public List<Amenity> searchAmenitiesByName(String searchQuery,
|
||||||
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude,
|
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude,
|
||||||
double lat, double lon, ResultMatcher<Amenity> matcher) {
|
double lat, double lon, ResultMatcher<Amenity> matcher) {
|
||||||
List<Amenity> amenities = new ArrayList<Amenity>();
|
List<Amenity> amenities = new ArrayList<Amenity>();
|
||||||
List<AmenityIndexRepositoryBinary> list = new ArrayList<AmenityIndexRepositoryBinary>();
|
List<AmenityIndexRepositoryBinary> list = new ArrayList<AmenityIndexRepositoryBinary>();
|
||||||
int left = MapUtils.get31TileNumberX(leftLongitude);
|
int left = MapUtils.get31TileNumberX(leftLongitude);
|
||||||
|
@ -927,16 +929,16 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
if (index instanceof AmenityIndexRepositoryBinary) {
|
if (index instanceof AmenityIndexRepositoryBinary) {
|
||||||
if (index.checkContainsInt(top, left, bottom, right)) {
|
if (index.checkContainsInt(top, left, bottom, right)) {
|
||||||
if(index.checkContains(lat, lon)){
|
if (index.checkContains(lat, lon)) {
|
||||||
list.add(0, (AmenityIndexRepositoryBinary) index);
|
list.add(0, (AmenityIndexRepositoryBinary) index);
|
||||||
} else {
|
} else {
|
||||||
list.add((AmenityIndexRepositoryBinary) index);
|
list.add((AmenityIndexRepositoryBinary) index);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not using boundares results in very slow initial search if user has many maps installed
|
// Not using boundares results in very slow initial search if user has many maps installed
|
||||||
// int left = 0;
|
// int left = 0;
|
||||||
// int top = 0;
|
// int top = 0;
|
||||||
|
@ -954,7 +956,7 @@ public class ResourceManager {
|
||||||
|
|
||||||
return amenities;
|
return amenities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<PoiCategory, List<String>> searchAmenityCategoriesByName(String searchQuery, double lat, double lon) {
|
public Map<PoiCategory, List<String>> searchAmenityCategoriesByName(String searchQuery, double lat, double lon) {
|
||||||
Map<PoiCategory, List<String>> map = new LinkedHashMap<PoiCategory, List<String>>();
|
Map<PoiCategory, List<String>> map = new LinkedHashMap<PoiCategory, List<String>>();
|
||||||
for (AmenityIndexRepository index : getAmenityRepositories()) {
|
for (AmenityIndexRepository index : getAmenityRepositories()) {
|
||||||
|
@ -970,17 +972,17 @@ public class ResourceManager {
|
||||||
public AmenityIndexRepositoryBinary getAmenityRepositoryByFileName(String filename) {
|
public AmenityIndexRepositoryBinary getAmenityRepositoryByFileName(String filename) {
|
||||||
return (AmenityIndexRepositoryBinary) amenityRepositories.get(filename);
|
return (AmenityIndexRepositoryBinary) amenityRepositories.get(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////// Working with address ///////////////////////////////////////////
|
////////////////////////////////////////////// Working with address ///////////////////////////////////////////
|
||||||
|
|
||||||
public RegionAddressRepository getRegionRepository(String name){
|
public RegionAddressRepository getRegionRepository(String name) {
|
||||||
return addressMap.get(name);
|
return addressMap.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<RegionAddressRepository> getAddressRepositories(){
|
public Collection<RegionAddressRepository> getAddressRepositories() {
|
||||||
return addressMap.values();
|
return addressMap.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<BinaryMapReaderResource> getFileReaders() {
|
public Collection<BinaryMapReaderResource> getFileReaders() {
|
||||||
List<String> fileNames = new ArrayList<>(fileReaders.keySet());
|
List<String> fileNames = new ArrayList<>(fileReaders.keySet());
|
||||||
Collections.sort(fileNames, Algorithms.getStringVersionComparator());
|
Collections.sort(fileNames, Algorithms.getStringVersionComparator());
|
||||||
|
@ -993,8 +995,8 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////// Working with transport ////////////////////////////////////////////////
|
////////////////////////////////////////////// Working with transport ////////////////////////////////////////////////
|
||||||
|
|
||||||
private List<BinaryMapIndexReader> getTransportRepositories(double topLat, double leftLon, double bottomLat, double rightLon) {
|
private List<BinaryMapIndexReader> getTransportRepositories(double topLat, double leftLon, double bottomLat, double rightLon) {
|
||||||
|
@ -1013,7 +1015,7 @@ public class ResourceManager {
|
||||||
|
|
||||||
|
|
||||||
public List<TransportStop> searchTransportSync(double topLat, double leftLon, double bottomLat, double rightLon,
|
public List<TransportStop> searchTransportSync(double topLat, double leftLon, double bottomLat, double rightLon,
|
||||||
ResultMatcher<TransportStop> matcher) throws IOException {
|
ResultMatcher<TransportStop> matcher) throws IOException {
|
||||||
TransportStopsRouteReader readers =
|
TransportStopsRouteReader readers =
|
||||||
new TransportStopsRouteReader(getTransportRepositories(topLat, leftLon, bottomLat, rightLon));
|
new TransportStopsRouteReader(getTransportRepositories(topLat, leftLon, bottomLat, rightLon));
|
||||||
List<TransportStop> stops = new ArrayList<>();
|
List<TransportStop> stops = new ArrayList<>();
|
||||||
|
@ -1030,7 +1032,7 @@ public class ResourceManager {
|
||||||
|
|
||||||
public List<TransportRoute> getRoutesForStop(TransportStop stop) {
|
public List<TransportRoute> getRoutesForStop(TransportStop stop) {
|
||||||
List<TransportRoute> rts = stop.getRoutes();
|
List<TransportRoute> rts = stop.getRoutes();
|
||||||
if(rts != null) {
|
if (rts != null) {
|
||||||
return rts;
|
return rts;
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
@ -1040,26 +1042,26 @@ public class ResourceManager {
|
||||||
public boolean updateRenderedMapNeeded(RotatedTileBox rotatedTileBox, DrawSettings drawSettings) {
|
public boolean updateRenderedMapNeeded(RotatedTileBox rotatedTileBox, DrawSettings drawSettings) {
|
||||||
return renderer.updateMapIsNeeded(rotatedTileBox, drawSettings);
|
return renderer.updateMapIsNeeded(rotatedTileBox, drawSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateRendererMap(RotatedTileBox rotatedTileBox, OnMapLoadedListener mapLoadedListener){
|
public void updateRendererMap(RotatedTileBox rotatedTileBox, OnMapLoadedListener mapLoadedListener) {
|
||||||
renderer.interruptLoadingMap();
|
renderer.interruptLoadingMap();
|
||||||
asyncLoadingThread.requestToLoadMap(new MapLoadRequest(rotatedTileBox, mapLoadedListener));
|
asyncLoadingThread.requestToLoadMap(new MapLoadRequest(rotatedTileBox, mapLoadedListener));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void interruptRendering(){
|
public void interruptRendering() {
|
||||||
renderer.interruptLoadingMap();
|
renderer.interruptLoadingMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSearchAmenitiesInProgress() {
|
public boolean isSearchAmenitiesInProgress() {
|
||||||
return searchAmenitiesInProgress;
|
return searchAmenitiesInProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapRenderRepositories getRenderer() {
|
public MapRenderRepositories getRenderer() {
|
||||||
return renderer;
|
return renderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////// Closing methods ////////////////////////////////////////////////
|
////////////////////////////////////////////// Closing methods ////////////////////////////////////////////////
|
||||||
|
|
||||||
public void closeFile(String fileName) {
|
public void closeFile(String fileName) {
|
||||||
amenityRepositories.remove(fileName);
|
amenityRepositories.remove(fileName);
|
||||||
addressMap.remove(fileName);
|
addressMap.remove(fileName);
|
||||||
|
@ -1067,12 +1069,12 @@ public class ResourceManager {
|
||||||
indexFileNames.remove(fileName);
|
indexFileNames.remove(fileName);
|
||||||
renderer.closeConnection(fileName);
|
renderer.closeConnection(fileName);
|
||||||
BinaryMapReaderResource resource = fileReaders.remove(fileName);
|
BinaryMapReaderResource resource = fileReaders.remove(fileName);
|
||||||
if(resource != null) {
|
if (resource != null) {
|
||||||
resource.close();
|
resource.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void close(){
|
public synchronized void close() {
|
||||||
for (TilesCache tc : tilesCacheList) {
|
for (TilesCache tc : tilesCacheList) {
|
||||||
tc.close();
|
tc.close();
|
||||||
}
|
}
|
||||||
|
@ -1082,13 +1084,13 @@ public class ResourceManager {
|
||||||
transportRepositories.clear();
|
transportRepositories.clear();
|
||||||
addressMap.clear();
|
addressMap.clear();
|
||||||
amenityRepositories.clear();
|
amenityRepositories.clear();
|
||||||
for(BinaryMapReaderResource res : fileReaders.values()) {
|
for (BinaryMapReaderResource res : fileReaders.values()) {
|
||||||
res.close();
|
res.close();
|
||||||
}
|
}
|
||||||
fileReaders.clear();
|
fileReaders.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public BinaryMapIndexReader[] getRoutingMapFiles() {
|
public BinaryMapIndexReader[] getRoutingMapFiles() {
|
||||||
Collection<BinaryMapReaderResource> fileReaders = getFileReaders();
|
Collection<BinaryMapReaderResource> fileReaders = getFileReaders();
|
||||||
List<BinaryMapIndexReader> readers = new ArrayList<>(fileReaders.size());
|
List<BinaryMapIndexReader> readers = new ArrayList<>(fileReaders.size());
|
||||||
|
@ -1107,7 +1109,7 @@ public class ResourceManager {
|
||||||
Collection<BinaryMapReaderResource> fileReaders = getFileReaders();
|
Collection<BinaryMapReaderResource> fileReaders = getFileReaders();
|
||||||
List<BinaryMapIndexReader> readers = new ArrayList<>(fileReaders.size());
|
List<BinaryMapIndexReader> readers = new ArrayList<>(fileReaders.size());
|
||||||
for (BinaryMapReaderResource r : fileReaders) {
|
for (BinaryMapReaderResource r : fileReaders) {
|
||||||
if (r.isUseForPublicTransport()) {
|
if (r.isUseForPublicTransport()) {
|
||||||
BinaryMapIndexReader reader = r.getReader(BinaryMapReaderResourceType.TRANSPORT_ROUTING);
|
BinaryMapIndexReader reader = r.getReader(BinaryMapReaderResourceType.TRANSPORT_ROUTING);
|
||||||
if (reader != null) {
|
if (reader != null) {
|
||||||
readers.add(reader);
|
readers.add(reader);
|
||||||
|
@ -1132,12 +1134,29 @@ public class ResourceManager {
|
||||||
return readers.toArray(new BinaryMapIndexReader[0]);
|
return readers.toArray(new BinaryMapIndexReader[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BinaryMapIndexReader[] getTravelFiles() {
|
||||||
|
Collection<BinaryMapReaderResource> fileReaders = getFileReaders();
|
||||||
|
List<BinaryMapIndexReader> readers = new ArrayList<>(fileReaders.size());
|
||||||
|
for (BinaryMapReaderResource res : fileReaders) {
|
||||||
|
if (!res.filename.toString().toLowerCase().contains("wiki")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BinaryMapIndexReader index = res.getReader(BinaryMapReaderResourceType.POI);
|
||||||
|
for (BinaryIndexPart p : index.getIndexes()) {
|
||||||
|
if (p instanceof BinaryMapPoiReaderAdapter.PoiRegion) {
|
||||||
|
readers.add(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return readers.toArray(new BinaryMapIndexReader[0]);
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, String> getIndexFileNames() {
|
public Map<String, String> getIndexFileNames() {
|
||||||
return new LinkedHashMap<String, String>(indexFileNames);
|
return new LinkedHashMap<String, String>(indexFileNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean containsBasemap(){
|
public boolean containsBasemap() {
|
||||||
return !basemapFileNames.isEmpty();
|
return !basemapFileNames.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1171,13 +1190,13 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void reloadTilesFromFS() {
|
public synchronized void reloadTilesFromFS() {
|
||||||
for (TilesCache tc : tilesCacheList) {
|
for (TilesCache tc : tilesCacheList) {
|
||||||
tc.tilesOnFS.clear();
|
tc.tilesOnFS.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// On low memory method ///
|
/// On low memory method ///
|
||||||
public void onLowMemory() {
|
public void onLowMemory() {
|
||||||
log.info("On low memory");
|
log.info("On low memory");
|
||||||
|
@ -1186,10 +1205,10 @@ public class ResourceManager {
|
||||||
r.clearCache();
|
r.clearCache();
|
||||||
}
|
}
|
||||||
renderer.clearCache();
|
renderer.clearCache();
|
||||||
|
|
||||||
System.gc();
|
System.gc();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GeoidAltitudeCorrection getGeoidAltitudeCorrection() {
|
public GeoidAltitudeCorrection getGeoidAltitudeCorrection() {
|
||||||
return geoidAltitudeCorrection;
|
return geoidAltitudeCorrection;
|
||||||
}
|
}
|
||||||
|
@ -1204,7 +1223,7 @@ public class ResourceManager {
|
||||||
tc.clearTiles();
|
tc.clearTiles();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IncrementalChangesManager getChangesManager() {
|
public IncrementalChangesManager getChangesManager() {
|
||||||
return changesManager;
|
return changesManager;
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,23 +85,23 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
* 2. check settings for default?
|
* 2. check settings for default?
|
||||||
*/
|
*/
|
||||||
public void initTravelBooks() {
|
public void initTravelBooks() {
|
||||||
List<File> files = getPossibleFiles();
|
BinaryMapIndexReader[] readers = application.getResourceManager().getTravelFiles();
|
||||||
String travelBook = application.getSettings().SELECTED_TRAVEL_BOOK.get();
|
String travelBook = application.getSettings().SELECTED_TRAVEL_BOOK.get();
|
||||||
existingTravelBooks.clear();
|
existingTravelBooks.clear();
|
||||||
if (files != null && !files.isEmpty()) {
|
if (readers != null) {
|
||||||
for (File f : files) {
|
for (BinaryMapIndexReader reader : readers) {
|
||||||
|
File f = reader.getFile();
|
||||||
existingTravelBooks.add(f);
|
existingTravelBooks.add(f);
|
||||||
if (selectedTravelBook == null) {
|
if (selectedTravelBook == null) {
|
||||||
selectedTravelBook = f;
|
selectedTravelBook = f;
|
||||||
} else if (Algorithms.objectEquals(travelBook, f.getName())) {
|
} else if (Algorithms.objectEquals(travelBook, f.getName())) {
|
||||||
selectedTravelBook = f;
|
selectedTravelBook = f;
|
||||||
}
|
}
|
||||||
|
selectedTravelBook = reader.getFile();
|
||||||
}
|
}
|
||||||
selectedTravelBook = files.get(0);
|
|
||||||
} else {
|
} else {
|
||||||
selectedTravelBook = null;
|
selectedTravelBook = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,6 +147,7 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public List<WikivoyageSearchResult> search(String searchQuery) {
|
public List<WikivoyageSearchResult> search(String searchQuery) {
|
||||||
|
|
||||||
List<WikivoyageSearchResult> res = new ArrayList<>();
|
List<WikivoyageSearchResult> res = new ArrayList<>();
|
||||||
CollatorStringMatcher matcher = new CollatorStringMatcher(searchQuery,
|
CollatorStringMatcher matcher = new CollatorStringMatcher(searchQuery,
|
||||||
CollatorStringMatcher.StringMatcherMode.CHECK_STARTS_FROM_SPACE);
|
CollatorStringMatcher.StringMatcherMode.CHECK_STARTS_FROM_SPACE);
|
||||||
|
|
Loading…
Reference in a new issue