From 5efe8247bd9180e7bde841635de2545e9e9f3ea9 Mon Sep 17 00:00:00 2001 From: RZR-UA <90444451+RZR-UA@users.noreply.github.com> Date: Wed, 18 Dec 2024 12:22:47 +0100 Subject: [PATCH] TravelGpx: refactor route_activity_type, add translation phrases (#21576) * Activity logger * Revert "Activity logger" This reverts commit dfea9c59ca47734a7dd82e1b6c1728ab0693e01e. * 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 --- OsmAnd/res/values/phrases.xml | 63 +++++++++++++++++++ .../plus/configmap/TravelRoutesFragment.java | 6 +- .../plus/render/TravelRendererHelper.java | 8 +-- .../plus/wikivoyage/data/TravelGpx.java | 3 +- .../plus/wikivoyage/data/TravelObfHelper.java | 33 ++++++---- 5 files changed, 93 insertions(+), 20 deletions(-) diff --git a/OsmAnd/res/values/phrases.xml b/OsmAnd/res/values/phrases.xml index 5b8e7cf788d..7cdebf8386c 100644 --- a/OsmAnd/res/values/phrases.xml +++ b/OsmAnd/res/values/phrases.xml @@ -5464,6 +5464,69 @@ Water sports Other routes + Car + Off-Road + ATV (All-Terrain Vehicle) + Truck (HGV) + Karting + Adventure Motorcycling + Enduro Motorcycling + Motocross + Off-Road Motorcycling (Dirt Biking) + Road Motorcycling + Sport Motorcycling + Touring Motorcycling + Track Racing + Motor scooter + Backpacking + Hiking + Hill climbing + Road Running + Trail Running + Trekking + Walking + Cross-Country Skiing + Ice Skating + Ski Touring + Skiing + Snowboarding + Snowmobiling + Snowshoeing + E-Biking + E-mountain bike + Gravel Biking + Mountain biking + Road cycling + Touring + Aviation + Drone Flying + Gliding (Sailplane) + Hang gliding + Hot Air Ballooning + Parachuting (Skydiving) + Paragliding + Powered Paragliding (Paramotoring) + Ultralight Aviation + Canoe + Diving + Scuba diving + Kayak + Surfing + Swimming outdoor + Waterskiing + Windsurfing + Motorboat + Rafting + Horse riding + Mushrooms picking + Harvesting + Tree Climbing + Caving + Train Riding + Golfing + Fitness + Inline skates + Name etymology Name of the left side Name of the right side diff --git a/OsmAnd/src/net/osmand/plus/configmap/TravelRoutesFragment.java b/OsmAnd/src/net/osmand/plus/configmap/TravelRoutesFragment.java index 4b306030660..5c73a9d727d 100644 --- a/OsmAnd/src/net/osmand/plus/configmap/TravelRoutesFragment.java +++ b/OsmAnd/src/net/osmand/plus/configmap/TravelRoutesFragment.java @@ -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; @@ -115,7 +115,7 @@ private void showHideTopShadow(@NonNull View view) { } private void updateRouteTypes() { - List routesTypes = app.getResourceManager().searchPoiSubTypesByPrefix(ACTIVITY_TYPE); + List routesTypes = app.getResourceManager().searchPoiSubTypesByPrefix(ROUTE_ACTIVITY_TYPE); Collections.sort(routesTypes, OsmAndCollator.primaryCollator()::compare); this.routeTypes = routesTypes; } @@ -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(); diff --git a/OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java b/OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java index 74cd7cc1776..c59af72392c 100644 --- a/OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java +++ b/OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java @@ -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; @@ -148,12 +148,12 @@ public void updateRouteTypesVisibility() { } boolean showTracks = getRouteTracksProperty().get(); boolean renderedChanged = false; - List routesTypes = resourceManager.searchPoiSubTypesByPrefix(ACTIVITY_TYPE); + List routesTypes = resourceManager.searchPoiSubTypesByPrefix(ROUTE_ACTIVITY_TYPE); for (String type : routesTypes) { CommonPreference 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); } } @@ -385,7 +385,7 @@ private boolean updateRouteTypeVisibility(RenderingRulesStorage storage, String public void onRendererLoaded(String name, RenderingRulesStorage rules, InputStream source) { for (Map.Entry> 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); } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java index 98c80d09154..9f3e8cf3596 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java @@ -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; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 795349a1c2d..39b01ab0b4c 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -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; @@ -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; @@ -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; @@ -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); @@ -1199,11 +1199,17 @@ private void reconstructGpxTagsFromAmenityType(Amenity amenity, Map 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();