Skip to content

Commit

Permalink
TravelGpx: refactor route_activity_type, add translation phrases (#21576
Browse files Browse the repository at this point in the history
)

* Activity logger

* Revert "Activity logger"

This reverts commit dfea9c5.

* Add translation skel for poi_activity_type_* tags

* Rename route_activity_type to route_activity

* Fix prefix for poi_route_activity_ strings

* Refactor route_activity_type tag processing

* Actualize ROUTE_ACTIVITY_TYPE const name

* Rename poi_route_activity_ translation tags

* Better cleanup for ROUTE_ACTIVITY_TYPE tags
  • Loading branch information
RZR-UA authored Dec 18, 2024
1 parent 813e982 commit 5efe824
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 20 deletions.
63 changes: 63 additions & 0 deletions OsmAnd/res/values/phrases.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5464,6 +5464,69 @@
<string name="poi_routes_water_sport">Water sports</string>
<string name="poi_routes_other">Other routes</string>

<string name="poi_route_activity_type_car">Car</string>
<string name="poi_route_activity_type_off_road">Off-Road</string>
<string name="poi_route_activity_type_all_terrain_vehicle">ATV (All-Terrain Vehicle)</string>
<string name="poi_route_activity_type_truck_hgv">Truck (HGV)</string>
<string name="poi_route_activity_type_karting">Karting</string>
<string name="poi_route_activity_type_adventure_motorcycling">Adventure Motorcycling</string>
<string name="poi_route_activity_type_enduro_motorcycling">Enduro Motorcycling</string>
<string name="poi_route_activity_type_motocross">Motocross</string>
<string name="poi_route_activity_type_off_road_motorcycling_dirt_biking">Off-Road Motorcycling (Dirt Biking)</string>
<string name="poi_route_activity_type_road_motorcycling">Road Motorcycling</string>
<string name="poi_route_activity_type_sport_motorcycling">Sport Motorcycling</string>
<string name="poi_route_activity_type_touring_motorcycling">Touring Motorcycling</string>
<string name="poi_route_activity_type_track_racing">Track Racing</string>
<string name="poi_route_activity_type_motor_scooter">Motor scooter</string>
<string name="poi_route_activity_type_backpacking">Backpacking</string>
<string name="poi_route_activity_type_hiking">Hiking</string>
<string name="poi_route_activity_type_hill_climbing">Hill climbing</string>
<string name="poi_route_activity_type_road_running">Road Running</string>
<string name="poi_route_activity_type_trail_running">Trail Running</string>
<string name="poi_route_activity_type_trekking">Trekking</string>
<string name="poi_route_activity_type_walking">Walking</string>
<string name="poi_route_activity_type_cross_country_skiing">Cross-Country Skiing</string>
<string name="poi_route_activity_type_ice_skating">Ice Skating</string>
<string name="poi_route_activity_type_ski_touring">Ski Touring</string>
<string name="poi_route_activity_type_skiing">Skiing</string>
<string name="poi_route_activity_type_snowboarding">Snowboarding</string>
<string name="poi_route_activity_type_snowmobiling">Snowmobiling</string>
<string name="poi_route_activity_type_snowshoeing">Snowshoeing</string>
<string name="poi_route_activity_type_e_biking">E-Biking</string>
<string name="poi_route_activity_type_e_mountain_bike">E-mountain bike</string>
<string name="poi_route_activity_type_gravel_biking">Gravel Biking</string>
<string name="poi_route_activity_type_mountain_biking">Mountain biking</string>
<string name="poi_route_activity_type_road_cycling">Road cycling</string>
<string name="poi_route_activity_type_touring">Touring</string>
<string name="poi_route_activity_type_aviation">Aviation</string>
<string name="poi_route_activity_type_drone_flying">Drone Flying</string>
<string name="poi_route_activity_type_gliding_sailplane">Gliding (Sailplane)</string>
<string name="poi_route_activity_type_hang_gliding">Hang gliding</string>
<string name="poi_route_activity_type_hot_air_ballooning">Hot Air Ballooning</string>
<string name="poi_route_activity_type_parachuting_skydiving">Parachuting (Skydiving)</string>
<string name="poi_route_activity_type_paragliding">Paragliding</string>
<string name="poi_route_activity_type_powered_paragliding_paramotoring">Powered Paragliding (Paramotoring)</string>
<string name="poi_route_activity_type_ultralight_aviation">Ultralight Aviation</string>
<string name="poi_route_activity_type_canoe">Canoe</string>
<string name="poi_route_activity_type_diving">Diving</string>
<string name="poi_route_activity_type_scuba_diving">Scuba diving</string>
<string name="poi_route_activity_type_kayak">Kayak</string>
<string name="poi_route_activity_type_surfing">Surfing</string>
<string name="poi_route_activity_type_swimming_outdoor">Swimming outdoor</string>
<string name="poi_route_activity_type_waterskiing">Waterskiing</string>
<string name="poi_route_activity_type_windsurfing">Windsurfing</string>
<string name="poi_route_activity_type_motorboat">Motorboat</string>
<string name="poi_route_activity_type_rafting">Rafting</string>
<string name="poi_route_activity_type_horse_riding">Horse riding</string>
<string name="poi_route_activity_type_mushrooms_picking">Mushrooms picking</string>
<string name="poi_route_activity_type_harvesting">Harvesting</string>
<string name="poi_route_activity_type_tree_climbing">Tree Climbing</string>
<string name="poi_route_activity_type_caving">Caving</string>
<string name="poi_route_activity_type_train_riding">Train Riding</string>
<string name="poi_route_activity_type_golfing">Golfing</string>
<string name="poi_route_activity_type_fitness">Fitness</string>
<string name="poi_route_activity_type_inline_skates">Inline skates</string>

