From d7a12127053c04a89803766679499ceeeadf9bb7 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 18 Dec 2020 13:01:49 +0200 Subject: [PATCH] Add RouteArticleFilter --- .../plus/wikivoyage/data/TravelObfHelper.java | 52 ++++++++----------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 65f45001da..c760baa04b 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -12,6 +12,7 @@ import net.osmand.ResultMatcher; import net.osmand.binary.BinaryMapIndexReader; import net.osmand.data.Amenity; import net.osmand.data.LatLon; +import net.osmand.osm.PoiCategory; import net.osmand.plus.OsmandApplication; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -28,7 +29,6 @@ import java.util.List; import java.util.Map; import static net.osmand.CollatorStringMatcher.StringMatcherMode.*; -import static net.osmand.binary.BinaryMapIndexReader.ACCEPT_ALL_POI_TYPE_FILTER; public class TravelObfHelper implements TravelHelper { @@ -67,33 +67,13 @@ public class TravelObfHelper implements TravelHelper { public List loadPopularArticles() { String language = app.getLanguage(); popularArticles.clear(); - final List amenities = new ArrayList<>(); + List amenities; for (BinaryMapIndexReader travelBookReader : getTravelBookReaders()) { try { - if (travelBookReader == null) { - popularArticles = new ArrayList<>(); - return popularArticles; - } final LatLon location = app.getMapViewTrackingUtilities().getMapLocation(); - BinaryMapIndexReader.SearchRequest req = - BinaryMapIndexReader.buildSearchPoiRequest(location, SEARCH_RADIUS, -1, - ACCEPT_ALL_POI_TYPE_FILTER, - new ResultMatcher() { - @Override - public boolean publish(Amenity amenity) { - if (amenity.getSubType().equals(ROUTE_ARTICLE)) { - amenities.add(amenity); - } - return false; - } - - @Override - public boolean isCancelled() { - return false; - } - }); - travelBookReader.searchPoi(req); - + BinaryMapIndexReader.SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest( + location, SEARCH_RADIUS, -1, getSearchRouteArticleFilter(), null); + amenities = travelBookReader.searchPoi(req); if (amenities.size() > 0) { for (Amenity a : amenities) { if (!Algorithms.isEmpty(a.getName(language))) { @@ -116,7 +96,6 @@ public class TravelObfHelper implements TravelHelper { } }); } - } catch (Exception e) { LOG.error(e.getMessage()); } @@ -124,6 +103,20 @@ public class TravelObfHelper implements TravelHelper { return popularArticles; } + BinaryMapIndexReader.SearchPoiTypeFilter getSearchRouteArticleFilter() { + return new BinaryMapIndexReader.SearchPoiTypeFilter() { + @Override + public boolean accept(PoiCategory type, String subcategory) { + return subcategory.equals(ROUTE_ARTICLE); + } + + @Override + public boolean isEmpty() { + return false; + } + }; + } + private TravelArticle readArticle(Amenity amenity, String lang) { TravelArticle res = new TravelArticle(); res.title = Algorithms.isEmpty(amenity.getName(lang)) ? amenity.getName() : amenity.getName(lang); @@ -191,12 +184,11 @@ public class TravelObfHelper implements TravelHelper { int top = 0; int bottom = Integer.MAX_VALUE; BinaryMapIndexReader.SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest( - left, right, top, bottom, -1, ACCEPT_ALL_POI_TYPE_FILTER, + left, right, top, bottom, -1, getSearchRouteArticleFilter(), new ResultMatcher() { @Override public boolean publish(Amenity amenity) { - if (amenity.getSubType().equals(ROUTE_ARTICLE) - && getRouteId(amenity).equals(routeId)) { + if (getRouteId(amenity).equals(routeId)) { amenities.add(amenity); } return false; @@ -208,7 +200,7 @@ public class TravelObfHelper implements TravelHelper { } }); - travelBookReader.searchPoiByName(req); + travelBookReader.searchPoi(req); } catch (IOException e) { LOG.error(e.getMessage()); }