Skip to content

Commit

Permalink
Implement better gpxFileName scheme for TravelGpx
Browse files Browse the repository at this point in the history
  • Loading branch information
RZR-UA committed Nov 22, 2024
1 parent 3c0cf79 commit 2b8cde4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
16 changes: 16 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/data/Amenity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static net.osmand.gpx.GPXUtilities.AMENITY_PREFIX;
import static net.osmand.gpx.GPXUtilities.OSM_PREFIX;
import static net.osmand.osm.MapPoiTypes.ROUTES_PREFIX;
import static net.osmand.osm.MapPoiTypes.ROUTE_ARTICLE;
import static net.osmand.osm.MapPoiTypes.ROUTE_ARTICLE_POINT;
import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK;

import net.osmand.Location;
Expand Down Expand Up @@ -449,6 +451,20 @@ public String getRouteId() {
return getAdditionalInfo(ROUTE_ID);
}

public String getGpxFileName(String lang) {
final String gpxFileName = lang != null ? getName(lang) : getEnName(true);
if (!Algorithms.isEmpty(gpxFileName)) {
return gpxFileName;
}
if (!Algorithms.isEmpty(getRouteId())) {
return getRouteId();
}
if (!Algorithms.isEmpty(getSubType())) {
return getType().getKeyName() + " " + getSubType();
}
return getType().getKeyName();
}

public String getStrictTagContent(String tag, String lang) {
if (lang != null) {
String translateName = getAdditionalInfo(tag + ":" + lang);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private void showResultWithLocation(SearchResult searchResult) {
Amenity amenity = (Amenity) pair.second;
TravelHelper travelHelper = app.getTravelHelper();
TravelGpx travelGpx = travelHelper.searchGpx(amenity.getLocation(), amenity.getRouteId(), amenity.getRef());
travelHelper.openTrackMenu(travelGpx, getMapActivity(), amenity.getRouteId(), amenity.getLocation(), true);
travelHelper.openTrackMenu(travelGpx, getMapActivity(), amenity.getGpxFileName(null), amenity.getLocation(), true);
} else {
showOnMap(getMapActivity(), dialogFragment,
searchResult.location.getLatitude(), searchResult.location.getLongitude(),
Expand Down
4 changes: 2 additions & 2 deletions OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ public boolean showMenuAction(@Nullable Object object) {
if (subType.equals(ROUTE_ARTICLE)) {
String lang = app.getLanguage();
lang = amenity.getContentLanguage(Amenity.DESCRIPTION, lang, "en");
String name = amenity.getName(lang);
String name = amenity.getGpxFileName(lang);
TravelArticle article = travelHelper.getArticleByTitle(name, lang, true, null);
if (article == null) {
return true;
Expand All @@ -616,7 +616,7 @@ public boolean showMenuAction(@Nullable Object object) {
if (travelGpx == null) {
return true;
}
travelHelper.openTrackMenu(travelGpx, mapActivity, amenity.getRouteId(), amenity.getLocation(), false);
travelHelper.openTrackMenu(travelGpx, mapActivity, amenity.getGpxFileName(null), amenity.getLocation(), false);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public boolean showMenuAction(@Nullable Object object) {

WptPt wptPt = selectedGpxPoint.getSelectedPoint();
TravelHelper travelHelper = app.getTravelHelper();
travelHelper.openTrackMenu(travelGpx, mapActivity, travelGpx.getRouteId(),
travelHelper.openTrackMenu(travelGpx, mapActivity, travelGpx.getGpxFileName(),
new LatLon(wptPt.getLat(), wptPt.getLon()), false);
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public String getRouteId() {
return routeId;
}

public String getGpxFileName() {
return !Algorithms.isEmpty(title) ? title : routeId;
}

public String getRouteSource() {
return routeSource;
}
Expand Down

0 comments on commit 2b8cde4

Please sign in to comment.