Revert some changes of travel obf

This commit is contained in:
max-klaus 2021-01-10 15:24:52 +03:00
parent 75e5f7828a
commit ce256d1994
3 changed files with 37 additions and 15 deletions

View file

@ -171,6 +171,7 @@ public class TravelArticle {
@Nullable File file; @Nullable File file;
double lat; double lat;
double lon; double lon;
@Nullable String title;
@Nullable String routeId; @Nullable String routeId;
@Nullable String routeSource; @Nullable String routeSource;
@ -194,6 +195,7 @@ public class TravelArticle {
file = article.file; file = article.file;
lat = article.lat; lat = article.lat;
lon = article.lon; lon = article.lon;
title = article.title;
routeId = article.routeId; routeId = article.routeId;
routeSource = article.routeSource; routeSource = article.routeSource;
} }
@ -202,6 +204,7 @@ public class TravelArticle {
public void writeToParcel(Parcel out, int flags) { public void writeToParcel(Parcel out, int flags) {
out.writeDouble(lat); out.writeDouble(lat);
out.writeDouble(lon); out.writeDouble(lon);
out.writeString(title);
out.writeString(routeId); out.writeString(routeId);
out.writeString(routeSource); out.writeString(routeSource);
out.writeString(file != null ? file.getAbsolutePath() : null); out.writeString(file != null ? file.getAbsolutePath() : null);
@ -210,6 +213,7 @@ public class TravelArticle {
private void readFromParcel(Parcel in) { private void readFromParcel(Parcel in) {
lat = in.readDouble(); lat = in.readDouble();
lon = in.readDouble(); lon = in.readDouble();
title = in.readString();
routeId = in.readString(); routeId = in.readString();
routeSource = in.readString(); routeSource = in.readString();
String filePath = in.readString(); String filePath = in.readString();

View file

@ -62,7 +62,7 @@ public class TravelObfHelper implements TravelHelper {
private final Collator collator; private final Collator collator;
private List<TravelArticle> popularArticles = new ArrayList<>(); private List<TravelArticle> popularArticles = new ArrayList<>();
private Map<TravelArticleIdentifier, Map<String, TravelArticle>> cachedArticles = new ConcurrentHashMap<>(); private final Map<TravelArticleIdentifier, Map<String, TravelArticle>> cachedArticles = new ConcurrentHashMap<>();
private final TravelLocalDataHelper localDataHelper; private final TravelLocalDataHelper localDataHelper;
public TravelObfHelper(OsmandApplication app) { public TravelObfHelper(OsmandApplication app) {
@ -211,13 +211,15 @@ public class TravelObfHelper implements TravelHelper {
continue; continue;
} }
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0,
Algorithms.emptyIfNull(article.routeId), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, Algorithms.emptyIfNull(article.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE,
getSearchFilter(false), new ResultMatcher<Amenity>() { getSearchFilter(true), new ResultMatcher<Amenity>() {
@Override @Override
public boolean publish(Amenity amenity) { public boolean publish(Amenity amenity) {
String amenityLang = amenity.getTagSuffix(Amenity.LANG_YES + ":"); 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); pointList.add(amenity);
} }
return false; return false;
@ -367,7 +369,7 @@ public class TravelObfHelper implements TravelHelper {
Collections.sort(list, new Comparator<WikivoyageSearchResult>() { Collections.sort(list, new Comparator<WikivoyageSearchResult>() {
@Override @Override
public int compare(WikivoyageSearchResult res1, WikivoyageSearchResult res2) { 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) { private TravelArticle findArticleById(@NonNull final TravelArticleIdentifier articleId, final String lang) {
TravelArticle article = null; TravelArticle article = null;
boolean isDbArticle = articleId.file != null && articleId.file.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT); final boolean isDbArticle = articleId.file != null && articleId.file.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT);
List<Amenity> amenities = null; final List<Amenity> amenities = new ArrayList<>();
for (BinaryMapIndexReader reader : getReaders()) { for (BinaryMapIndexReader reader : getReaders()) {
try { try {
if (articleId.file != null && !articleId.file.equals(reader.getFile()) && !isDbArticle) { if (articleId.file != null && !articleId.file.equals(reader.getFile()) && !isDbArticle) {
continue; continue;
} }
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0,
Algorithms.emptyIfNull(articleId.routeId), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, Algorithms.emptyIfNull(articleId.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE,
getSearchFilter(false), null, null); getSearchFilter(false), new ResultMatcher<Amenity>() {
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)) { if (!Double.isNaN(articleId.lat)) {
req.setBBoxRadius(articleId.lat, articleId.lon, ARTICLE_SEARCH_RADIUS); req.setBBoxRadius(articleId.lat, articleId.lon, ARTICLE_SEARCH_RADIUS);
if (!Algorithms.isEmpty(articleId.routeId)) { if (!Algorithms.isEmpty(articleId.routeId)) {
amenities = reader.searchPoiByName(req); reader.searchPoiByName(req);
} else { } else {
amenities = reader.searchPoi(req); reader.searchPoi(req);
} }
} else { } else {
amenities = reader.searchPoi(req); reader.searchPoi(req);
} }
} catch (IOException e) { } catch (IOException e) {
LOG.error(e.getMessage()); LOG.error(e.getMessage());

View file

@ -33,7 +33,7 @@ public class WikivoyageSearchResult {
public WikivoyageSearchResult(String routeId, String articleTitle, String isPartOf, String imageTitle, @Nullable List<String> langs) { public WikivoyageSearchResult(String routeId, String articleTitle, String isPartOf, String imageTitle, @Nullable List<String> langs) {
TravelArticle article = new TravelArticle(); TravelArticle article = new TravelArticle();
article.routeId = routeId; article.routeId = routeId;
this.articleTitle = articleTitle; article.title = articleTitle;
this.articleId = article.generateIdentifier(); this.articleId = article.generateIdentifier();
this.imageTitle = imageTitle; this.imageTitle = imageTitle;
this.isPartOf = isPartOf; this.isPartOf = isPartOf;
@ -47,7 +47,7 @@ public class WikivoyageSearchResult {
} }
public String getArticleTitle() { public String getArticleTitle() {
return articleTitle; return articleId.title;
} }
public String getArticleRouteId() { public String getArticleRouteId() {