From 75e5f7828a0ee727075ed6b880f0fb73d77a002e Mon Sep 17 00:00:00 2001 From: max-klaus Date: Sun, 10 Jan 2021 14:12:50 +0300 Subject: [PATCH] Fix gpx reading for travel obf --- .../osmand/binary/BinaryMapIndexReader.java | 4 + .../main/java/net/osmand/data/Amenity.java | 14 +- .../wikivoyage/WikivoyageWebViewClient.java | 3 +- .../WikivoyageArticleDialogFragment.java | 8 +- .../plus/wikivoyage/data/TravelArticle.java | 12 +- .../plus/wikivoyage/data/TravelDbHelper.java | 7 +- .../plus/wikivoyage/data/TravelHelper.java | 6 - .../plus/wikivoyage/data/TravelObfHelper.java | 160 +++++++++--------- .../data/WikivoyageSearchResult.java | 6 +- 9 files changed, 99 insertions(+), 121 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapIndexReader.java b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapIndexReader.java index 7486576b61..8743940a74 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapIndexReader.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapIndexReader.java @@ -1769,6 +1769,10 @@ public class BinaryMapIndexReader { return limit != -1 && searchResults.size() > limit; } + public void setLimit(int limit) { + this.limit = limit; + } + public boolean isCancelled() { if (this.interrupted) { return interrupted; diff --git a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java index 52b3233426..3ef6a54652 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java @@ -208,7 +208,7 @@ public class Amenity extends MapObject { return getAdditionalInfo(COLOR); } - public String getIcon() { + public String getGpxIcon() { return getAdditionalInfo(GPX_ICON); } @@ -262,17 +262,15 @@ public class Amenity extends MapObject { return l; } - public String getTagSuffix(String tagBegin) { - String tagSuffix = null; + public String getTagSuffix(String tagPrefix) { for (String infoTag : getAdditionalInfoKeys()) { - if (infoTag.startsWith(tagBegin)) { - if (infoTag.length() > tagBegin.length()) { - tagSuffix = infoTag.substring(tagBegin.length()); - break; + if (infoTag.startsWith(tagPrefix)) { + if (infoTag.length() > tagPrefix.length()) { + return infoTag.substring(tagPrefix.length()); } } } - return tagSuffix; + return null; } public String getTagContent(String tag, String lang) { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java index c2c42551e2..b102e718f6 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java @@ -14,6 +14,7 @@ import androidx.fragment.app.FragmentManager; import net.osmand.AndroidUtils; import net.osmand.GPXUtilities; +import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.WptPt; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -119,7 +120,7 @@ public class WikivoyageWebViewClient extends WebViewClient { fragmentManager.popBackStackImmediate(); File path = app.getTravelHelper().createGpxFile(article); - GPXUtilities.GPXFile gpxFile = article.getGpxFile(); + GPXFile gpxFile = article.getGpxFile(); gpxFile.path = path.getAbsolutePath(); app.getSelectedGpxHelper().setGpxFileToDisplay(gpxFile); MapActivity.launchMapActivityMoveToTop(activity); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java index 20556832db..9e2339f3ee 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java @@ -27,6 +27,8 @@ import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager.BackStackEntry; import net.osmand.AndroidUtils; +import net.osmand.GPXUtilities; +import net.osmand.GPXUtilities.GPXFile; import net.osmand.IndexConstants; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -309,10 +311,10 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme } webViewClient.setArticle(article); articleToolbarText.setText(article.getTitle()); - article.setGpxFile(getMyApplication().getTravelHelper().getGpxFile(article, selectedLang)); - if (article.getGpxFile() != null && article.getGpxFile().getPointsSize() > 0) { + GPXFile gpxFile = article.getGpxFile(); + if (gpxFile != null && gpxFile.getPointsSize() > 0) { trackButton.setVisibility(View.VISIBLE); - trackButton.setText(getString(R.string.shared_string_gpx_points) + " (" + article.getGpxFile().getPointsSize() + ")"); + trackButton.setText(getString(R.string.shared_string_gpx_points) + " (" + gpxFile.getPointsSize() + ")"); } else { trackButton.setVisibility(View.GONE); } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java index bfa87423f9..0579af14cc 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java @@ -43,6 +43,7 @@ public class TravelArticle { String aggregatedPartOf; long lastModified; + boolean gpxFileRead; @NonNull public TravelArticleIdentifier generateIdentifier() { @@ -98,10 +99,6 @@ public class TravelArticle { return gpxFile; } - public void setGpxFile(GPXFile gpxFile) { - this.gpxFile = gpxFile; - } - public String getRouteId() { return routeId; } @@ -174,7 +171,6 @@ public class TravelArticle { @Nullable File file; double lat; double lon; - @Nullable String title; @Nullable String routeId; @Nullable String routeSource; @@ -198,7 +194,6 @@ public class TravelArticle { file = article.file; lat = article.lat; lon = article.lon; - title = article.title; routeId = article.routeId; routeSource = article.routeSource; } @@ -207,7 +202,6 @@ public class TravelArticle { public void writeToParcel(Parcel out, int flags) { out.writeDouble(lat); out.writeDouble(lon); - out.writeString(title); out.writeString(routeId); out.writeString(routeSource); out.writeString(file != null ? file.getAbsolutePath() : null); @@ -216,7 +210,6 @@ public class TravelArticle { private void readFromParcel(Parcel in) { lat = in.readDouble(); lon = in.readDouble(); - title = in.readString(); routeId = in.readString(); routeSource = in.readString(); String filePath = in.readString(); @@ -241,14 +234,13 @@ public class TravelArticle { TravelArticleIdentifier that = (TravelArticleIdentifier) o; return areLatLonEqual(that.lat, that.lon, lat, lon) && Algorithms.objectEquals(file, that.file) && - Algorithms.stringsEqual(title, that.title) && Algorithms.stringsEqual(routeId, that.routeId) && Algorithms.stringsEqual(routeSource, that.routeSource); } @Override public int hashCode() { - return Algorithms.hash(file, lat, lon, title, routeId, routeSource); + return Algorithms.hash(file, lat, lon, routeId, routeSource); } private static boolean areLatLonEqual(double lat1, double lon1, double lat2, double lon2) { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java index d36407441a..73bebdf9ad 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java @@ -448,7 +448,7 @@ public class TravelDbHelper implements TravelHelper { } } if (matchLang) { - prev.articleId.title = rs.getArticleTitle(); + prev.articleTitle = rs.getArticleTitle(); prev.isPartOf = rs.getIsPartOf(); } prev.langs.add(matchLang ? 0 : 1, rs.langs.get(0)); @@ -683,11 +683,6 @@ public class TravelDbHelper implements TravelHelper { return res; } - @Override - public GPXFile getGpxFile(@NonNull TravelArticle article, @Nullable String lang) { - return article.getGpxFile(); - } - public String formatTravelBookName(File tb) { if (tb == null) { return application.getString(R.string.shared_string_none); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java index 20dcfac73e..87b5bc1e95 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java @@ -3,7 +3,6 @@ package net.osmand.plus.wikivoyage.data; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import net.osmand.GPXUtilities; import net.osmand.data.LatLon; import net.osmand.data.QuadRect; import net.osmand.plus.wikivoyage.data.TravelArticle.TravelArticleIdentifier; @@ -13,8 +12,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import static net.osmand.GPXUtilities.*; - public interface TravelHelper { TravelLocalDataHelper getBookmarksHelper(); @@ -52,9 +49,6 @@ public interface TravelHelper { @NonNull ArrayList getArticleLangs(@NonNull TravelArticleIdentifier articleId); - @Nullable - GPXFile getGpxFile(@NonNull TravelArticle article, @Nullable String lang); - @NonNull String getGPXName(@NonNull final TravelArticle article); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 1f7a2af18f..d173e20b47 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -45,7 +45,8 @@ import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import static net.osmand.GPXUtilities.*; +import static net.osmand.GPXUtilities.WptPt; +import static net.osmand.GPXUtilities.writeGpxFile; public class TravelObfHelper implements TravelHelper { @@ -93,12 +94,12 @@ public class TravelObfHelper implements TravelHelper { try { final LatLon location = app.getMapViewTrackingUtilities().getMapLocation(); SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest( - location, POPULAR_ARTICLES_SEARCH_RADIUS, -1, getSearchRouteArticleFilter(), null); + location, POPULAR_ARTICLES_SEARCH_RADIUS, -1, getSearchFilter(false), null); List amenities = reader.searchPoi(req); if (amenities.size() > 0) { for (Amenity amenity : amenities) { if (!Algorithms.isEmpty(amenity.getName(lang))) { - TravelArticle article = cacheTravelArticles(reader.getFile(), amenity, lang); + TravelArticle article = cacheTravelArticles(reader.getFile(), amenity, lang, false); if (article != null) { popularArticles.add(article); if (popularArticles.size() >= MAX_POPULAR_ARTICLES_COUNT) { @@ -127,23 +128,23 @@ public class TravelObfHelper implements TravelHelper { } @Nullable - private TravelArticle cacheTravelArticles(File file, Amenity amenity, String lang) { + private TravelArticle cacheTravelArticles(File file, Amenity amenity, String lang, boolean readPoints) { TravelArticle article = null; - Map articles = readArticles(file, amenity); + Map articles = readArticles(file, amenity, readPoints); if (!Algorithms.isEmpty(articles)) { TravelArticleIdentifier newArticleId = articles.values().iterator().next().generateIdentifier(); cachedArticles.put(newArticleId, articles); - article = getCachedArticle(newArticleId, lang); + article = getCachedArticle(newArticleId, lang, readPoints); } return article; } @NonNull - private SearchPoiTypeFilter getSearchRouteArticleFilter() { + private SearchPoiTypeFilter getSearchFilter(final boolean articlePoints) { return new SearchPoiTypeFilter() { @Override public boolean accept(PoiCategory type, String subcategory) { - return subcategory.equals(ROUTE_ARTICLE); + return subcategory.equals(articlePoints ? ROUTE_ARTICLE_POINT : ROUTE_ARTICLE); } @Override @@ -154,32 +155,17 @@ public class TravelObfHelper implements TravelHelper { } @NonNull - private SearchPoiTypeFilter getSearchRouteArticlePointsFilter() { - return new SearchPoiTypeFilter() { - @Override - public boolean accept(PoiCategory type, String subcategory) { - return subcategory.equals(ROUTE_ARTICLE_POINT); - } - - @Override - public boolean isEmpty() { - return false; - } - }; - } - - @NonNull - private Map readArticles(@NonNull File file, @NonNull Amenity amenity) { + private Map readArticles(@NonNull File file, @NonNull Amenity amenity, boolean readPoints) { Map articles = new HashMap<>(); Set langs = getLanguages(amenity); for (String lang : langs) { - articles.put(lang, readArticle(file, amenity, lang)); + articles.put(lang, readArticle(file, amenity, lang, readPoints)); } return articles; } @NonNull - private TravelArticle readArticle(@NonNull File file, @NonNull Amenity amenity, @Nullable String lang) { + private TravelArticle readArticle(@NonNull File file, @NonNull Amenity amenity, @NonNull String lang, boolean readPoints) { TravelArticle res = new TravelArticle(); res.file = file; String title = amenity.getName(lang); @@ -195,40 +181,44 @@ public class TravelObfHelper implements TravelHelper { res.lang = lang; res.contentsJson = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.CONTENT_JSON, lang)); res.aggregatedPartOf = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.IS_AGGR_PART, lang)); + if (readPoints) { + res.gpxFile = buildGpxFile(res); + res.gpxFileRead = true; + } return res; } - - @Override - public GPXFile getGpxFile(@NonNull TravelArticle article, @Nullable String lang) { + private GPXFile buildGpxFile(@NonNull TravelArticle article) { GPXFile gpxFile = null; - List pointList = getPointList(article, lang); + List pointList = getPointList(article); if (!Algorithms.isEmpty(pointList)) { - gpxFile = new GPXFile(article.getTitle(), lang, ""); + gpxFile = new GPXFile(article.getTitle(), article.getLang(), ""); for (Amenity amenity : pointList) { - WptPt wptPt = createWptPt(amenity, lang); + WptPt wptPt = createWptPt(amenity, article.getLang()); gpxFile.addPoint(wptPt); } } return gpxFile; } - @Nullable - private List getPointList(@NonNull final TravelArticle article, @Nullable final String lang) { + @NonNull + private List getPointList(@NonNull final TravelArticle article) { final List pointList = new ArrayList<>(); + final String lang = article.getLang(); for (BinaryMapIndexReader reader : getReaders()) { try { - final LatLon location = new LatLon(article.getLat(), article.getLon()); - SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest( - location, POPULAR_ARTICLES_SEARCH_RADIUS, -1, getSearchRouteArticlePointsFilter(), - new ResultMatcher() { + if (article.file != null && !article.file.equals(reader.getFile())) { + continue; + } + SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, + Algorithms.emptyIfNull(article.routeId), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, + getSearchFilter(false), new ResultMatcher() { + @Override - public boolean publish(Amenity point) { - String amenityLang = point.getTagSuffix(Amenity.LANG_YES + ":"); - if (lang != null && lang.equals(amenityLang) - && point.getAdditionalInfo(Amenity.ROUTE_ID) != null - && point.getAdditionalInfo(Amenity.ROUTE_ID).equals(article.getRouteId())) { - pointList.add(point); + public boolean publish(Amenity amenity) { + String amenityLang = amenity.getTagSuffix(Amenity.LANG_YES + ":"); + if (lang.equals(amenityLang)) { + pointList.add(amenity); } return false; } @@ -237,8 +227,18 @@ public class TravelObfHelper implements TravelHelper { public boolean isCancelled() { return false; } - }); - reader.searchPoi(req); + }, null); + + if (!Double.isNaN(article.lat)) { + req.setBBoxRadius(article.lat, article.lon, ARTICLE_SEARCH_RADIUS); + if (!Algorithms.isEmpty(article.title)) { + reader.searchPoiByName(req); + } else { + reader.searchPoi(req); + } + } else { + reader.searchPoi(req); + } } catch (Exception e) { LOG.error(e.getMessage(), e); } @@ -258,7 +258,7 @@ public class TravelObfHelper implements TravelHelper { if (color != null) { wptPt.setColor(ColorDialogs.getColorByTag(color)); } - String iconName = amenity.getIcon(); + String iconName = amenity.getGpxIcon(); if (iconName != null) { wptPt.setIconName(iconName); } @@ -284,7 +284,7 @@ public class TravelObfHelper implements TravelHelper { for (BinaryMapIndexReader reader : getReaders()) { try { SearchRequest searchRequest = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, searchQuery, - 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, getSearchRouteArticleFilter(), new ResultMatcher() { + 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, getSearchFilter(false), new ResultMatcher() { @Override public boolean publish(Amenity object) { List otherNames = object.getAllNames(false); @@ -313,7 +313,7 @@ public class TravelObfHelper implements TravelHelper { for (Amenity amenity : entry.getValue()) { Set nameLangs = getLanguages(amenity); if (nameLangs.contains(appLang)) { - TravelArticle article = readArticle(file, amenity, appLang); + TravelArticle article = readArticle(file, amenity, appLang, false); ArrayList langs = new ArrayList<>(nameLangs); Collections.sort(langs, new Comparator() { @Override @@ -367,7 +367,7 @@ public class TravelObfHelper implements TravelHelper { Collections.sort(list, new Comparator() { @Override public int compare(WikivoyageSearchResult res1, WikivoyageSearchResult res2) { - return collator.compare(res1.articleId.title, res2.articleId.title); + return collator.compare(res1.articleTitle, res2.articleTitle); } }); } @@ -407,7 +407,7 @@ public class TravelObfHelper implements TravelHelper { for (BinaryMapIndexReader reader : getReaders()) { try { SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest(0, - Integer.MAX_VALUE, 0, Integer.MAX_VALUE, -1, getSearchRouteArticleFilter(), new ResultMatcher() { + Integer.MAX_VALUE, 0, Integer.MAX_VALUE, -1, getSearchFilter(false), new ResultMatcher() { @Override public boolean publish(Amenity amenity) { @@ -450,7 +450,7 @@ public class TravelObfHelper implements TravelHelper { for (Amenity amenity : entry.getValue()) { Set nameLangs = getLanguages(amenity); if (nameLangs.contains(lang)) { - TravelArticle a = readArticle(file, amenity, lang); + TravelArticle a = readArticle(file, amenity, lang, false); WikivoyageSearchResult rs = new WikivoyageSearchResult(a, new ArrayList<>(nameLangs)); List l = navMap.get(rs.isPartOf); if (l == null) { @@ -487,12 +487,12 @@ public class TravelObfHelper implements TravelHelper { @Override public TravelArticle getArticleById(@NonNull TravelArticleIdentifier articleId, @NonNull String lang) { - TravelArticle article = getCachedArticle(articleId, lang); + TravelArticle article = getCachedArticle(articleId, lang, true); return article == null ? localDataHelper.getSavedArticle(articleId.file, articleId.routeId, lang) : article; } @Nullable - private TravelArticle getCachedArticle(@NonNull TravelArticleIdentifier articleId, @NonNull String lang) { + private TravelArticle getCachedArticle(@NonNull TravelArticleIdentifier articleId, @NonNull String lang, boolean forceReadPoints) { TravelArticle article = null; Map articles = cachedArticles.get(articleId); if (articles != null) { @@ -508,54 +508,45 @@ public class TravelObfHelper implements TravelHelper { } } } - return article == null ? findArticleById(articleId, lang) : article; + if (article == null) { + article = findArticleById(articleId, lang); + } + if (article != null && !article.gpxFileRead && forceReadPoints) { + article.gpxFile = buildGpxFile(article); + article.gpxFileRead = true; + } + return article; } private TravelArticle findArticleById(@NonNull final TravelArticleIdentifier articleId, final String lang) { TravelArticle article = null; - final boolean isDbArticle = articleId.file != null && articleId.file.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT); - final List amenities = new ArrayList<>(); + boolean isDbArticle = articleId.file != null && articleId.file.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT); + List amenities = null; for (BinaryMapIndexReader reader : getReaders()) { try { if (articleId.file != null && !articleId.file.equals(reader.getFile()) && !isDbArticle) { continue; } SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, - Algorithms.emptyIfNull(articleId.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, - getSearchRouteArticleFilter(), new ResultMatcher() { - boolean done = false; - - @Override - public boolean publish(Amenity amenity) { - if (Algorithms.stringsEqual(articleId.routeId, Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID, null))) - && Algorithms.stringsEqual(articleId.routeSource, Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_SOURCE, null))) || isDbArticle) { - amenities.add(amenity); - done = true; - } - return false; - } - - @Override - public boolean isCancelled() { - return done; - } - }, null); + Algorithms.emptyIfNull(articleId.routeId), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, + getSearchFilter(false), null, null); + req.setLimit(1); if (!Double.isNaN(articleId.lat)) { req.setBBoxRadius(articleId.lat, articleId.lon, ARTICLE_SEARCH_RADIUS); - if (!Algorithms.isEmpty(articleId.title)) { - reader.searchPoiByName(req); + if (!Algorithms.isEmpty(articleId.routeId)) { + amenities = reader.searchPoiByName(req); } else { - reader.searchPoi(req); + amenities = reader.searchPoi(req); } } else { - reader.searchPoi(req); + amenities = reader.searchPoi(req); } } catch (IOException e) { LOG.error(e.getMessage()); } if (!Algorithms.isEmpty(amenities)) { - article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang); + article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang, true); } } return article; @@ -570,7 +561,7 @@ public class TravelObfHelper implements TravelHelper { @Nullable @Override public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull LatLon latLon, @NonNull final String lang) { - QuadRect rect = latLon != null ? MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), ARTICLE_SEARCH_RADIUS) : new QuadRect(); + QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), ARTICLE_SEARCH_RADIUS); return getArticleByTitle(title, rect, lang); } @@ -596,13 +587,14 @@ public class TravelObfHelper implements TravelHelper { for (BinaryMapIndexReader reader : getReaders()) { try { SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest( - x, y, title, left, right, top, bottom, getSearchRouteArticleFilter(), null, null); + x, y, title, left, right, top, bottom, getSearchFilter(false), null, null); + req.setLimit(1); amenities = reader.searchPoiByName(req); } catch (IOException e) { LOG.error(e.getMessage()); } if (!Algorithms.isEmpty(amenities)) { - article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang); + article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang, true); } } return article; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageSearchResult.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageSearchResult.java index 5482bfee6c..e67fea4eaa 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageSearchResult.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageSearchResult.java @@ -15,6 +15,7 @@ public class WikivoyageSearchResult { TravelArticleIdentifier articleId; + String articleTitle; String imageTitle; String isPartOf; @@ -32,8 +33,7 @@ public class WikivoyageSearchResult { public WikivoyageSearchResult(String routeId, String articleTitle, String isPartOf, String imageTitle, @Nullable List langs) { TravelArticle article = new TravelArticle(); article.routeId = routeId; - article.title = articleTitle; - + this.articleTitle = articleTitle; this.articleId = article.generateIdentifier(); this.imageTitle = imageTitle; this.isPartOf = isPartOf; @@ -47,7 +47,7 @@ public class WikivoyageSearchResult { } public String getArticleTitle() { - return articleId.title; + return articleTitle; } public String getArticleRouteId() {