From 3cf65218b25e511477a12a7d6ab54a9138a7b5aa Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 11 Feb 2021 23:58:19 +0200 Subject: [PATCH 1/4] Fix bookmarks --- .../plus/wikivoyage/data/TravelObfHelper.java | 177 ++++++++++++++---- 1 file changed, 143 insertions(+), 34 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 2d76743c65..67fee65a9d 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -70,6 +70,7 @@ public class TravelObfHelper implements TravelHelper { public static final String ROUTE_ARTICLE_POINT = "route_article_point"; public static final String ROUTE_TRACK = "route_track"; public static final int ARTICLE_SEARCH_RADIUS = 50000; + public static final int SAVED_ARTICLE_SEARCH_RADIUS = 30000; public static final int MAX_POPULAR_ARTICLES_COUNT = 30; public static final String REF_TAG = "ref"; public static final String NAME_TAG = "name"; @@ -240,6 +241,24 @@ public class TravelObfHelper implements TravelHelper { }; } + @NonNull + private SearchPoiTypeFilter getSubcategoriesSearchFilter(final String... filterSubcategory) { + return new SearchPoiTypeFilter() { + @Override + public boolean accept(PoiCategory type, String subcategory) { + for (String filterSubcategory : filterSubcategory) { + return subcategory.equals(filterSubcategory); + } + return false; + } + + @Override + public boolean isEmpty() { + return false; + } + }; + } + @NonNull private Map readArticles(@NonNull File file, @NonNull Amenity amenity) { Map articles = new HashMap<>(); @@ -681,55 +700,145 @@ public class TravelObfHelper implements TravelHelper { private synchronized TravelArticle findArticleById(@NonNull final TravelArticleIdentifier articleId, final String lang, boolean readGpx, @Nullable GpxReadCallback callback) { + final List> amenities = new ArrayList<>(); TravelArticle article = 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()) { + SearchRequest req = null; + for (final BinaryMapIndexReader reader : getReaders()) { try { - if (articleId.file != null && !articleId.file.equals(reader.getFile()) && !isDbArticle) { - continue; + if (articleId.file != null && articleId.file.equals(reader.getFile())) { + if (articleId.file.lastModified() == reader.getFile().lastModified()) { + req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, + Algorithms.emptyIfNull(articleId.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, + getSubcategoriesSearchFilter(ROUTE_ARTICLE, ROUTE_TRACK), new ResultMatcher() { + boolean done = false; + + @Override + public boolean publish(Amenity amenity) { + if (Algorithms.stringsEqual(articleId.routeId, + Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID)))) { + amenities.add(new Pair<>(reader.getFile(), amenity)); + done = true; + } + return false; + } + + @Override + public boolean isCancelled() { + return done; + } + }, null); + req.setBBoxRadius(articleId.lat, articleId.lon, ARTICLE_SEARCH_RADIUS); + } else { + req = getEqualsTitleRequest(articleId, lang, amenities, reader); + req.setBBoxRadius(articleId.lat, articleId.lon, ARTICLE_SEARCH_RADIUS / 10); + } } - SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, - Algorithms.emptyIfNull(articleId.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, - getSearchFilter(ROUTE_ARTICLE), new ResultMatcher() { - boolean done = false; - - @Override - public boolean publish(Amenity amenity) { - if (Algorithms.stringsEqual(articleId.routeId, - Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID))) || isDbArticle) { - amenities.add(amenity); - done = true; - } - return false; - } - - @Override - public boolean isCancelled() { - return done; - } - }, null); - - if (!Double.isNaN(articleId.lat)) { - req.setBBoxRadius(articleId.lat, articleId.lon, ARTICLE_SEARCH_RADIUS); - if (!Algorithms.isEmpty(articleId.title)) { - reader.searchPoiByName(req); + if (req != null) { + if (!Double.isNaN(articleId.lat)) { + if (!Algorithms.isEmpty(articleId.title)) { + reader.searchPoiByName(req); + } else { + reader.searchPoi(req); + } } else { reader.searchPoi(req); } - } else { - reader.searchPoi(req); + break; } } catch (IOException e) { LOG.error(e.getMessage()); } - if (!Algorithms.isEmpty(amenities)) { - article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang, readGpx, callback); + } + if (amenities.isEmpty()) { + for (BinaryMapIndexReader reader : getReaders()) { + try { + req = getEqualsTitleRequest(articleId, lang, amenities, reader); + req.setBBoxRadius(articleId.lat, articleId.lon, SAVED_ARTICLE_SEARCH_RADIUS); + if (!Double.isNaN(articleId.lat)) { + if (!Algorithms.isEmpty(articleId.title)) { + reader.searchPoiByName(req); + } else { + reader.searchPoi(req); + } + } else { + reader.searchPoi(req); + } + } catch (IOException e) { + LOG.error(e.getMessage()); + } } } + if (amenities.isEmpty()) { + for (final BinaryMapIndexReader reader : getReaders()) { + try { + req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, + Algorithms.emptyIfNull(articleId.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, + getSubcategoriesSearchFilter(ROUTE_ARTICLE, ROUTE_TRACK), new ResultMatcher() { + boolean done = false; + + @Override + public boolean publish(Amenity amenity) { + if (Algorithms.stringsEqual(articleId.routeId, + Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID))) + && Algorithms.stringsEqual(articleId.routeSource, + Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_SOURCE)))) { + amenities.add(new Pair<>(reader.getFile(), amenity)); + done = true; + } + return false; + } + + @Override + public boolean isCancelled() { + return done; + } + }, null); + req.setBBoxRadius(articleId.lat, articleId.lon, SAVED_ARTICLE_SEARCH_RADIUS); + if (!Double.isNaN(articleId.lat)) { + if (!Algorithms.isEmpty(articleId.title)) { + reader.searchPoiByName(req); + } else { + reader.searchPoi(req); + } + } else { + reader.searchPoi(req); + } + } catch (IOException e) { + LOG.error(e.getMessage()); + } + } + } + if (!Algorithms.isEmpty(amenities)) { + article = cacheTravelArticles(amenities.get(0).first, amenities.get(0).second, lang, readGpx, callback); + } return article; } + private SearchRequest getEqualsTitleRequest(@NonNull final TravelArticleIdentifier articleId, + final String lang, final List> amenities, + final BinaryMapIndexReader reader) { + return BinaryMapIndexReader.buildSearchPoiRequest(0, 0, + Algorithms.emptyIfNull(articleId.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, + getSubcategoriesSearchFilter(ROUTE_ARTICLE, ROUTE_TRACK), new ResultMatcher() { + boolean done = false; + + @Override + public boolean publish(Amenity amenity) { + if (Algorithms.stringsEqual(Algorithms.emptyIfNull(articleId.title), + Algorithms.emptyIfNull(amenity.getName(lang)))) { + amenities.add(new Pair<>(reader.getFile(), amenity)); + done = true; + } + return false; + } + + @Override + public boolean isCancelled() { + return done; + } + }, null); + } + @Nullable @Override public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull final String lang, From 06a85035ccffacc4c2fba548327c5c009445c556 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 12 Feb 2021 13:07:15 +0200 Subject: [PATCH 2/4] Fix bookmarks --- .../plus/wikivoyage/data/TravelDbHelper.java | 6 ++++ .../plus/wikivoyage/data/TravelHelper.java | 3 ++ .../data/TravelLocalDataHelper.java | 8 ++--- .../plus/wikivoyage/data/TravelObfHelper.java | 29 +++++++++++++++---- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java index 0fc6c232f9..68595ea71e 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java @@ -605,6 +605,12 @@ public class TravelDbHelper implements TravelHelper { return res; } + @Override + public TravelArticle checkExistedArticle(@Nullable TravelArticle article, @Nullable TravelArticleIdentifier articleId, + @Nullable String lang, boolean readGpx, @Nullable GpxReadCallback callback) { + return article; + } + @Nullable @Override public TravelArticleIdentifier getArticleId(@NonNull String title, @NonNull String lang) { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java index 7e89431690..0f822cac66 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java @@ -41,6 +41,9 @@ public interface TravelHelper { @Nullable TravelArticle getArticleById(@NonNull TravelArticleIdentifier articleId, @Nullable String lang, boolean readGpx, @Nullable GpxReadCallback callback); + @Nullable + TravelArticle checkExistedArticle(@Nullable TravelArticle article,@Nullable TravelArticleIdentifier articleId, @Nullable String lang, boolean readGpx, @Nullable GpxReadCallback callback); + @Nullable TravelArticle getArticleByTitle(@NonNull String title, @NonNull String lang, boolean readGpx, @Nullable GpxReadCallback callback); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java index d95b9239ee..7e073570ff 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java @@ -1,9 +1,5 @@ package net.osmand.plus.wikivoyage.data; - -import android.database.DatabaseUtils; -import android.database.sqlite.SQLiteDatabase; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -428,7 +424,9 @@ public class TravelLocalDataHelper { if (cursor.moveToFirst()) { do { TravelArticle dbArticle = readSavedArticle(cursor); - TravelArticle article = context.getTravelHelper().getArticleById(dbArticle.generateIdentifier(), dbArticle.lang, false, null); + dbArticle.generateIdentifier(); + TravelArticle article = context.getTravelHelper().checkExistedArticle(dbArticle, + null,null, false, null); if (article != null && article.getLastModified() > dbArticle.getLastModified()) { updateSavedArticle(dbArticle, article); res.add(article); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 67fee65a9d..53cee47524 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -698,15 +698,32 @@ public class TravelObfHelper implements TravelHelper { } } - private synchronized TravelArticle findArticleById(@NonNull final TravelArticleIdentifier articleId, - final String lang, boolean readGpx, @Nullable GpxReadCallback callback) { + private synchronized TravelArticle findArticleById(@NonNull TravelArticleIdentifier articleId, + String lang, boolean readGpx, @Nullable GpxReadCallback callback) { + return checkExistedArticle(null, articleId, lang, readGpx, callback); + } + + @Override + public synchronized TravelArticle checkExistedArticle(@Nullable TravelArticle checkedArticle, + @Nullable TravelArticleIdentifier articleId, + @Nullable String lang, boolean readGpx, @Nullable GpxReadCallback callback) { final List> amenities = new ArrayList<>(); TravelArticle article = null; + long lastModified; + if (checkedArticle != null) { + articleId = checkedArticle.generateIdentifier(); + lang = checkedArticle.getLang(); + lastModified = checkedArticle.getLastModified(); + } else { + lastModified = articleId.file.lastModified(); + } + final TravelArticleIdentifier finalArticleId = articleId; SearchRequest req = null; for (final BinaryMapIndexReader reader : getReaders()) { try { if (articleId.file != null && articleId.file.equals(reader.getFile())) { - if (articleId.file.lastModified() == reader.getFile().lastModified()) { + if (lastModified == reader.getFile().lastModified()) { + req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, Algorithms.emptyIfNull(articleId.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, getSubcategoriesSearchFilter(ROUTE_ARTICLE, ROUTE_TRACK), new ResultMatcher() { @@ -714,7 +731,7 @@ public class TravelObfHelper implements TravelHelper { @Override public boolean publish(Amenity amenity) { - if (Algorithms.stringsEqual(articleId.routeId, + if (Algorithms.stringsEqual(finalArticleId.routeId, Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID)))) { amenities.add(new Pair<>(reader.getFile(), amenity)); done = true; @@ -778,9 +795,9 @@ public class TravelObfHelper implements TravelHelper { @Override public boolean publish(Amenity amenity) { - if (Algorithms.stringsEqual(articleId.routeId, + if (Algorithms.stringsEqual(finalArticleId.routeId, Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID))) - && Algorithms.stringsEqual(articleId.routeSource, + && Algorithms.stringsEqual(finalArticleId.routeSource, Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_SOURCE)))) { amenities.add(new Pair<>(reader.getFile(), amenity)); done = true; From 76e1708058899f4e41eda8e4046cc71b94d20ff9 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 12 Feb 2021 13:59:11 +0200 Subject: [PATCH 3/4] Fix bookmarks --- .../plus/wikivoyage/data/TravelDbHelper.java | 5 +- .../plus/wikivoyage/data/TravelHelper.java | 2 +- .../data/TravelLocalDataHelper.java | 4 +- .../plus/wikivoyage/data/TravelObfHelper.java | 102 +++++++++++------- 4 files changed, 67 insertions(+), 46 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java index 68595ea71e..627f6d7945 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java @@ -606,9 +606,8 @@ public class TravelDbHelper implements TravelHelper { } @Override - public TravelArticle checkExistedArticle(@Nullable TravelArticle article, @Nullable TravelArticleIdentifier articleId, - @Nullable String lang, boolean readGpx, @Nullable GpxReadCallback callback) { - return article; + public TravelArticle findSavedArticle(@NonNull TravelArticle savedArticle) { + return savedArticle; } @Nullable diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java index 0f822cac66..0cde849fbf 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java @@ -42,7 +42,7 @@ public interface TravelHelper { TravelArticle getArticleById(@NonNull TravelArticleIdentifier articleId, @Nullable String lang, boolean readGpx, @Nullable GpxReadCallback callback); @Nullable - TravelArticle checkExistedArticle(@Nullable TravelArticle article,@Nullable TravelArticleIdentifier articleId, @Nullable String lang, boolean readGpx, @Nullable GpxReadCallback callback); + TravelArticle findSavedArticle(@NonNull TravelArticle savedArticle); @Nullable TravelArticle getArticleByTitle(@NonNull String title, @NonNull String lang, boolean readGpx, @Nullable GpxReadCallback callback); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java index 7e073570ff..928571f584 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java @@ -424,9 +424,7 @@ public class TravelLocalDataHelper { if (cursor.moveToFirst()) { do { TravelArticle dbArticle = readSavedArticle(cursor); - dbArticle.generateIdentifier(); - TravelArticle article = context.getTravelHelper().checkExistedArticle(dbArticle, - null,null, false, null); + TravelArticle article = context.getTravelHelper().findSavedArticle(dbArticle); if (article != null && article.getLastModified() > dbArticle.getLastModified()) { updateSavedArticle(dbArticle, article); res.add(article); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 53cee47524..176a1dc7c8 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -227,22 +227,7 @@ public class TravelObfHelper implements TravelHelper { } @NonNull - private SearchPoiTypeFilter getSearchFilter(final String filterSubcategory) { - return new SearchPoiTypeFilter() { - @Override - public boolean accept(PoiCategory type, String subcategory) { - return subcategory.equals(filterSubcategory); - } - - @Override - public boolean isEmpty() { - return false; - } - }; - } - - @NonNull - private SearchPoiTypeFilter getSubcategoriesSearchFilter(final String... filterSubcategory) { + private SearchPoiTypeFilter getSearchFilter(final String... filterSubcategory) { return new SearchPoiTypeFilter() { @Override public boolean accept(PoiCategory type, String subcategory) { @@ -698,25 +683,64 @@ public class TravelObfHelper implements TravelHelper { } } - private synchronized TravelArticle findArticleById(@NonNull TravelArticleIdentifier articleId, - String lang, boolean readGpx, @Nullable GpxReadCallback callback) { - return checkExistedArticle(null, articleId, lang, readGpx, callback); + private synchronized TravelArticle findArticleById(@NonNull final TravelArticleIdentifier articleId, + String lang, boolean readGpx, @Nullable GpxReadCallback callback) { + TravelArticle article = 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.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, + getSearchFilter(ROUTE_ARTICLE), new ResultMatcher() { + boolean done = false; + + @Override + public boolean publish(Amenity amenity) { + if (Algorithms.stringsEqual(articleId.routeId, + Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID))) || isDbArticle) { + amenities.add(amenity); + done = true; + } + return false; + } + + @Override + public boolean isCancelled() { + return done; + } + }, null); + + if (!Double.isNaN(articleId.lat)) { + req.setBBoxRadius(articleId.lat, articleId.lon, ARTICLE_SEARCH_RADIUS); + if (!Algorithms.isEmpty(articleId.title)) { + reader.searchPoiByName(req); + } else { + reader.searchPoi(req); + } + } else { + reader.searchPoi(req); + } + } catch (IOException e) { + LOG.error(e.getMessage()); + } + if (!Algorithms.isEmpty(amenities)) { + article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang, readGpx, callback); + } + } + return article; } @Override - public synchronized TravelArticle checkExistedArticle(@Nullable TravelArticle checkedArticle, - @Nullable TravelArticleIdentifier articleId, - @Nullable String lang, boolean readGpx, @Nullable GpxReadCallback callback) { + public synchronized TravelArticle findSavedArticle(@NonNull TravelArticle savedArticle) { final List> amenities = new ArrayList<>(); TravelArticle article = null; - long lastModified; - if (checkedArticle != null) { - articleId = checkedArticle.generateIdentifier(); - lang = checkedArticle.getLang(); - lastModified = checkedArticle.getLastModified(); - } else { - lastModified = articleId.file.lastModified(); - } + TravelArticleIdentifier articleId = savedArticle.generateIdentifier(); + String lang = savedArticle.getLang(); + long lastModified = savedArticle.getLastModified(); final TravelArticleIdentifier finalArticleId = articleId; SearchRequest req = null; for (final BinaryMapIndexReader reader : getReaders()) { @@ -726,7 +750,7 @@ public class TravelObfHelper implements TravelHelper { req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, Algorithms.emptyIfNull(articleId.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, - getSubcategoriesSearchFilter(ROUTE_ARTICLE, ROUTE_TRACK), new ResultMatcher() { + getSearchFilter(ROUTE_ARTICLE, ROUTE_TRACK), new ResultMatcher() { boolean done = false; @Override @@ -790,7 +814,7 @@ public class TravelObfHelper implements TravelHelper { try { req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, Algorithms.emptyIfNull(articleId.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, - getSubcategoriesSearchFilter(ROUTE_ARTICLE, ROUTE_TRACK), new ResultMatcher() { + getSearchFilter(ROUTE_ARTICLE, ROUTE_TRACK), new ResultMatcher() { boolean done = false; @Override @@ -826,17 +850,17 @@ public class TravelObfHelper implements TravelHelper { } } if (!Algorithms.isEmpty(amenities)) { - article = cacheTravelArticles(amenities.get(0).first, amenities.get(0).second, lang, readGpx, callback); + article = cacheTravelArticles(amenities.get(0).first, amenities.get(0).second, lang, false, null); } return article; } private SearchRequest getEqualsTitleRequest(@NonNull final TravelArticleIdentifier articleId, - final String lang, final List> amenities, - final BinaryMapIndexReader reader) { + final String lang, final List> amenities, + final BinaryMapIndexReader reader) { return BinaryMapIndexReader.buildSearchPoiRequest(0, 0, Algorithms.emptyIfNull(articleId.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, - getSubcategoriesSearchFilter(ROUTE_ARTICLE, ROUTE_TRACK), new ResultMatcher() { + getSearchFilter(ROUTE_ARTICLE, ROUTE_TRACK), new ResultMatcher() { boolean done = false; @Override @@ -859,14 +883,14 @@ public class TravelObfHelper implements TravelHelper { @Nullable @Override public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull final String lang, - boolean readGpx, @Nullable GpxReadCallback callback) { + boolean readGpx, @Nullable GpxReadCallback callback) { return getArticleByTitle(title, new QuadRect(), lang, readGpx, callback); } @Nullable @Override public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull LatLon latLon, - @NonNull final String lang, boolean readGpx, @Nullable GpxReadCallback callback) { + @NonNull final String lang, boolean readGpx, @Nullable GpxReadCallback callback) { QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), ARTICLE_SEARCH_RADIUS); return getArticleByTitle(title, rect, lang, readGpx, callback); } @@ -874,7 +898,7 @@ public class TravelObfHelper implements TravelHelper { @Nullable @Override public synchronized TravelArticle getArticleByTitle(@NonNull final String title, @NonNull QuadRect rect, - @NonNull final String lang, boolean readGpx, @Nullable GpxReadCallback callback) { + @NonNull final String lang, boolean readGpx, @Nullable GpxReadCallback callback) { TravelArticle article = null; final List amenities = new ArrayList<>(); int x = 0; From 4a0eab97a189ba75fe19f68abca93d96e57d9f49 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 12 Feb 2021 17:23:08 +0200 Subject: [PATCH 4/4] Fix empty names --- .../plus/wikivoyage/data/TravelObfHelper.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 176a1dc7c8..fc59ae3daf 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -747,7 +747,6 @@ public class TravelObfHelper implements TravelHelper { try { if (articleId.file != null && articleId.file.equals(reader.getFile())) { if (lastModified == reader.getFile().lastModified()) { - req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, Algorithms.emptyIfNull(articleId.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, getSearchFilter(ROUTE_ARTICLE, ROUTE_TRACK), new ResultMatcher() { @@ -770,8 +769,10 @@ public class TravelObfHelper implements TravelHelper { }, null); req.setBBoxRadius(articleId.lat, articleId.lon, ARTICLE_SEARCH_RADIUS); } else { - req = getEqualsTitleRequest(articleId, lang, amenities, reader); - req.setBBoxRadius(articleId.lat, articleId.lon, ARTICLE_SEARCH_RADIUS / 10); + if (!Algorithms.isEmpty(articleId.title)) { + req = getEqualsTitleRequest(articleId, lang, amenities, reader); + req.setBBoxRadius(articleId.lat, articleId.lon, ARTICLE_SEARCH_RADIUS / 10); + } } } if (req != null) { @@ -790,17 +791,13 @@ public class TravelObfHelper implements TravelHelper { LOG.error(e.getMessage()); } } - if (amenities.isEmpty()) { + if (amenities.isEmpty() && !Algorithms.isEmpty(articleId.title)) { for (BinaryMapIndexReader reader : getReaders()) { try { req = getEqualsTitleRequest(articleId, lang, amenities, reader); req.setBBoxRadius(articleId.lat, articleId.lon, SAVED_ARTICLE_SEARCH_RADIUS); if (!Double.isNaN(articleId.lat)) { - if (!Algorithms.isEmpty(articleId.title)) { - reader.searchPoiByName(req); - } else { - reader.searchPoi(req); - } + reader.searchPoiByName(req); } else { reader.searchPoi(req); }