Fix gpx reading for travel obf
This commit is contained in:
parent
f62cf097a0
commit
75e5f7828a
9 changed files with 99 additions and 121 deletions
|
@ -1769,6 +1769,10 @@ public class BinaryMapIndexReader {
|
||||||
return limit != -1 && searchResults.size() > limit;
|
return limit != -1 && searchResults.size() > limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLimit(int limit) {
|
||||||
|
this.limit = limit;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
if (this.interrupted) {
|
if (this.interrupted) {
|
||||||
return interrupted;
|
return interrupted;
|
||||||
|
|
|
@ -208,7 +208,7 @@ public class Amenity extends MapObject {
|
||||||
return getAdditionalInfo(COLOR);
|
return getAdditionalInfo(COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIcon() {
|
public String getGpxIcon() {
|
||||||
return getAdditionalInfo(GPX_ICON);
|
return getAdditionalInfo(GPX_ICON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,17 +262,15 @@ public class Amenity extends MapObject {
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTagSuffix(String tagBegin) {
|
public String getTagSuffix(String tagPrefix) {
|
||||||
String tagSuffix = null;
|
|
||||||
for (String infoTag : getAdditionalInfoKeys()) {
|
for (String infoTag : getAdditionalInfoKeys()) {
|
||||||
if (infoTag.startsWith(tagBegin)) {
|
if (infoTag.startsWith(tagPrefix)) {
|
||||||
if (infoTag.length() > tagBegin.length()) {
|
if (infoTag.length() > tagPrefix.length()) {
|
||||||
tagSuffix = infoTag.substring(tagBegin.length());
|
return infoTag.substring(tagPrefix.length());
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tagSuffix;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTagContent(String tag, String lang) {
|
public String getTagContent(String tag, String lang) {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.GPXUtilities;
|
import net.osmand.GPXUtilities;
|
||||||
|
import net.osmand.GPXUtilities.GPXFile;
|
||||||
import net.osmand.GPXUtilities.WptPt;
|
import net.osmand.GPXUtilities.WptPt;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
|
@ -119,7 +120,7 @@ public class WikivoyageWebViewClient extends WebViewClient {
|
||||||
fragmentManager.popBackStackImmediate();
|
fragmentManager.popBackStackImmediate();
|
||||||
|
|
||||||
File path = app.getTravelHelper().createGpxFile(article);
|
File path = app.getTravelHelper().createGpxFile(article);
|
||||||
GPXUtilities.GPXFile gpxFile = article.getGpxFile();
|
GPXFile gpxFile = article.getGpxFile();
|
||||||
gpxFile.path = path.getAbsolutePath();
|
gpxFile.path = path.getAbsolutePath();
|
||||||
app.getSelectedGpxHelper().setGpxFileToDisplay(gpxFile);
|
app.getSelectedGpxHelper().setGpxFileToDisplay(gpxFile);
|
||||||
MapActivity.launchMapActivityMoveToTop(activity);
|
MapActivity.launchMapActivityMoveToTop(activity);
|
||||||
|
|
|
@ -27,6 +27,8 @@ import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentManager.BackStackEntry;
|
import androidx.fragment.app.FragmentManager.BackStackEntry;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.GPXUtilities;
|
||||||
|
import net.osmand.GPXUtilities.GPXFile;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
|
@ -309,10 +311,10 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme
|
||||||
}
|
}
|
||||||
webViewClient.setArticle(article);
|
webViewClient.setArticle(article);
|
||||||
articleToolbarText.setText(article.getTitle());
|
articleToolbarText.setText(article.getTitle());
|
||||||
article.setGpxFile(getMyApplication().getTravelHelper().getGpxFile(article, selectedLang));
|
GPXFile gpxFile = article.getGpxFile();
|
||||||
if (article.getGpxFile() != null && article.getGpxFile().getPointsSize() > 0) {
|
if (gpxFile != null && gpxFile.getPointsSize() > 0) {
|
||||||
trackButton.setVisibility(View.VISIBLE);
|
trackButton.setVisibility(View.VISIBLE);
|
||||||
trackButton.setText(getString(R.string.shared_string_gpx_points) + " (" + article.getGpxFile().getPointsSize() + ")");
|
trackButton.setText(getString(R.string.shared_string_gpx_points) + " (" + gpxFile.getPointsSize() + ")");
|
||||||
} else {
|
} else {
|
||||||
trackButton.setVisibility(View.GONE);
|
trackButton.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ public class TravelArticle {
|
||||||
String aggregatedPartOf;
|
String aggregatedPartOf;
|
||||||
|
|
||||||
long lastModified;
|
long lastModified;
|
||||||
|
boolean gpxFileRead;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public TravelArticleIdentifier generateIdentifier() {
|
public TravelArticleIdentifier generateIdentifier() {
|
||||||
|
@ -98,10 +99,6 @@ public class TravelArticle {
|
||||||
return gpxFile;
|
return gpxFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGpxFile(GPXFile gpxFile) {
|
|
||||||
this.gpxFile = gpxFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRouteId() {
|
public String getRouteId() {
|
||||||
return routeId;
|
return routeId;
|
||||||
}
|
}
|
||||||
|
@ -174,7 +171,6 @@ 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;
|
||||||
|
|
||||||
|
@ -198,7 +194,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -207,7 +202,6 @@ 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);
|
||||||
|
@ -216,7 +210,6 @@ 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();
|
||||||
|
@ -241,14 +234,13 @@ public class TravelArticle {
|
||||||
TravelArticleIdentifier that = (TravelArticleIdentifier) o;
|
TravelArticleIdentifier that = (TravelArticleIdentifier) o;
|
||||||
return areLatLonEqual(that.lat, that.lon, lat, lon) &&
|
return areLatLonEqual(that.lat, that.lon, lat, lon) &&
|
||||||
Algorithms.objectEquals(file, that.file) &&
|
Algorithms.objectEquals(file, that.file) &&
|
||||||
Algorithms.stringsEqual(title, that.title) &&
|
|
||||||
Algorithms.stringsEqual(routeId, that.routeId) &&
|
Algorithms.stringsEqual(routeId, that.routeId) &&
|
||||||
Algorithms.stringsEqual(routeSource, that.routeSource);
|
Algorithms.stringsEqual(routeSource, that.routeSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Algorithms.hash(file, lat, lon, title, routeId, routeSource);
|
return Algorithms.hash(file, lat, lon, routeId, routeSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean areLatLonEqual(double lat1, double lon1, double lat2, double lon2) {
|
private static boolean areLatLonEqual(double lat1, double lon1, double lat2, double lon2) {
|
||||||
|
|
|
@ -448,7 +448,7 @@ public class TravelDbHelper implements TravelHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (matchLang) {
|
if (matchLang) {
|
||||||
prev.articleId.title = rs.getArticleTitle();
|
prev.articleTitle = rs.getArticleTitle();
|
||||||
prev.isPartOf = rs.getIsPartOf();
|
prev.isPartOf = rs.getIsPartOf();
|
||||||
}
|
}
|
||||||
prev.langs.add(matchLang ? 0 : 1, rs.langs.get(0));
|
prev.langs.add(matchLang ? 0 : 1, rs.langs.get(0));
|
||||||
|
@ -683,11 +683,6 @@ public class TravelDbHelper implements TravelHelper {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public GPXFile getGpxFile(@NonNull TravelArticle article, @Nullable String lang) {
|
|
||||||
return article.getGpxFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String formatTravelBookName(File tb) {
|
public String formatTravelBookName(File tb) {
|
||||||
if (tb == null) {
|
if (tb == null) {
|
||||||
return application.getString(R.string.shared_string_none);
|
return application.getString(R.string.shared_string_none);
|
||||||
|
|
|
@ -3,7 +3,6 @@ package net.osmand.plus.wikivoyage.data;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import net.osmand.GPXUtilities;
|
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.QuadRect;
|
import net.osmand.data.QuadRect;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelArticle.TravelArticleIdentifier;
|
import net.osmand.plus.wikivoyage.data.TravelArticle.TravelArticleIdentifier;
|
||||||
|
@ -13,8 +12,6 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static net.osmand.GPXUtilities.*;
|
|
||||||
|
|
||||||
public interface TravelHelper {
|
public interface TravelHelper {
|
||||||
|
|
||||||
TravelLocalDataHelper getBookmarksHelper();
|
TravelLocalDataHelper getBookmarksHelper();
|
||||||
|
@ -52,9 +49,6 @@ public interface TravelHelper {
|
||||||
@NonNull
|
@NonNull
|
||||||
ArrayList<String> getArticleLangs(@NonNull TravelArticleIdentifier articleId);
|
ArrayList<String> getArticleLangs(@NonNull TravelArticleIdentifier articleId);
|
||||||
|
|
||||||
@Nullable
|
|
||||||
GPXFile getGpxFile(@NonNull TravelArticle article, @Nullable String lang);
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
String getGPXName(@NonNull final TravelArticle article);
|
String getGPXName(@NonNull final TravelArticle article);
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,8 @@ import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import static net.osmand.GPXUtilities.*;
|
import static net.osmand.GPXUtilities.WptPt;
|
||||||
|
import static net.osmand.GPXUtilities.writeGpxFile;
|
||||||
|
|
||||||
public class TravelObfHelper implements TravelHelper {
|
public class TravelObfHelper implements TravelHelper {
|
||||||
|
|
||||||
|
@ -93,12 +94,12 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
try {
|
try {
|
||||||
final LatLon location = app.getMapViewTrackingUtilities().getMapLocation();
|
final LatLon location = app.getMapViewTrackingUtilities().getMapLocation();
|
||||||
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(
|
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(
|
||||||
location, POPULAR_ARTICLES_SEARCH_RADIUS, -1, getSearchRouteArticleFilter(), null);
|
location, POPULAR_ARTICLES_SEARCH_RADIUS, -1, getSearchFilter(false), null);
|
||||||
List<Amenity> amenities = reader.searchPoi(req);
|
List<Amenity> amenities = reader.searchPoi(req);
|
||||||
if (amenities.size() > 0) {
|
if (amenities.size() > 0) {
|
||||||
for (Amenity amenity : amenities) {
|
for (Amenity amenity : amenities) {
|
||||||
if (!Algorithms.isEmpty(amenity.getName(lang))) {
|
if (!Algorithms.isEmpty(amenity.getName(lang))) {
|
||||||
TravelArticle article = cacheTravelArticles(reader.getFile(), amenity, lang);
|
TravelArticle article = cacheTravelArticles(reader.getFile(), amenity, lang, false);
|
||||||
if (article != null) {
|
if (article != null) {
|
||||||
popularArticles.add(article);
|
popularArticles.add(article);
|
||||||
if (popularArticles.size() >= MAX_POPULAR_ARTICLES_COUNT) {
|
if (popularArticles.size() >= MAX_POPULAR_ARTICLES_COUNT) {
|
||||||
|
@ -127,23 +128,23 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private TravelArticle cacheTravelArticles(File file, Amenity amenity, String lang) {
|
private TravelArticle cacheTravelArticles(File file, Amenity amenity, String lang, boolean readPoints) {
|
||||||
TravelArticle article = null;
|
TravelArticle article = null;
|
||||||
Map<String, TravelArticle> articles = readArticles(file, amenity);
|
Map<String, TravelArticle> articles = readArticles(file, amenity, readPoints);
|
||||||
if (!Algorithms.isEmpty(articles)) {
|
if (!Algorithms.isEmpty(articles)) {
|
||||||
TravelArticleIdentifier newArticleId = articles.values().iterator().next().generateIdentifier();
|
TravelArticleIdentifier newArticleId = articles.values().iterator().next().generateIdentifier();
|
||||||
cachedArticles.put(newArticleId, articles);
|
cachedArticles.put(newArticleId, articles);
|
||||||
article = getCachedArticle(newArticleId, lang);
|
article = getCachedArticle(newArticleId, lang, readPoints);
|
||||||
}
|
}
|
||||||
return article;
|
return article;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private SearchPoiTypeFilter getSearchRouteArticleFilter() {
|
private SearchPoiTypeFilter getSearchFilter(final boolean articlePoints) {
|
||||||
return new SearchPoiTypeFilter() {
|
return new SearchPoiTypeFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(PoiCategory type, String subcategory) {
|
public boolean accept(PoiCategory type, String subcategory) {
|
||||||
return subcategory.equals(ROUTE_ARTICLE);
|
return subcategory.equals(articlePoints ? ROUTE_ARTICLE_POINT : ROUTE_ARTICLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -154,32 +155,17 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private SearchPoiTypeFilter getSearchRouteArticlePointsFilter() {
|
private Map<String, TravelArticle> readArticles(@NonNull File file, @NonNull Amenity amenity, boolean readPoints) {
|
||||||
return new SearchPoiTypeFilter() {
|
|
||||||
@Override
|
|
||||||
public boolean accept(PoiCategory type, String subcategory) {
|
|
||||||
return subcategory.equals(ROUTE_ARTICLE_POINT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private Map<String, TravelArticle> readArticles(@NonNull File file, @NonNull Amenity amenity) {
|
|
||||||
Map<String, TravelArticle> articles = new HashMap<>();
|
Map<String, TravelArticle> articles = new HashMap<>();
|
||||||
Set<String> langs = getLanguages(amenity);
|
Set<String> langs = getLanguages(amenity);
|
||||||
for (String lang : langs) {
|
for (String lang : langs) {
|
||||||
articles.put(lang, readArticle(file, amenity, lang));
|
articles.put(lang, readArticle(file, amenity, lang, readPoints));
|
||||||
}
|
}
|
||||||
return articles;
|
return articles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private TravelArticle readArticle(@NonNull File file, @NonNull Amenity amenity, @Nullable String lang) {
|
private TravelArticle readArticle(@NonNull File file, @NonNull Amenity amenity, @NonNull String lang, boolean readPoints) {
|
||||||
TravelArticle res = new TravelArticle();
|
TravelArticle res = new TravelArticle();
|
||||||
res.file = file;
|
res.file = file;
|
||||||
String title = amenity.getName(lang);
|
String title = amenity.getName(lang);
|
||||||
|
@ -195,40 +181,44 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
res.lang = lang;
|
res.lang = lang;
|
||||||
res.contentsJson = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.CONTENT_JSON, lang));
|
res.contentsJson = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.CONTENT_JSON, lang));
|
||||||
res.aggregatedPartOf = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.IS_AGGR_PART, lang));
|
res.aggregatedPartOf = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.IS_AGGR_PART, lang));
|
||||||
|
if (readPoints) {
|
||||||
|
res.gpxFile = buildGpxFile(res);
|
||||||
|
res.gpxFileRead = true;
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private GPXFile buildGpxFile(@NonNull TravelArticle article) {
|
||||||
@Override
|
|
||||||
public GPXFile getGpxFile(@NonNull TravelArticle article, @Nullable String lang) {
|
|
||||||
GPXFile gpxFile = null;
|
GPXFile gpxFile = null;
|
||||||
List<Amenity> pointList = getPointList(article, lang);
|
List<Amenity> pointList = getPointList(article);
|
||||||
if (!Algorithms.isEmpty(pointList)) {
|
if (!Algorithms.isEmpty(pointList)) {
|
||||||
gpxFile = new GPXFile(article.getTitle(), lang, "");
|
gpxFile = new GPXFile(article.getTitle(), article.getLang(), "");
|
||||||
for (Amenity amenity : pointList) {
|
for (Amenity amenity : pointList) {
|
||||||
WptPt wptPt = createWptPt(amenity, lang);
|
WptPt wptPt = createWptPt(amenity, article.getLang());
|
||||||
gpxFile.addPoint(wptPt);
|
gpxFile.addPoint(wptPt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return gpxFile;
|
return gpxFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@NonNull
|
||||||
private List<Amenity> getPointList(@NonNull final TravelArticle article, @Nullable final String lang) {
|
private List<Amenity> getPointList(@NonNull final TravelArticle article) {
|
||||||
final List<Amenity> pointList = new ArrayList<>();
|
final List<Amenity> pointList = new ArrayList<>();
|
||||||
|
final String lang = article.getLang();
|
||||||
for (BinaryMapIndexReader reader : getReaders()) {
|
for (BinaryMapIndexReader reader : getReaders()) {
|
||||||
try {
|
try {
|
||||||
final LatLon location = new LatLon(article.getLat(), article.getLon());
|
if (article.file != null && !article.file.equals(reader.getFile())) {
|
||||||
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(
|
continue;
|
||||||
location, POPULAR_ARTICLES_SEARCH_RADIUS, -1, getSearchRouteArticlePointsFilter(),
|
}
|
||||||
new ResultMatcher<Amenity>() {
|
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(0, 0,
|
||||||
|
Algorithms.emptyIfNull(article.routeId), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE,
|
||||||
|
getSearchFilter(false), new ResultMatcher<Amenity>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean publish(Amenity point) {
|
public boolean publish(Amenity amenity) {
|
||||||
String amenityLang = point.getTagSuffix(Amenity.LANG_YES + ":");
|
String amenityLang = amenity.getTagSuffix(Amenity.LANG_YES + ":");
|
||||||
if (lang != null && lang.equals(amenityLang)
|
if (lang.equals(amenityLang)) {
|
||||||
&& point.getAdditionalInfo(Amenity.ROUTE_ID) != null
|
pointList.add(amenity);
|
||||||
&& point.getAdditionalInfo(Amenity.ROUTE_ID).equals(article.getRouteId())) {
|
|
||||||
pointList.add(point);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -237,8 +227,18 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
}, null);
|
||||||
reader.searchPoi(req);
|
|
||||||
|
if (!Double.isNaN(article.lat)) {
|
||||||
|
req.setBBoxRadius(article.lat, article.lon, ARTICLE_SEARCH_RADIUS);
|
||||||
|
if (!Algorithms.isEmpty(article.title)) {
|
||||||
|
reader.searchPoiByName(req);
|
||||||
|
} else {
|
||||||
|
reader.searchPoi(req);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reader.searchPoi(req);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error(e.getMessage(), e);
|
LOG.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
if (color != null) {
|
if (color != null) {
|
||||||
wptPt.setColor(ColorDialogs.getColorByTag(color));
|
wptPt.setColor(ColorDialogs.getColorByTag(color));
|
||||||
}
|
}
|
||||||
String iconName = amenity.getIcon();
|
String iconName = amenity.getGpxIcon();
|
||||||
if (iconName != null) {
|
if (iconName != null) {
|
||||||
wptPt.setIconName(iconName);
|
wptPt.setIconName(iconName);
|
||||||
}
|
}
|
||||||
|
@ -284,7 +284,7 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
for (BinaryMapIndexReader reader : getReaders()) {
|
for (BinaryMapIndexReader reader : getReaders()) {
|
||||||
try {
|
try {
|
||||||
SearchRequest<Amenity> searchRequest = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, searchQuery,
|
SearchRequest<Amenity> searchRequest = BinaryMapIndexReader.buildSearchPoiRequest(0, 0, searchQuery,
|
||||||
0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, getSearchRouteArticleFilter(), new ResultMatcher<Amenity>() {
|
0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, getSearchFilter(false), new ResultMatcher<Amenity>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean publish(Amenity object) {
|
public boolean publish(Amenity object) {
|
||||||
List<String> otherNames = object.getAllNames(false);
|
List<String> otherNames = object.getAllNames(false);
|
||||||
|
@ -313,7 +313,7 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
for (Amenity amenity : entry.getValue()) {
|
for (Amenity amenity : entry.getValue()) {
|
||||||
Set<String> nameLangs = getLanguages(amenity);
|
Set<String> nameLangs = getLanguages(amenity);
|
||||||
if (nameLangs.contains(appLang)) {
|
if (nameLangs.contains(appLang)) {
|
||||||
TravelArticle article = readArticle(file, amenity, appLang);
|
TravelArticle article = readArticle(file, amenity, appLang, false);
|
||||||
ArrayList<String> langs = new ArrayList<>(nameLangs);
|
ArrayList<String> langs = new ArrayList<>(nameLangs);
|
||||||
Collections.sort(langs, new Comparator<String>() {
|
Collections.sort(langs, new Comparator<String>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -367,7 +367,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.articleId.title, res2.articleId.title);
|
return collator.compare(res1.articleTitle, res2.articleTitle);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -407,7 +407,7 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
for (BinaryMapIndexReader reader : getReaders()) {
|
for (BinaryMapIndexReader reader : getReaders()) {
|
||||||
try {
|
try {
|
||||||
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(0,
|
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(0,
|
||||||
Integer.MAX_VALUE, 0, Integer.MAX_VALUE, -1, getSearchRouteArticleFilter(), new ResultMatcher<Amenity>() {
|
Integer.MAX_VALUE, 0, Integer.MAX_VALUE, -1, getSearchFilter(false), new ResultMatcher<Amenity>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean publish(Amenity amenity) {
|
public boolean publish(Amenity amenity) {
|
||||||
|
@ -450,7 +450,7 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
for (Amenity amenity : entry.getValue()) {
|
for (Amenity amenity : entry.getValue()) {
|
||||||
Set<String> nameLangs = getLanguages(amenity);
|
Set<String> nameLangs = getLanguages(amenity);
|
||||||
if (nameLangs.contains(lang)) {
|
if (nameLangs.contains(lang)) {
|
||||||
TravelArticle a = readArticle(file, amenity, lang);
|
TravelArticle a = readArticle(file, amenity, lang, false);
|
||||||
WikivoyageSearchResult rs = new WikivoyageSearchResult(a, new ArrayList<>(nameLangs));
|
WikivoyageSearchResult rs = new WikivoyageSearchResult(a, new ArrayList<>(nameLangs));
|
||||||
List<WikivoyageSearchResult> l = navMap.get(rs.isPartOf);
|
List<WikivoyageSearchResult> l = navMap.get(rs.isPartOf);
|
||||||
if (l == null) {
|
if (l == null) {
|
||||||
|
@ -487,12 +487,12 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TravelArticle getArticleById(@NonNull TravelArticleIdentifier articleId, @NonNull String lang) {
|
public TravelArticle getArticleById(@NonNull TravelArticleIdentifier articleId, @NonNull String lang) {
|
||||||
TravelArticle article = getCachedArticle(articleId, lang);
|
TravelArticle article = getCachedArticle(articleId, lang, true);
|
||||||
return article == null ? localDataHelper.getSavedArticle(articleId.file, articleId.routeId, lang) : article;
|
return article == null ? localDataHelper.getSavedArticle(articleId.file, articleId.routeId, lang) : article;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private TravelArticle getCachedArticle(@NonNull TravelArticleIdentifier articleId, @NonNull String lang) {
|
private TravelArticle getCachedArticle(@NonNull TravelArticleIdentifier articleId, @NonNull String lang, boolean forceReadPoints) {
|
||||||
TravelArticle article = null;
|
TravelArticle article = null;
|
||||||
Map<String, TravelArticle> articles = cachedArticles.get(articleId);
|
Map<String, TravelArticle> articles = cachedArticles.get(articleId);
|
||||||
if (articles != null) {
|
if (articles != null) {
|
||||||
|
@ -508,54 +508,45 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return article == null ? findArticleById(articleId, lang) : article;
|
if (article == null) {
|
||||||
|
article = findArticleById(articleId, lang);
|
||||||
|
}
|
||||||
|
if (article != null && !article.gpxFileRead && forceReadPoints) {
|
||||||
|
article.gpxFile = buildGpxFile(article);
|
||||||
|
article.gpxFileRead = true;
|
||||||
|
}
|
||||||
|
return article;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
final boolean isDbArticle = articleId.file != null && articleId.file.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT);
|
boolean isDbArticle = articleId.file != null && articleId.file.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT);
|
||||||
final List<Amenity> amenities = new ArrayList<>();
|
List<Amenity> amenities = null;
|
||||||
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.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE,
|
Algorithms.emptyIfNull(articleId.routeId), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE,
|
||||||
getSearchRouteArticleFilter(), new ResultMatcher<Amenity>() {
|
getSearchFilter(false), null, null);
|
||||||
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.title)) {
|
if (!Algorithms.isEmpty(articleId.routeId)) {
|
||||||
reader.searchPoiByName(req);
|
amenities = reader.searchPoiByName(req);
|
||||||
} else {
|
} else {
|
||||||
reader.searchPoi(req);
|
amenities = reader.searchPoi(req);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
reader.searchPoi(req);
|
amenities = reader.searchPoi(req);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.error(e.getMessage());
|
LOG.error(e.getMessage());
|
||||||
}
|
}
|
||||||
if (!Algorithms.isEmpty(amenities)) {
|
if (!Algorithms.isEmpty(amenities)) {
|
||||||
article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang);
|
article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return article;
|
return article;
|
||||||
|
@ -570,7 +561,7 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull LatLon latLon, @NonNull final String lang) {
|
public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull LatLon latLon, @NonNull final String lang) {
|
||||||
QuadRect rect = latLon != null ? MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), ARTICLE_SEARCH_RADIUS) : new QuadRect();
|
QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), ARTICLE_SEARCH_RADIUS);
|
||||||
return getArticleByTitle(title, rect, lang);
|
return getArticleByTitle(title, rect, lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,13 +587,14 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
for (BinaryMapIndexReader reader : getReaders()) {
|
for (BinaryMapIndexReader reader : getReaders()) {
|
||||||
try {
|
try {
|
||||||
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(
|
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(
|
||||||
x, y, title, left, right, top, bottom, getSearchRouteArticleFilter(), null, null);
|
x, y, title, left, right, top, bottom, getSearchFilter(false), null, null);
|
||||||
|
req.setLimit(1);
|
||||||
amenities = reader.searchPoiByName(req);
|
amenities = reader.searchPoiByName(req);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.error(e.getMessage());
|
LOG.error(e.getMessage());
|
||||||
}
|
}
|
||||||
if (!Algorithms.isEmpty(amenities)) {
|
if (!Algorithms.isEmpty(amenities)) {
|
||||||
article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang);
|
article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return article;
|
return article;
|
||||||
|
|
|
@ -15,6 +15,7 @@ public class WikivoyageSearchResult {
|
||||||
|
|
||||||
TravelArticleIdentifier articleId;
|
TravelArticleIdentifier articleId;
|
||||||
|
|
||||||
|
String articleTitle;
|
||||||
String imageTitle;
|
String imageTitle;
|
||||||
String isPartOf;
|
String isPartOf;
|
||||||
|
|
||||||
|
@ -32,8 +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;
|
||||||
article.title = articleTitle;
|
this.articleTitle = 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 articleId.title;
|
return articleTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getArticleRouteId() {
|
public String getArticleRouteId() {
|
||||||
|
|
Loading…
Reference in a new issue