<string name="poi_name_etymology">Name etymology</string>
<string name="poi_name_left">Name of the left side</string>
<string name="poi_name_right">Name of the right side</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.osmand.plus.configmap;

import static net.osmand.IProgress.EMPTY_PROGRESS;
import static net.osmand.plus.wikivoyage.data.TravelGpx.ACTIVITY_TYPE;
import static net.osmand.plus.wikivoyage.data.TravelGpx.ROUTE_ACTIVITY_TYPE;

import android.os.Bundle;
import android.view.Gravity;
Expand Down Expand Up @@ -115,7 +115,7 @@ private void showHideTopShadow(@NonNull View view) {
}

private void updateRouteTypes() {
List<String> routesTypes = app.getResourceManager().searchPoiSubTypesByPrefix(ACTIVITY_TYPE);
List<String> routesTypes = app.getResourceManager().searchPoiSubTypesByPrefix(ROUTE_ACTIVITY_TYPE);
Collections.sort(routesTypes, OsmAndCollator.primaryCollator()::compare);
this.routeTypes = routesTypes;
}
Expand Down Expand Up @@ -331,7 +331,7 @@ private void setupRouteTypes(ViewGroup container) {
View itemView = inflater.inflate(R.layout.list_item_icon_and_menu, container, false);
AndroidUtils.setBackground(itemView, UiUtilities.getSelectableDrawable(app));
String name;
String attrName = type.replace(ACTIVITY_TYPE + "_", "");
String attrName = type.replace(ROUTE_ACTIVITY_TYPE + "_", "");
PoiType poiType = poiTypes.getTextPoiAdditionalByKey(type);
if (poiType != null) {
name = poiType.getTranslation();
Expand Down
8 changes: 4 additions & 4 deletions OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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 static net.osmand.plus.wikivoyage.data.TravelGpx.ACTIVITY_TYPE;
import static net.osmand.plus.wikivoyage.data.TravelGpx.ROUTE_ACTIVITY_TYPE;
import static net.osmand.render.RenderingRulesStorage.LINE_RULES;
import static net.osmand.render.RenderingRulesStorage.ORDER_RULES;
import static net.osmand.render.RenderingRulesStorage.POINT_RULES;
Expand Down Expand Up @@ -148,12 +148,12 @@ public void updateRouteTypesVisibility() {
}
boolean showTracks = getRouteTracksProperty().get();
boolean renderedChanged = false;
List<String> routesTypes = resourceManager.searchPoiSubTypesByPrefix(ACTIVITY_TYPE);
List<String> routesTypes = resourceManager.searchPoiSubTypesByPrefix(ROUTE_ACTIVITY_TYPE);
for (String type : routesTypes) {
CommonPreference<Boolean> pref = getRouteTypeProperty(type);
if (renderer != null) {
boolean selected = showTracks && pref.get();
String attrName = type.replace(ACTIVITY_TYPE + "_", "");
String attrName = type.replace(ROUTE_ACTIVITY_TYPE + "_", "");
renderedChanged |= updateRouteTypeVisibility(renderer, attrName, selected, false);
}
}
Expand Down Expand Up @@ -385,7 +385,7 @@ private boolean updateRouteTypeVisibility(RenderingRulesStorage storage, String
public void onRendererLoaded(String name, RenderingRulesStorage rules, InputStream source) {
for (Map.Entry<String, CommonPreference<Boolean>> entry : routeTypesProps.entrySet()) {
boolean selected = entry.getValue().get();
String attrName = entry.getKey().replace(ACTIVITY_TYPE + "_", "");
String attrName = entry.getKey().replace(ROUTE_ACTIVITY_TYPE + "_", "");
updateRouteTypeVisibility(rules, attrName, selected, false);
}
}
Expand Down
3 changes: 2 additions & 1 deletion OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public class TravelGpx extends TravelArticle {
public static final String ELE_GRAPH = "ele_graph";
public static final String ROUTE_BBOX_RADIUS = "route_bbox_radius";
public static final String USER = "user";
public static final String ACTIVITY_TYPE = "route_activity_type";
public static final String ROUTE_TYPE = "route_type";
public static final String ROUTE_ACTIVITY_TYPE = "route_activity_type";
public static final String TRAVEL_MAP_TO_POI_TAG = "route_id";

public String user;
Expand Down
33 changes: 21 additions & 12 deletions OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK;
import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK_POINT;
import static net.osmand.plus.wikivoyage.data.PopularArticles.ARTICLES_PER_PAGE;
import static net.osmand.plus.wikivoyage.data.TravelGpx.ACTIVITY_TYPE;
import static net.osmand.plus.wikivoyage.data.TravelGpx.ROUTE_ACTIVITY_TYPE;
import static net.osmand.plus.wikivoyage.data.TravelGpx.AVERAGE_ELEVATION;
import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELEVATION_DOWN;
import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELEVATION_UP;
Expand All @@ -18,6 +18,7 @@
import static net.osmand.plus.wikivoyage.data.TravelGpx.MAX_ELEVATION;
import static net.osmand.plus.wikivoyage.data.TravelGpx.MIN_ELEVATION;
import static net.osmand.plus.wikivoyage.data.TravelGpx.ROUTE_BBOX_RADIUS;
import static net.osmand.plus.wikivoyage.data.TravelGpx.ROUTE_TYPE;
import static net.osmand.plus.wikivoyage.data.TravelGpx.START_ELEVATION;
import static net.osmand.plus.wikivoyage.data.TravelGpx.USER;
import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_BACKGROUNDS;
Expand Down Expand Up @@ -71,7 +72,6 @@
import net.osmand.shared.gpx.GpxFile;
import net.osmand.shared.gpx.GpxUtilities;
import net.osmand.shared.gpx.RouteActivityHelper;
import net.osmand.shared.gpx.primitives.RouteActivity;
import net.osmand.shared.gpx.primitives.Track;
import net.osmand.shared.gpx.primitives.TrkSegment;
import net.osmand.shared.gpx.primitives.WptPt;
Expand Down Expand Up @@ -324,7 +324,7 @@ private TravelGpx getTravelGpx(File file, Amenity amenity) {
travelGpx.description = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.DESCRIPTION));
travelGpx.routeId = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID));
travelGpx.user = Algorithms.emptyIfNull(amenity.getTagContent(USER));
travelGpx.activityType = Algorithms.emptyIfNull(amenity.getTagContent(ACTIVITY_TYPE));
travelGpx.activityType = Algorithms.emptyIfNull(amenity.getTagContent(ROUTE_ACTIVITY_TYPE));
travelGpx.ref = Algorithms.emptyIfNull(amenity.getRef());
travelGpx.totalDistance = Algorithms.parseFloatSilently(amenity.getTagContent(DISTANCE), 0);
travelGpx.diffElevationUp = Algorithms.parseDoubleSilently(amenity.getTagContent(DIFF_ELEVATION_UP), 0);
Expand Down Expand Up @@ -1199,11 +1199,17 @@ private void reconstructGpxTagsFromAmenityType(Amenity amenity, Map<String, Stri
String osmValue = amenity.getType().getPoiTypeByKeyName(subType).getOsmValue();
if (!Algorithms.isEmpty(osmValue)) {
if (amenity.hasOsmRouteId() || !"other".equals(osmValue)) {
gpxFileExtensions.put("route_type", osmValue); // do not litter gpx with default route_type
gpxFileExtensions.put(ROUTE_TYPE, osmValue); // do not litter gpx with default route_type
}
String activityType = amenity.getAdditionalInfo("route_activity_type");
if (activityType != null) {
gpxFileExtensions.put(GpxUtilities.ACTIVITY_TYPE, activityType); // osmand:activity in gpx
RouteActivityHelper helper = app.getRouteActivityHelper();
for (String key : amenity.getAdditionalInfoKeys()) {
if (key.startsWith(ROUTE_ACTIVITY_TYPE + "_")) {
String activityType = amenity.getAdditionalInfo(key);
if (!activityType.isEmpty() && helper.findRouteActivity(activityType) != null) {
gpxFileExtensions.put(GpxUtilities.ACTIVITY_TYPE, activityType); // osmand:activity in gpx
break;
}
}
}
}
}
Expand Down Expand Up @@ -1292,11 +1298,14 @@ private synchronized GpxFile buildGpxFile(@NonNull List<BinaryMapIndexReader> re
}
gpxFile.setHasAltitude(hasAltitude);
if (gpxFileExtensions.containsKey(GpxUtilities.ACTIVITY_TYPE)) {
gpxFile.getMetadata().getExtensionsToWrite()
.put(GpxUtilities.ACTIVITY_TYPE, gpxFileExtensions.get(GpxUtilities.ACTIVITY_TYPE));
gpxFileExtensions.remove(GpxUtilities.ACTIVITY_TYPE); // move activity to the metadata
gpxFileExtensions.remove("route_activity_type"); // osmand:activity is enough
gpxFileExtensions.remove("route_type");
final String activityType = gpxFileExtensions.get(GpxUtilities.ACTIVITY_TYPE);
gpxFile.getMetadata().getExtensionsToWrite().put(GpxUtilities.ACTIVITY_TYPE, activityType);

// cleanup type and activity tags
gpxFileExtensions.remove(ROUTE_TYPE);
gpxFileExtensions.remove(ROUTE_ACTIVITY_TYPE);
gpxFileExtensions.remove(ROUTE_ACTIVITY_TYPE + "_" + activityType);
gpxFileExtensions.remove(GpxUtilities.ACTIVITY_TYPE); // moved to the metadata
}

Gson gson = new Gson();
Expand Down

0 comments on commit 5efe824

Please sign in to comment.