Merge pull request #10369 from osmandapp/issue_336_wikiwoyage_bigfix
travel obf resource manager reader added
This commit is contained in:
commit
7538d5bea1
4 changed files with 198 additions and 7 deletions
|
@ -67,6 +67,7 @@ import net.osmand.plus.voice.MediaCommandPlayerImpl;
|
|||
import net.osmand.plus.voice.TTSCommandPlayerImpl;
|
||||
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
|
||||
import net.osmand.plus.wikivoyage.data.TravelHelper;
|
||||
import net.osmand.plus.wikivoyage.data.TravelObfHelper;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
import net.osmand.router.RoutingConfiguration;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -459,7 +460,7 @@ public class AppInitializer implements IProgress {
|
|||
app.mapViewTrackingUtilities = startupInit(new MapViewTrackingUtilities(app), MapViewTrackingUtilities.class);
|
||||
|
||||
// TODOTRAVEL_OBF_HELPER check ResourceManager and use TravelObfHelper
|
||||
app.travelHelper = new TravelDbHelper(app);
|
||||
app.travelHelper = !TravelDbHelper.checkIfDbFileExists(app) ? new TravelObfHelper(app) : new TravelDbHelper(app);
|
||||
app.travelHelper.initializeDataOnAppStartup();
|
||||
app.travelHelper = startupInit(app.travelHelper, TravelHelper.class);
|
||||
|
||||
|
|
|
@ -75,7 +75,6 @@ import java.util.Map.Entry;
|
|||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
||||
import static net.osmand.IndexConstants.VOICE_INDEX_DIR;
|
||||
|
||||
/**
|
||||
|
@ -210,7 +209,7 @@ public class ResourceManager {
|
|||
protected final Map<String, AmenityIndexRepository> amenityRepositories = new ConcurrentHashMap<String, AmenityIndexRepository>();
|
||||
// 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> travelRepositories = new ConcurrentHashMap<String, BinaryMapReaderResource>();
|
||||
protected final Map<String, String> indexFileNames = new ConcurrentHashMap<String, String>();
|
||||
protected final Map<String, String> basemapFileNames = new ConcurrentHashMap<String, String>();
|
||||
|
||||
|
@ -634,6 +633,7 @@ public class ResourceManager {
|
|||
collectFiles(roadsPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||
if (Version.isPaidVersion(context)) {
|
||||
collectFiles(context.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||
collectFiles(context.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT, files);
|
||||
}
|
||||
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isSubscribedToLiveUpdates(context)) {
|
||||
collectFiles(context.getAppPath(IndexConstants.SRTM_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
|
||||
|
@ -726,7 +726,10 @@ public class ResourceManager {
|
|||
}
|
||||
renderer.initializeNewResource(progress, f, mapReader);
|
||||
BinaryMapReaderResource resource = new BinaryMapReaderResource(f, mapReader);
|
||||
|
||||
if (collectTravelFiles(resource)){
|
||||
//travel files are indexed
|
||||
continue;
|
||||
}
|
||||
fileReaders.put(f.getName(), resource);
|
||||
if (!mapReader.getRegionNames().isEmpty()) {
|
||||
RegionAddressRepositoryBinary rarb = new RegionAddressRepositoryBinary(this, resource);
|
||||
|
@ -798,7 +801,43 @@ public class ResourceManager {
|
|||
return warnings;
|
||||
}
|
||||
|
||||
private List<BinaryMapIndexReader> getTravelRepositories() {
|
||||
List<String> fileNames = new ArrayList<>(travelRepositories.keySet());
|
||||
Collections.sort(fileNames, Algorithms.getStringVersionComparator());
|
||||
List<BinaryMapIndexReader> res = new ArrayList<>();
|
||||
for (String fileName : fileNames) {
|
||||
BinaryMapReaderResource r = travelRepositories.get(fileName);
|
||||
if (r != null) {
|
||||
res.add(r.getReader(BinaryMapReaderResourceType.POI));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private List<BinaryMapIndexReader> getTravelRepositories(double topLat, double leftLon, double bottomLat, double rightLon) {
|
||||
List<String> fileNames = new ArrayList<>(travelRepositories.keySet());
|
||||
Collections.sort(fileNames, Algorithms.getStringVersionComparator());
|
||||
int leftX31 = MapUtils.get31TileNumberX(leftLon);
|
||||
int topX31 = MapUtils.get31TileNumberY(topLat);
|
||||
int rightX31 = MapUtils.get31TileNumberX(rightLon);
|
||||
int bottomX31 = MapUtils.get31TileNumberY(bottomLat);
|
||||
List<BinaryMapIndexReader> res = new ArrayList<>();
|
||||
for (String fileName : fileNames) {
|
||||
BinaryMapReaderResource r = travelRepositories.get(fileName);
|
||||
if (r != null && r.getShallowReader().containsPoiData(leftX31, topX31, rightX31, bottomX31)) {
|
||||
res.add(r.getReader(BinaryMapReaderResourceType.POI));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private boolean collectTravelFiles(BinaryMapReaderResource resource) {
|
||||
if (resource.getFileName().contains(IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT)){
|
||||
travelRepositories.put(resource.getFileName(), resource);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void initMapBoundariesCacheNative() {
|
||||
File indCache = context.getAppPath(INDEXES_CACHE);
|
||||
|
@ -1065,6 +1104,7 @@ public class ResourceManager {
|
|||
addressMap.remove(fileName);
|
||||
transportRepositories.remove(fileName);
|
||||
indexFileNames.remove(fileName);
|
||||
travelRepositories.remove(fileName);
|
||||
renderer.closeConnection(fileName);
|
||||
BinaryMapReaderResource resource = fileReaders.remove(fileName);
|
||||
if(resource != null) {
|
||||
|
@ -1080,6 +1120,7 @@ public class ResourceManager {
|
|||
basemapFileNames.clear();
|
||||
renderer.clearAllResources();
|
||||
transportRepositories.clear();
|
||||
travelRepositories.clear();
|
||||
addressMap.clear();
|
||||
amenityRepositories.clear();
|
||||
for(BinaryMapReaderResource res : fileReaders.values()) {
|
||||
|
@ -1088,7 +1129,6 @@ public class ResourceManager {
|
|||
fileReaders.clear();
|
||||
}
|
||||
|
||||
|
||||
public BinaryMapIndexReader[] getRoutingMapFiles() {
|
||||
Collection<BinaryMapReaderResource> fileReaders = getFileReaders();
|
||||
List<BinaryMapIndexReader> readers = new ArrayList<>(fileReaders.size());
|
||||
|
|
|
@ -114,6 +114,18 @@ public class TravelDbHelper implements TravelHelper {
|
|||
localDataHelper = new TravelLocalDataHelper(application);
|
||||
}
|
||||
|
||||
public static boolean checkIfDbFileExists(OsmandApplication app) {
|
||||
File[] files = app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR).listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public TravelLocalDataHelper getBookmarksHelper() {
|
||||
return localDataHelper;
|
||||
}
|
||||
|
|
138
OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java
Normal file
138
OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java
Normal file
|
@ -0,0 +1,138 @@
|
|||
package net.osmand.plus.wikivoyage.data;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import net.osmand.CollatorStringMatcher;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.MapObject;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.api.SQLiteAPI;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TravelObfHelper implements TravelHelper {
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(TravelObfHelper.class);
|
||||
|
||||
|
||||
private final OsmandApplication application;
|
||||
|
||||
private TravelLocalDataHelper localDataHelper;
|
||||
|
||||
private List<TravelArticle> popularArticles = new ArrayList<TravelArticle>();
|
||||
|
||||
|
||||
public TravelObfHelper(OsmandApplication application) {
|
||||
this.application = application;
|
||||
localDataHelper = new TravelLocalDataHelper(application);
|
||||
}
|
||||
|
||||
public TravelLocalDataHelper getBookmarksHelper() {
|
||||
return localDataHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeDataOnAppStartup() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyTravelBookPresent() {
|
||||
return checkIfObfFileExists(application);
|
||||
}
|
||||
|
||||
|
||||
public void initializeDataToDisplay() {
|
||||
localDataHelper.refreshCachedData();
|
||||
loadPopularArticles();
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
public List<WikivoyageSearchResult> search(final String searchQuery) {
|
||||
List<WikivoyageSearchResult> res = new ArrayList<>();
|
||||
return res;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<TravelArticle> getPopularArticles() {
|
||||
return popularArticles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<WikivoyageSearchResult, List<WikivoyageSearchResult>> getNavigationMap(TravelArticle article) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TravelArticle getArticleById(String routeId, String lang) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TravelArticle getArticleByTitle(String title, String lang) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArticleId(String title, String lang) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getArticleLangs(String articleId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<TravelArticle> loadPopularArticles() {
|
||||
popularArticles = new ArrayList<>();
|
||||
return popularArticles;
|
||||
}
|
||||
|
||||
public String getGPXName(TravelArticle article) {
|
||||
return article.getTitle().replace('/', '_').replace('\'', '_')
|
||||
.replace('\"', '_') + IndexConstants.GPX_FILE_EXT;
|
||||
}
|
||||
|
||||
public File createGpxFile(TravelArticle article) {
|
||||
final GPXUtilities.GPXFile gpx = article.getGpxFile();
|
||||
File file = application.getAppPath(IndexConstants.GPX_TRAVEL_DIR + getGPXName(article));
|
||||
if (!file.exists()) {
|
||||
GPXUtilities.writeGpxFile(file, gpx);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectedTravelBookName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean checkIfObfFileExists(OsmandApplication app) {
|
||||
File[] files = app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR).listFiles();
|
||||
if (files != null) {
|
||||
for (File f : files) {
|
||||
if (f.getName().contains(IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue