travel obf resource manager reader added

This commit is contained in:
simon 2020-12-09 14:55:35 +02:00
parent c949f98329
commit 16ae7b28c1
2 changed files with 132 additions and 112 deletions

View file

@ -19,8 +19,10 @@ import net.osmand.IndexConstants;
import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryIndexPart;
import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter;
import net.osmand.binary.BinaryMapPoiReaderAdapter;
import net.osmand.binary.CachedOsmandIndexes;
import net.osmand.data.Amenity;
import net.osmand.data.RotatedTileBox;
@ -75,7 +77,6 @@ import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import static net.osmand.IndexConstants.VOICE_INDEX_DIR;
/**
@ -126,6 +127,7 @@ public class ResourceManager {
private List<BinaryMapIndexReader> readers = new ArrayList<>(BinaryMapReaderResourceType.values().length);
private boolean useForRouting;
private boolean useForPublicTransport;
public BinaryMapReaderResource(File f, BinaryMapIndexReader initialReader) {
this.filename = f;
this.initialReader = initialReader;
@ -540,6 +542,7 @@ public class ResourceManager {
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__copyOnlyIfDoesNotExist = "copyOnlyIfDoesNotExist";
private void unpackBundledAssets(AssetManager assetManager, File appDataDir, IProgress progress, boolean isFirstInstall) throws IOException, XmlPullParserException {
List<AssetEntry> assetEntries = DownloadOsmandIndexesHelper.getBundledAssets(assetManager);
for (AssetEntry asset : assetEntries) {
@ -608,7 +611,6 @@ public class ResourceManager {
}
private void renameRoadsFiles(ArrayList<File> files, File roadsPath) {
Iterator<File> it = files.iterator();
while (it.hasNext()) {
@ -634,6 +636,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_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);
@ -799,7 +802,6 @@ public class ResourceManager {
}
public void initMapBoundariesCacheNative() {
File indCache = context.getAppPath(INDEXES_CACHE);
if (indCache.exists()) {
@ -1132,6 +1134,23 @@ public class ResourceManager {
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() {
return new LinkedHashMap<String, String>(indexFileNames);
}

View file

@ -85,23 +85,23 @@ public class TravelObfHelper implements TravelHelper {
* 2. check settings for default?
*/
public void initTravelBooks() {
List<File> files = getPossibleFiles();
BinaryMapIndexReader[] readers = application.getResourceManager().getTravelFiles();
String travelBook = application.getSettings().SELECTED_TRAVEL_BOOK.get();
existingTravelBooks.clear();
if (files != null && !files.isEmpty()) {
for (File f : files) {
if (readers != null) {
for (BinaryMapIndexReader reader : readers) {
File f = reader.getFile();
existingTravelBooks.add(f);
if (selectedTravelBook == null) {
selectedTravelBook = f;
} else if (Algorithms.objectEquals(travelBook, f.getName())) {
selectedTravelBook = f;
}
selectedTravelBook = reader.getFile();
}
selectedTravelBook = files.get(0);
} else {
selectedTravelBook = null;
}
}
/**
@ -147,6 +147,7 @@ public class TravelObfHelper implements TravelHelper {
@NonNull
@Override
public List<WikivoyageSearchResult> search(String searchQuery) {
List<WikivoyageSearchResult> res = new ArrayList<>();
CollatorStringMatcher matcher = new CollatorStringMatcher(searchQuery,
CollatorStringMatcher.StringMatcherMode.CHECK_STARTS_FROM_SPACE);