From ce256d199479bd85de11f92ccde7cfd4a53f9790 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Sun, 10 Jan 2021 15:24:52 +0300 Subject: [PATCH] Revert some changes of travel obf --- .../plus/wikivoyage/data/TravelArticle.java | 4 ++ .../plus/wikivoyage/data/TravelObfHelper.java | 44 +++++++++++++------ .../data/WikivoyageSearchResult.java | 4 +- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java index 0579af14cc..0989a7c2e1 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java @@ -171,6 +171,7 @@ public class TravelArticle { @Nullable File file; double lat; double lon; + @Nullable String title; @Nullable String routeId; @Nullable String routeSource; @@ -194,6 +195,7 @@ public class TravelArticle { file = article.file; lat = article.lat; lon = article.lon; + title = article.title; routeId = article.routeId; routeSource = article.routeSource; } @@ -202,6 +204,7 @@ 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); @@ -210,6 +213,7 @@ 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(); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index d173e20b47..a224c61e00 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -62,7 +62,7 @@ public class TravelObfHelper implements TravelHelper { private final Collator collator; private List popularArticles = new ArrayList<>(); - private Map> cachedArticles = new ConcurrentHashMap<>(); + private final Map> cachedArticles = new ConcurrentHashMap<>(); private final TravelLocalDataHelper localDataHelper; public TravelObfHelper(OsmandApplication app) { @@ -211,13 +211,15 @@ public class TravelObfHelper implements TravelHelper { continue; } SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, - Algorithms.emptyIfNull(article.routeId), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, - getSearchFilter(false), new ResultMatcher() { + Algorithms.emptyIfNull(article.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, + getSearchFilter(true), new ResultMatcher() { @Override public boolean publish(Amenity amenity) { String amenityLang = amenity.getTagSuffix(Amenity.LANG_YES + ":"); - if (lang.equals(amenityLang)) { + if (lang != null && lang.equals(amenityLang) + && Algorithms.stringsEqual(article.routeId, Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID, null))) + && Algorithms.stringsEqual(article.routeSource, Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_SOURCE, null)))) { pointList.add(amenity); } return false; @@ -367,7 +369,7 @@ public class TravelObfHelper implements TravelHelper { Collections.sort(list, new Comparator() { @Override public int compare(WikivoyageSearchResult res1, WikivoyageSearchResult res2) { - return collator.compare(res1.articleTitle, res2.articleTitle); + return collator.compare(res1.getArticleTitle(), res2.getArticleTitle()); } }); } @@ -520,27 +522,43 @@ public class TravelObfHelper implements TravelHelper { private TravelArticle findArticleById(@NonNull final TravelArticleIdentifier articleId, final String lang) { TravelArticle article = null; - boolean isDbArticle = articleId.file != null && articleId.file.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT); - List amenities = null; + final boolean isDbArticle = articleId.file != null && articleId.file.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT); + final List amenities = new ArrayList<>(); 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.routeId), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, - getSearchFilter(false), null, null); + Algorithms.emptyIfNull(articleId.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, + getSearchFilter(false), 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); - req.setLimit(1); if (!Double.isNaN(articleId.lat)) { req.setBBoxRadius(articleId.lat, articleId.lon, ARTICLE_SEARCH_RADIUS); if (!Algorithms.isEmpty(articleId.routeId)) { - amenities = reader.searchPoiByName(req); + reader.searchPoiByName(req); } else { - amenities = reader.searchPoi(req); + reader.searchPoi(req); } } else { - amenities = reader.searchPoi(req); + reader.searchPoi(req); } } catch (IOException e) { LOG.error(e.getMessage()); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageSearchResult.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageSearchResult.java index e67fea4eaa..595edd34c4 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageSearchResult.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageSearchResult.java @@ -33,7 +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; - this.articleTitle = articleTitle; + article.title = articleTitle; this.articleId = article.generateIdentifier(); this.imageTitle = imageTitle; this.isPartOf = isPartOf; @@ -47,7 +47,7 @@ public class WikivoyageSearchResult { } public String getArticleTitle() { - return articleTitle; + return articleId.title; } public String getArticleRouteId() {