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;
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();

View file

@ -62,7 +62,7 @@ public class TravelObfHelper implements TravelHelper {
private final Collator collator;
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;
public TravelObfHelper(OsmandApplication app) {
@ -211,13 +211,15 @@ public class TravelObfHelper implements TravelHelper {
continue;
}
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0,
Algorithms.emptyIfNull(article.routeId), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE,
getSearchFilter(false), new ResultMatcher<Amenity>() {
Algorithms.emptyIfNull(article.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE,
getSearchFilter(true), new ResultMatcher<Amenity>() {
@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<WikivoyageSearchResult>() {
@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<Amenity> amenities = null;
final boolean isDbArticle = articleId.file != null && articleId.file.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT);
final List<Amenity> amenities = new ArrayList<>();
for (BinaryMapIndexReader reader : getReaders()) {
try {
if (articleId.file != null && !articleId.file.equals(reader.getFile()) && !isDbArticle) {
continue;
}
SearchRequest<Amenity> 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<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)) {
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());

View file

@ -33,7 +33,7 @@ public class WikivoyageSearchResult {
public WikivoyageSearchResult(String routeId, String articleTitle, String isPartOf, String imageTitle, @Nullable List<String> 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() {