From b9f2f267f3b55ee8d4d8523577fdd10d8a8dd6e1 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Wed, 13 Nov 2024 14:00:58 +0100 Subject: [PATCH 01/60] Fix routes activities_ POI click, optimize consts --- .../main/java/net/osmand/NativeLibrary.java | 3 +- .../main/java/net/osmand/osm/MapPoiTypes.java | 1 + .../java/net/osmand/search/SearchUICore.java | 9 ++--- .../osmand/plus/views/layers/POIMapLayer.java | 35 +++++++++++-------- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/NativeLibrary.java b/OsmAnd-java/src/main/java/net/osmand/NativeLibrary.java index 49f08c1372c..5d182f23208 100644 --- a/OsmAnd-java/src/main/java/net/osmand/NativeLibrary.java +++ b/OsmAnd-java/src/main/java/net/osmand/NativeLibrary.java @@ -2,6 +2,7 @@ import static net.osmand.IndexConstants.GPX_FILE_EXT; import static net.osmand.IndexConstants.GPX_GZ_FILE_EXT; +import static net.osmand.data.Amenity.ROUTE_ID; import java.io.File; import java.io.FileOutputStream; @@ -696,7 +697,7 @@ public List getOriginalNames() { public String getRouteID() { for (Map.Entry entry : getTags().entrySet()) { - if ("route_id".equals(entry.getKey())) { + if (ROUTE_ID.equals(entry.getKey())) { return entry.getValue(); } } diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 05170babbd1..f4eac618397 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -49,6 +49,7 @@ public class MapPoiTypes { public static final String ROUTE_ARTICLE_POINT = "route_article_point"; public static final String CATEGORY = "category"; public static final String ROUTE_TRACK = "route_track"; + public static final String ROUTE_ACTIVITIES_PREFIX = "activities_"; public static final String ROUTE_TRACK_POINT = "route_track_point"; private PoiTranslator poiTranslator = null; diff --git a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java index d4b4f2a1f22..ccd3acf7067 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -1,5 +1,9 @@ package net.osmand.search; +import static net.osmand.data.Amenity.ROUTE_ID; +import static net.osmand.osm.MapPoiTypes.ROUTE_ACTIVITIES_PREFIX; +import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK; + import net.osmand.CallbackWithObject; import net.osmand.Collator; import net.osmand.PlatformUtil; @@ -289,11 +293,8 @@ public boolean sameSearchResult(SearchResult r1, SearchResult r2) { || (subType1.startsWith("route_hiking_") && subType1.endsWith("n_poi"))) { similarityRadius = 50000; } - final String ROUTE_ID = "route_id"; - final String ROUTE_TRACK = "route_track"; - final String ROUTE_TYPE_PREFIX = "activities_"; if (Algorithms.stringsEqual(a1.getAdditionalInfo(ROUTE_ID), a2.getAdditionalInfo(ROUTE_ID)) - && (subType1.startsWith(ROUTE_TYPE_PREFIX) || subType1.equals(ROUTE_TRACK))) { + && (subType1.startsWith(ROUTE_ACTIVITIES_PREFIX) || subType1.equals(ROUTE_TRACK))) { similarityRadius = 50000; } } diff --git a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java index 9d0bb04b441..72262b2d0c1 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java @@ -1,7 +1,9 @@ package net.osmand.plus.views.layers; +import static net.osmand.osm.MapPoiTypes.ROUTES; import static net.osmand.osm.MapPoiTypes.ROUTE_ARTICLE; import static net.osmand.osm.MapPoiTypes.ROUTE_ARTICLE_POINT; +import static net.osmand.osm.MapPoiTypes.ROUTE_ACTIVITIES_PREFIX; import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK; import static net.osmand.plus.utils.AndroidUtils.dpToPx; @@ -602,26 +604,29 @@ public LatLon getObjectLocation(Object o) { public boolean showMenuAction(@Nullable Object object) { OsmandApplication app = view.getApplication(); MapActivity mapActivity = view.getMapActivity(); - TravelHelper travelHelper = app.getTravelHelper(); if (mapActivity != null && object instanceof Amenity) { + TravelHelper travelHelper = app.getTravelHelper(); Amenity amenity = (Amenity) object; - if (amenity.getSubType().equals(ROUTE_TRACK)) { - TravelGpx travelGpx = travelHelper.searchGpx(amenity.getLocation(), amenity.getRouteId(), amenity.getRef()); - if (travelGpx == null) { + String subType = amenity.getSubType(); + if (amenity.getType().getKeyName().equals(ROUTES)) { + if (subType.equals(ROUTE_ARTICLE)) { + String lang = app.getLanguage(); + lang = amenity.getContentLanguage(Amenity.DESCRIPTION, lang, "en"); + String name = amenity.getName(lang); + TravelArticle article = travelHelper.getArticleByTitle(name, lang, true, null); + if (article == null) { + return true; + } + travelHelper.openTrackMenu(article, mapActivity, name, amenity.getLocation()); return true; - } - travelHelper.openTrackMenu(travelGpx, mapActivity, amenity.getRouteId(), amenity.getLocation()); - return true; - } else if (amenity.getSubType().equals(ROUTE_ARTICLE)) { - String lang = app.getLanguage(); - lang = amenity.getContentLanguage(Amenity.DESCRIPTION, lang, "en"); - String name = amenity.getName(lang); - TravelArticle article = travelHelper.getArticleByTitle(name, lang, true, null); - if (article == null) { + } else if (subType.equals(ROUTE_TRACK) || subType.startsWith(ROUTE_ACTIVITIES_PREFIX)) { + TravelGpx travelGpx = travelHelper.searchGpx(amenity.getLocation(), amenity.getRouteId(), amenity.getRef()); + if (travelGpx == null) { + return true; + } + travelHelper.openTrackMenu(travelGpx, mapActivity, amenity.getRouteId(), amenity.getLocation()); return true; } - travelHelper.openTrackMenu(article, mapActivity, name, amenity.getLocation()); - return true; } } return false; From 37eebadfaf8686599b16f11a593a3394edd0a18b Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Thu, 14 Nov 2024 14:48:00 +0100 Subject: [PATCH 02/60] Implement click-on-map for route=segment ways --- .../plus/views/layers/MapSelectionHelper.java | 39 +++++++++++-------- .../plus/wikivoyage/data/TravelDbHelper.java | 6 ++- .../plus/wikivoyage/data/TravelHelper.java | 3 +- .../plus/wikivoyage/data/TravelObfHelper.java | 19 +++++++-- 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java b/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java index 58ac11bc5f1..2c39a3592d5 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java @@ -2,6 +2,7 @@ import static net.osmand.IndexConstants.GPX_FILE_EXT; import static net.osmand.binary.BinaryMapIndexReader.ACCEPT_ALL_POI_TYPE_FILTER; +import static net.osmand.data.Amenity.ROUTE_ID; import static net.osmand.data.FavouritePoint.DEFAULT_BACKGROUND_TYPE; import static net.osmand.data.MapObject.AMENITY_ID_RIGHT_SHIFT; import static net.osmand.osm.OsmRouteType.HIKING; @@ -213,7 +214,7 @@ private void selectObjectsFromNative(@NonNull MapSelectionResult result, @NonNul if (renderedObjects != null) { double cosRotateTileSize = Math.cos(Math.toRadians(rc.rotate)) * TILE_SIZE; double sinRotateTileSize = Math.sin(Math.toRadians(rc.rotate)) * TILE_SIZE; - boolean selectedRoutes = false; + boolean isRouteGpxSelected = false; for (RenderedObject renderedObject : renderedObjects) { String routeID = renderedObject.getRouteID(); String fileName = renderedObject.getGpxFileName(); @@ -250,14 +251,14 @@ private void selectObjectsFromNative(@NonNull MapSelectionResult result, @NonNul result.objectLatLon = renderedObject.getLabelLatLon(); } LatLon searchLatLon = result.objectLatLon != null ? result.objectLatLon : result.pointLatLon; - if (isTravelGpx) { - addTravelGpx(result, renderedObject, filter); + if (isTravelGpx && !isRouteGpxSelected) { + isRouteGpxSelected = addTravelGpx(result, filter, renderedObject.getTagValue("ref")); } else { - if (isRoute && !selectedRoutes) { - selectedRoutes = true; + if (isRoute && !isRouteGpxSelected) { NetworkRouteSelectorFilter routeFilter = createRouteFilter(); if (!Algorithms.isEmpty(routeFilter.typeFilter)) { - addRoute(result, tileBox, point, routeFilter); + addOsmRoute(result, tileBox, point, routeFilter); + isRouteGpxSelected = true; } } boolean amenityAdded = addAmenity(result, renderedObject, searchLatLon); @@ -276,7 +277,7 @@ private void selectObjectsFromOpenGl(@NonNull MapSelectionResult result, @NonNul int delta = 20; PointI tl = new PointI((int) point.x - delta, (int) point.y - delta); PointI br = new PointI((int) point.x + delta, (int) point.y + delta); - boolean selectedRoutes = false; + boolean isRouteGpxSelected = false; MapSymbolInformationList symbols = rendererView.getSymbolsIn(new AreaI(tl, br), false); for (int i = 0; i < symbols.size(); i++) { MapSymbolInformation symbolInfo = symbols.get(i); @@ -333,20 +334,24 @@ private void selectObjectsFromOpenGl(@NonNull MapSelectionResult result, @NonNul } if (obfMapObject != null) { Map tags = getTags(obfMapObject.getResolvedAttributes()); - boolean isRoute = !Algorithms.isEmpty(OsmRouteType.getRouteKeys(tags)); - if (isRoute && !selectedRoutes) { - selectedRoutes = true; + boolean isOsmRoute = !Algorithms.isEmpty(OsmRouteType.getRouteKeys(tags)); + if (isOsmRoute && !isRouteGpxSelected) { NetworkRouteSelectorFilter routeFilter = createRouteFilter(); if (!Algorithms.isEmpty(routeFilter.typeFilter)) { - addRoute(result, tileBox, point, routeFilter); + addOsmRoute(result, tileBox, point, routeFilter); + isRouteGpxSelected = true; } } + boolean isTravelGpx = app.getTravelHelper().isTravelGpxTags(tags); + if (isTravelGpx && !isRouteGpxSelected) { + isRouteGpxSelected = addTravelGpx(result, tags.get(ROUTE_ID), null); + } IOnPathMapSymbol onPathMapSymbol = getOnPathMapSymbol(symbolInfo); if (onPathMapSymbol == null) { amenity = getAmenity(result.objectLatLon, obfMapObject); if (amenity != null) { amenity.setMapIconName(getMapIconName(symbolInfo)); - } else if (!isRoute) { + } else if (!isOsmRoute && !isTravelGpx) { addRenderedObject(result, symbolInfo, obfMapObject); } } @@ -431,15 +436,17 @@ private Amenity getAmenity(LatLon latLon, ObfMapObject obfMapObject) { return amenity; } - private void addTravelGpx(@NonNull MapSelectionResult result, @NonNull RenderedObject object, @Nullable String filter) { - TravelGpx travelGpx = app.getTravelHelper().searchGpx(result.pointLatLon, filter, object.getTagValue("ref")); + private boolean addTravelGpx(@NonNull MapSelectionResult result, @Nullable String routeId, @Nullable String ref) { + TravelGpx travelGpx = app.getTravelHelper().searchGpx(result.pointLatLon, routeId, ref); if (travelGpx != null && isUniqueGpx(result.selectedObjects, travelGpx)) { WptPt selectedPoint = new WptPt(); selectedPoint.setLat(result.pointLatLon.getLatitude()); selectedPoint.setLon(result.pointLatLon.getLongitude()); SelectedGpxPoint selectedGpxPoint = new SelectedGpxPoint(null, selectedPoint); result.selectedObjects.put(new Pair<>(travelGpx, selectedGpxPoint), mapLayers.getTravelSelectionLayer()); + return true; } + return false; } private boolean isUniqueGpx(@NonNull Map selectedObjects, @@ -461,8 +468,8 @@ private boolean isUniqueGpx(@NonNull Map selectedO return true; } - private void addRoute(@NonNull MapSelectionResult result, @NonNull RotatedTileBox tileBox, @NonNull PointF point, - @NonNull NetworkRouteSelectorFilter selectorFilter) { + private void addOsmRoute(@NonNull MapSelectionResult result, @NonNull RotatedTileBox tileBox, @NonNull PointF point, + @NonNull NetworkRouteSelectorFilter selectorFilter) { int searchRadius = (int) (OsmandMapLayer.getScaledTouchRadius(app, tileBox.getDefaultRadiusPoi()) * 1.5f); LatLon minLatLon = NativeUtilities.getLatLonFromElevatedPixel(view.getMapRenderer(), tileBox, point.x - searchRadius, point.y - searchRadius); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java index 6d4d4d40df7..21687d634d1 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java @@ -203,7 +203,6 @@ public void saveOrRemoveArticle(@NonNull TravelArticle article, boolean save) { } } - public List getExistingTravelBooks() { return existingTravelBooks; } @@ -713,6 +712,11 @@ public String formatTravelBookName(File tb) { return nm.substring(0, nm.indexOf('.')).replace('_', ' '); } + @Override + public boolean isTravelGpxTags(@NonNull Map tags) { + return false; // stub + } + @Nullable @Override public TravelGpx searchGpx(@NonNull LatLon location, @Nullable String fileName, @Nullable String ref) { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java index 91ab8552c18..54c0d13dd77 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java @@ -61,6 +61,8 @@ interface GpxReadCallback { @NonNull ArrayList getArticleLangs(@NonNull TravelArticleIdentifier articleId); + boolean isTravelGpxTags(@NonNull Map tags); + @Nullable TravelGpx searchGpx(@NonNull LatLon location, @Nullable String fileName, @Nullable String ref); @@ -80,5 +82,4 @@ void openTrackMenu(@NonNull TravelArticle article, @NonNull MapActivity mapActiv String getWikivoyageFileName(); void saveOrRemoveArticle(@NonNull TravelArticle article, boolean save); - } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index ded6432c219..d281f6a27ce 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -2,6 +2,7 @@ import static net.osmand.IndexConstants.GPX_FILE_EXT; import static net.osmand.data.Amenity.REF; +import static net.osmand.data.Amenity.ROUTE; import static net.osmand.data.Amenity.ROUTE_ID; import static net.osmand.osm.MapPoiTypes.ROUTE_ARTICLE; import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK; @@ -206,8 +207,15 @@ public int compare(Pair article1, Pair article2) { return popularArticles; } + @Override + public boolean isTravelGpxTags(@NonNull Map tags) { + return tags.containsKey(ROUTE_ID) && "segment".equals(tags.get(ROUTE)); + } + @Nullable public synchronized TravelGpx searchGpx(@NonNull LatLon location, @Nullable String filter, @Nullable String ref) { + final String lcFilter = filter != null ? filter.toLowerCase() : null; + final String lcSearchRef = ref != null ? ref.toLowerCase() : null; List> foundAmenities = new ArrayList<>(); int searchRadius = ARTICLE_SEARCH_RADIUS; TravelGpx travelGpx = null; @@ -221,9 +229,14 @@ public synchronized TravelGpx searchGpx(@NonNull LatLon location, @Nullable Stri } for (Pair foundGpx : foundAmenities) { Amenity amenity = foundGpx.second; - if ((Algorithms.objectEquals(amenity.getRouteId(), filter) - || Algorithms.objectEquals(amenity.getName(), filter)) - && Algorithms.objectEquals(amenity.getRef(), ref)) { + final String aRef = amenity.getRef(); + final String aName = amenity.getName(); + final String aRouteId = amenity.getRouteId(); + final String lcRef = aRef != null ? aRef.toLowerCase() : null; + final String lcName = aName != null ? aName.toLowerCase() : null; + final String lcRouteId = aRouteId != null ? aRouteId.toLowerCase() : null; + if ((Algorithms.objectEquals(lcRouteId, lcFilter) || Algorithms.objectEquals(lcName, lcFilter)) + && (lcSearchRef == null || Algorithms.objectEquals(lcRef, lcSearchRef))) { travelGpx = getTravelGpx(foundGpx.first, amenity); break; } From 38acfe4582d403fbae5e0eee244a81e4636af248 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Fri, 15 Nov 2024 10:46:30 +0100 Subject: [PATCH 03/60] Refactor TravelObfHelper (ROUTE_ACTIVITIES_PREFIX) --- .../main/java/net/osmand/osm/MapPoiTypes.java | 4 ++-- .../plus/wikivoyage/data/TravelGpx.java | 2 +- .../plus/wikivoyage/data/TravelObfHelper.java | 19 ++++++++++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index f4eac618397..561d71e32fa 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -48,8 +48,8 @@ public class MapPoiTypes { public static final String ROUTE_ARTICLE = "route_article"; public static final String ROUTE_ARTICLE_POINT = "route_article_point"; public static final String CATEGORY = "category"; - public static final String ROUTE_TRACK = "route_track"; - public static final String ROUTE_ACTIVITIES_PREFIX = "activities_"; + public static final String ROUTE_TRACK = "route_track"; // routes:route_track (no activity) + public static final String ROUTE_ACTIVITIES_PREFIX = "activities_"; // routes:activity_xxx (without :route_track) public static final String ROUTE_TRACK_POINT = "route_track_point"; private PoiTranslator poiTranslator = null; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java index a724a764404..6ed1469905b 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java @@ -101,6 +101,6 @@ public String getPointFilterString() { @NonNull @Override public String getMainFilterString() { - return ROUTE_TRACK; + return ROUTE_TRACK; // considered together with ROUTE_ACTIVITIES_PREFIX } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index d281f6a27ce..555d822fe69 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -4,6 +4,7 @@ import static net.osmand.data.Amenity.REF; import static net.osmand.data.Amenity.ROUTE; import static net.osmand.data.Amenity.ROUTE_ID; +import static net.osmand.osm.MapPoiTypes.ROUTE_ACTIVITIES_PREFIX; import static net.osmand.osm.MapPoiTypes.ROUTE_ARTICLE; import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK; import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK_POINT; @@ -266,11 +267,16 @@ public boolean isCancelled() { })); } + private boolean isRouteTrackAmenity(Amenity amenity) { + return amenity.getSubType() != null && + (amenity.getSubType().equals(ROUTE_TRACK) || amenity.getSubType().startsWith(ROUTE_ACTIVITIES_PREFIX)); + } + @Nullable private TravelArticle cacheTravelArticles(File file, Amenity amenity, String lang, boolean readPoints, @Nullable GpxReadCallback callback) { TravelArticle article = null; Map articles; - if (ROUTE_TRACK.equals(amenity.getSubType())) { + if (isRouteTrackAmenity(amenity)) { articles = readRoutePoint(file, amenity); } else { articles = readArticles(file, amenity); @@ -322,14 +328,17 @@ private TravelGpx getTravelGpx(File file, Amenity amenity) { } @NonNull - public static SearchPoiTypeFilter getSearchFilter(String... filterSubcategory) { + public static SearchPoiTypeFilter getSearchFilter(String... filterSubcategories) { return new SearchPoiTypeFilter() { @Override public boolean accept(PoiCategory type, String subcategory) { - for (String filterSubcategory : filterSubcategory) { - if (subcategory.equals(filterSubcategory)) { + for (String filter : filterSubcategories) { + if (subcategory.equals(filter)) { return true; } + if (ROUTE_TRACK.equals(filter) && subcategory.startsWith(ROUTE_ACTIVITIES_PREFIX)) { + return true; // include routes:activites_xxx by routes:route_track filter + } } return false; } @@ -1131,7 +1140,7 @@ public boolean isCancelled() { @Override public boolean publish(Amenity amenity) { if (amenity.getRouteId().equals(article.getRouteId())) { - if (ROUTE_TRACK.equals(amenity.getSubType())) { + if (isRouteTrackAmenity(amenity)) { for (String key : amenity.getAdditionalInfoKeys()) { if (key.startsWith(OBF_GPX_EXTENSION_TAG_PREFIX)) { String tag = key.replaceFirst(OBF_GPX_EXTENSION_TAG_PREFIX, ""); From df083129d1258bf7ef40c56740b8ccb902ccd89d Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Fri, 15 Nov 2024 11:59:20 +0100 Subject: [PATCH 04/60] Refactor RouteTrack deduplication in POIMapLayer --- .../main/java/net/osmand/data/Amenity.java | 6 +++++ .../src/net/osmand/plus/poi/PoiUIFilter.java | 5 ---- .../osmand/plus/views/layers/POIMapLayer.java | 23 ++++++++----------- .../plus/wikivoyage/data/TravelObfHelper.java | 9 ++------ 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java index 13e72fae141..39364c4bb48 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java @@ -2,6 +2,8 @@ import static net.osmand.gpx.GPXUtilities.AMENITY_PREFIX; import static net.osmand.gpx.GPXUtilities.OSM_PREFIX; +import static net.osmand.osm.MapPoiTypes.ROUTE_ACTIVITIES_PREFIX; +import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK; import net.osmand.Location; import net.osmand.binary.BinaryMapIndexReader.TagValuePair; @@ -549,6 +551,10 @@ public boolean isPrivateAccess() { return PRIVATE_VALUE.equals(getTagContent(ACCESS_PRIVATE_TAG)); } + public boolean isRouteTrack() { + return subType != null && (subType.equals(ROUTE_TRACK) || subType.startsWith(ROUTE_ACTIVITIES_PREFIX)); + } + public JSONObject toJSON() { JSONObject json = super.toJSON(); json.put("subType", subType); diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java index 1029611f906..81639b31644 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java @@ -6,7 +6,6 @@ import static net.osmand.osm.MapPoiTypes.ROUTES; 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.osm.MapPoiTypes.WIKI_PLACE; import android.content.Context; @@ -199,10 +198,6 @@ public boolean isRouteArticlePointFilter() { return filterId.startsWith(STD_PREFIX + ROUTE_ARTICLE_POINT); } - public boolean isRouteTrackFilter() { - return filterId.startsWith(STD_PREFIX + ROUTE_TRACK); - } - public boolean isShowPrivateNeeded() { return filterByName != null && filterByName.contains("access:private"); } diff --git a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java index 72262b2d0c1..dca62ce2a8b 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java @@ -71,6 +71,7 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -160,6 +161,7 @@ protected List calculateResult(@NonNull QuadRect latLonBounds, int zoom int z = (int) Math.floor(zoom + Math.log(getMapDensity()) / Math.log(2)); List res = new ArrayList<>(); + Set deduplicateByRouteId = new HashSet<>(); PoiFilterUtils.combineStandardPoiFilters(calculatedFilters, app); for (PoiUIFilter filter : calculatedFilters) { List amenities = filter.searchAmenities(latLonBounds.top, latLonBounds.left, @@ -175,24 +177,17 @@ public boolean isCancelled() { return isInterrupted(); } }); - if (filter.isRouteTrackFilter()) { - for (Amenity amenity : amenities) { - boolean hasRoute = false; + for (Amenity amenity : amenities) { + if (amenity.isRouteTrack()) { String routeId = amenity.getRouteId(); - if (!Algorithms.isEmpty(routeId)) { - for (Amenity a : res) { - if (routeId.equals(a.getRouteId())) { - hasRoute = true; - break; - } + if (routeId != null) { + if (deduplicateByRouteId.contains(routeId)) { + continue; } - } - if (!hasRoute) { - res.add(amenity); + deduplicateByRouteId.add(routeId); } } - } else { - res.addAll(amenities); + res.add(amenity); } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 555d822fe69..2ed3888fad0 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -267,16 +267,11 @@ public boolean isCancelled() { })); } - private boolean isRouteTrackAmenity(Amenity amenity) { - return amenity.getSubType() != null && - (amenity.getSubType().equals(ROUTE_TRACK) || amenity.getSubType().startsWith(ROUTE_ACTIVITIES_PREFIX)); - } - @Nullable private TravelArticle cacheTravelArticles(File file, Amenity amenity, String lang, boolean readPoints, @Nullable GpxReadCallback callback) { TravelArticle article = null; Map articles; - if (isRouteTrackAmenity(amenity)) { + if (amenity.isRouteTrack()) { articles = readRoutePoint(file, amenity); } else { articles = readArticles(file, amenity); @@ -1140,7 +1135,7 @@ public boolean isCancelled() { @Override public boolean publish(Amenity amenity) { if (amenity.getRouteId().equals(article.getRouteId())) { - if (isRouteTrackAmenity(amenity)) { + if (amenity.isRouteTrack()) { for (String key : amenity.getAdditionalInfoKeys()) { if (key.startsWith(OBF_GPX_EXTENSION_TAG_PREFIX)) { String tag = key.replaceFirst(OBF_GPX_EXTENSION_TAG_PREFIX, ""); From fc343c4a11b3fd30b2ede53d599bf0fd51237f4a Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Fri, 15 Nov 2024 15:48:22 +0100 Subject: [PATCH 05/60] Refactor routeTrackFilters (ROUTE_ACTIVITIES_PREFIX) --- .../plus/configmap/TravelRoutesFragment.java | 4 +- .../plus/render/TravelRendererHelper.java | 53 ++++++++++++------- .../osmand/plus/views/layers/POIMapLayer.java | 23 ++++---- 3 files changed, 45 insertions(+), 35 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/configmap/TravelRoutesFragment.java b/OsmAnd/src/net/osmand/plus/configmap/TravelRoutesFragment.java index 5e21d5813b3..4b306030660 100644 --- a/OsmAnd/src/net/osmand/plus/configmap/TravelRoutesFragment.java +++ b/OsmAnd/src/net/osmand/plus/configmap/TravelRoutesFragment.java @@ -297,7 +297,7 @@ private void setupRouteTypes(ViewGroup container) { updateItemView(tracksView, getString(R.string.display_route_tracks), R.drawable.ic_action_track_16, selected, DescriptionType.VISIBLE_HIDDEN); app.runInUIThread(() -> { - rendererHelper.updateRouteTrackFilter(); + rendererHelper.updateRouteTrackFilters(); rendererHelper.updateRouteTypesVisibility(); app.getOsmandMap().refreshMap(true); app.getOsmandMap().getMapLayers().updateLayers((MapActivity) getMyActivity()); @@ -316,7 +316,7 @@ private void setupRouteTypes(ViewGroup container) { updateItemView(tracksAsPoiView, getString(R.string.display_route_tracks_as_poi), R.drawable.ic_action_info_dark, selected, DescriptionType.VISIBLE_HIDDEN); app.runInUIThread(() -> { - rendererHelper.updateRouteTrackFilter(); + rendererHelper.updateRouteTrackFilters(); rendererHelper.updateRouteTypesVisibility(); app.getOsmandMap().refreshMap(true); app.getOsmandMap().getMapLayers().updateLayers((MapActivity) getMyActivity()); diff --git a/OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java b/OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java index ea49370d3ad..30d7ce493e0 100644 --- a/OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java +++ b/OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java @@ -3,6 +3,7 @@ import static net.osmand.IProgress.EMPTY_PROGRESS; import static net.osmand.IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT; import static net.osmand.IndexConstants.WIKIVOYAGE_INDEX_DIR; +import static net.osmand.osm.MapPoiTypes.ROUTE_ACTIVITIES_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; @@ -20,6 +21,8 @@ import net.osmand.StateChangedListener; import net.osmand.core.android.MapRendererContext; import net.osmand.osm.MapPoiTypes; +import net.osmand.osm.PoiCategory; +import net.osmand.osm.PoiType; import net.osmand.plus.OsmandApplication; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.render.RendererRegistry.IRendererLoadedEventListener; @@ -42,6 +45,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeSet; public class TravelRendererHelper implements IRendererLoadedEventListener { @@ -68,7 +72,7 @@ public class TravelRendererHelper implements IRendererLoadedEventListener { private PoiUIFilter routeArticleFilter; private PoiUIFilter routeArticlePointsFilter; - private PoiUIFilter routeTrackFilter; + private Set routeTrackFilters; public interface OnFileVisibilityChangeListener { void fileVisibilityChanged(); @@ -235,11 +239,11 @@ public PoiUIFilter getRouteArticlePointsFilter() { } @Nullable - public PoiUIFilter getRouteTrackFilter() { - if (routeTrackFilter == null && app.getPoiTypes().isInit()) { - updateRouteTrackFilter(); + public Set getRouteTrackFilters() { + if (routeTrackFilters == null) { + updateRouteTrackFilters(); } - return routeTrackFilter; + return routeTrackFilters; } public void updateRouteArticleFilter() { @@ -249,26 +253,35 @@ public void updateRouteArticleFilter() { } public void updateRouteArticlePointsFilter() { - if (!app.getPoiTypes().isInit()) { - return; - } - PoiUIFilter routeArticlePointsFilter = app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + ROUTE_ARTICLE_POINT); - if (routeArticlePointsFilter != null) { - Set selectedCategories = new HashSet<>(); - List categories = app.getResourceManager().searchPoiSubTypesByPrefix(MapPoiTypes.CATEGORY); - for (String category : categories) { - CommonPreference prop = getRoutePointCategoryProperty(category); - if (prop.get()) { - selectedCategories.add(category.replace('_', ':').toLowerCase()); + if (app.getPoiTypes().isInit()) { + PoiUIFilter routeArticlePointsFilter = app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + ROUTE_ARTICLE_POINT); + if (routeArticlePointsFilter != null) { + Set selectedCategories = new HashSet<>(); + List categories = app.getResourceManager().searchPoiSubTypesByPrefix(MapPoiTypes.CATEGORY); + for (String category : categories) { + CommonPreference prop = getRoutePointCategoryProperty(category); + if (prop.get()) { + selectedCategories.add(category.replace('_', ':').toLowerCase()); + } } + routeArticlePointsFilter.setFilterByName(TextUtils.join(" ", selectedCategories)); } - routeArticlePointsFilter.setFilterByName(TextUtils.join(" ", selectedCategories)); + this.routeArticlePointsFilter = routeArticlePointsFilter; } - this.routeArticlePointsFilter = routeArticlePointsFilter; } - public void updateRouteTrackFilter() { - routeTrackFilter = app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + ROUTE_TRACK); + public void updateRouteTrackFilters() { + if (app.getPoiTypes().isInit()) { + routeTrackFilters = new TreeSet<>(); + PoiCategory routes = app.getPoiTypes().getRoutes(); + for (PoiType subType : routes.getPoiTypes()) { + String subTypeKeyName = subType.getKeyName(); + if (subTypeKeyName.startsWith(ROUTE_ACTIVITIES_PREFIX)) { + routeTrackFilters.add(app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + subTypeKeyName)); + } + } + routeTrackFilters.add(app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + ROUTE_TRACK)); + } } public boolean updateRouteTypeVisibility(RenderingRulesStorage storage, String name, boolean selected) { diff --git a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java index dca62ce2a8b..a7b82acb3a0 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java @@ -3,8 +3,6 @@ import static net.osmand.osm.MapPoiTypes.ROUTES; import static net.osmand.osm.MapPoiTypes.ROUTE_ARTICLE; import static net.osmand.osm.MapPoiTypes.ROUTE_ARTICLE_POINT; -import static net.osmand.osm.MapPoiTypes.ROUTE_ACTIVITIES_PREFIX; -import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK; import static net.osmand.plus.utils.AndroidUtils.dpToPx; import android.app.Dialog; @@ -102,7 +100,7 @@ public class POIMapLayer extends OsmandMapLayer implements IContextMenuProvider, private boolean routeTrackAsPoiFilterEnabled; private PoiUIFilter routeArticleFilter; private PoiUIFilter routeArticlePointsFilter; - private PoiUIFilter routeTrackFilter; + private Set routeTrackFilters; private String routeArticlePointsFilterByName; private boolean fileVisibilityChanged; public CustomMapObjects customObjectsDelegate; @@ -122,7 +120,7 @@ public POIMapLayer(@NonNull Context context) { routeArticlePointsFilterEnabled = travelRendererHelper.getRouteArticlePointsProperty().get(); routeArticleFilter = travelRendererHelper.getRouteArticleFilter(); routeArticlePointsFilter = travelRendererHelper.getRouteArticlePointsFilter(); - routeTrackFilter = travelRendererHelper.getRouteTrackFilter(); + routeTrackFilters = travelRendererHelper.getRouteTrackFilters(); routeArticlePointsFilterByName = routeArticlePointsFilter != null ? routeArticlePointsFilter.getFilterByName() : null; routingHelper.addListener(this); @@ -221,9 +219,8 @@ private Set collectFilters() { calculatedFilters.add(routeArticlePointsFilter); } boolean routeTrackAsPoiFilterEnabled = this.routeTrackAsPoiFilterEnabled; - PoiUIFilter routeTrackFilter = this.routeTrackFilter; - if (routeTrackAsPoiFilterEnabled && routeTrackFilter != null) { - calculatedFilters.add(routeTrackFilter); + if (routeTrackAsPoiFilterEnabled && this.routeTrackFilters != null) { + calculatedFilters.addAll(this.routeTrackFilters); } } return calculatedFilters; @@ -304,7 +301,7 @@ private boolean shouldDraw(int zoom) { && zoom >= START_ZOOM) { return true; } - if (travelRendererHelper.getRouteTracksAsPoiProperty().get() && routeTrackFilter != null) { + if (travelRendererHelper.getRouteTracksAsPoiProperty().get() && routeTrackFilters != null) { return travelRendererHelper.getRouteTracksProperty().get() ? zoom >= START_ZOOM : zoom >= START_ZOOM_ROUTE_TRACK; } @@ -318,7 +315,7 @@ private boolean shouldDraw(@NonNull RotatedTileBox tileBox, @NonNull Amenity ame } else { boolean routeArticle = ROUTE_ARTICLE_POINT.equals(amenity.getSubType()) || ROUTE_ARTICLE.equals(amenity.getSubType()); - boolean routeTrack = ROUTE_TRACK.equals(amenity.getSubType()); + boolean routeTrack = amenity.isRouteTrack(); if (routeArticle) { return tileBox.getZoom() >= START_ZOOM; } else if (routeTrack) { @@ -349,7 +346,7 @@ public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSett boolean routeTrackAsPoiFilterEnabled = travelRendererHelper.getRouteTracksAsPoiProperty().get(); PoiUIFilter routeArticleFilter = travelRendererHelper.getRouteArticleFilter(); PoiUIFilter routeArticlePointsFilter = travelRendererHelper.getRouteArticlePointsFilter(); - PoiUIFilter routeTrackFilter = travelRendererHelper.getRouteTrackFilter(); + Set routeTrackFilters = travelRendererHelper.getRouteTrackFilters(); String routeArticlePointsFilterByName = routeArticlePointsFilter != null ? routeArticlePointsFilter.getFilterByName() : null; boolean dataChanged = false; if (this.filters != selectedPoiFilters @@ -360,7 +357,7 @@ public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSett || this.routeTrackAsPoiFilterEnabled != routeTrackAsPoiFilterEnabled || this.routeArticleFilter != routeArticleFilter || this.routeArticlePointsFilter != routeArticlePointsFilter - || this.routeTrackFilter != routeTrackFilter + || this.routeTrackFilters != routeTrackFilters || this.fileVisibilityChanged || !Algorithms.stringsEqual(this.routeArticlePointsFilterByName, routeArticlePointsFilterByName)) { this.filters = selectedPoiFilters; @@ -371,7 +368,7 @@ public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSett this.routeTrackAsPoiFilterEnabled = routeTrackAsPoiFilterEnabled; this.routeArticleFilter = routeArticleFilter; this.routeArticlePointsFilter = routeArticlePointsFilter; - this.routeTrackFilter = routeTrackFilter; + this.routeTrackFilters = routeTrackFilters; this.routeArticlePointsFilterByName = routeArticlePointsFilterByName; this.fileVisibilityChanged = false; data.clearCache(); @@ -614,7 +611,7 @@ public boolean showMenuAction(@Nullable Object object) { } travelHelper.openTrackMenu(article, mapActivity, name, amenity.getLocation()); return true; - } else if (subType.equals(ROUTE_TRACK) || subType.startsWith(ROUTE_ACTIVITIES_PREFIX)) { + } else if (amenity.isRouteTrack()) { TravelGpx travelGpx = travelHelper.searchGpx(amenity.getLocation(), amenity.getRouteId(), amenity.getRef()); if (travelGpx == null) { return true; From 7c66702ff6b594cd4e6fab3b3cf0112b137b3f6f Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Tue, 19 Nov 2024 13:56:26 +0100 Subject: [PATCH 06/60] Implement click-on-search-results for Travel Obf --- .../controllers/AmenityMenuController.java | 2 +- .../dialogs/QuickSearchListFragment.java | 42 +++++++++++++------ .../plus/track/helpers/GpxUiHelper.java | 5 ++- .../layers/NetworkRouteSelectionLayer.java | 2 +- .../osmand/plus/views/layers/POIMapLayer.java | 4 +- .../views/layers/TravelSelectionLayer.java | 3 +- .../plus/wikivoyage/data/TravelDbHelper.java | 3 +- .../plus/wikivoyage/data/TravelHelper.java | 2 +- .../plus/wikivoyage/data/TravelObfHelper.java | 4 +- 9 files changed, 43 insertions(+), 24 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index 6790a7068b3..a7e5bba8abf 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -105,7 +105,7 @@ void openTrack(MapActivity mapActivity) { String name = amenity.getTagContent(Amenity.ROUTE_NAME); TravelArticle article = travelHelper.getArticleByTitle(name, lang, true, null); if (article != null) { - travelHelper.openTrackMenu(article, mapActivity, name, amenity.getLocation()); + travelHelper.openTrackMenu(article, mapActivity, name, amenity.getLocation(), false); } } diff --git a/OsmAnd/src/net/osmand/plus/search/dialogs/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/dialogs/QuickSearchListFragment.java index ccdadc58206..b00aacdea09 100644 --- a/OsmAnd/src/net/osmand/plus/search/dialogs/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/dialogs/QuickSearchListFragment.java @@ -16,7 +16,10 @@ import androidx.fragment.app.FragmentActivity; import net.osmand.IndexConstants; +import net.osmand.data.Amenity; import net.osmand.data.PointDescription; +import net.osmand.plus.wikivoyage.data.TravelGpx; +import net.osmand.plus.wikivoyage.data.TravelHelper; import net.osmand.shared.gpx.GpxFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -175,27 +178,42 @@ public boolean isShowResult() { public void showResult(SearchResult searchResult) { showResult = false; if (searchResult.objectType == ObjectType.GPX_TRACK) { - GPXInfo gpxInfo = (GPXInfo) searchResult.relatedObject; - if (dialogFragment.getSearchType().isTargetPoint()) { - File file = gpxInfo.getFile(); - if (file != null) { - selectTrack(file); - } - } else { - showTrackMenuFragment(gpxInfo); - } + showGpxTrackResult(searchResult); } else if (searchResult.location != null) { - Pair pair = QuickSearchListItem.getPointDescriptionObject(app, searchResult); + showResultWithLocation(searchResult); + } + } + + private void showResultWithLocation(SearchResult searchResult) { + Pair pair = QuickSearchListItem.getPointDescriptionObject(app, searchResult); - dialogFragment.hideToolbar(); - dialogFragment.hide(); + dialogFragment.hideToolbar(); + dialogFragment.hide(); + if (pair.second instanceof Amenity && ((Amenity) pair.second).isRouteTrack()) { + 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); + } else { showOnMap(getMapActivity(), dialogFragment, searchResult.location.getLatitude(), searchResult.location.getLongitude(), searchResult.preferredZoom, pair.first, pair.second); } } + private void showGpxTrackResult(SearchResult searchResult) { + GPXInfo gpxInfo = (GPXInfo) searchResult.relatedObject; + if (dialogFragment.getSearchType().isTargetPoint()) { + File file = gpxInfo.getFile(); + if (file != null) { + selectTrack(file); + } + } else { + showTrackMenuFragment(gpxInfo); + } + } + private void selectTrack(@NonNull File file) { SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(file.getAbsolutePath()); if (selectedGpxFile != null) { diff --git a/OsmAnd/src/net/osmand/plus/track/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/track/helpers/GpxUiHelper.java index 4cacb0fc1a2..6a0da8d23fd 100644 --- a/OsmAnd/src/net/osmand/plus/track/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/track/helpers/GpxUiHelper.java @@ -625,7 +625,8 @@ public static void saveAndOpenGpx(@NonNull MapActivity mapActivity, @NonNull GpxFile gpxFile, @NonNull WptPt selectedPoint, @Nullable GpxTrackAnalysis analyses, - @Nullable RouteKey routeKey) { + @Nullable RouteKey routeKey, + boolean adjustMapPosition) { SaveGpxHelper.saveGpx(file, gpxFile, errorMessage -> { if (errorMessage == null) { OsmandApplication app = mapActivity.getMyApplication(); @@ -634,7 +635,7 @@ public static void saveAndOpenGpx(@NonNull MapActivity mapActivity, GpxTrackAnalysis trackAnalysis = analyses != null ? analyses : selectedGpxFile.getTrackAnalysis(app); SelectedGpxPoint selectedGpxPoint = new SelectedGpxPoint(selectedGpxFile, selectedPoint); Bundle bundle = new Bundle(); - bundle.putBoolean(TrackMenuFragment.ADJUST_MAP_POSITION, false); + bundle.putBoolean(TrackMenuFragment.ADJUST_MAP_POSITION, adjustMapPosition); TrackMenuFragment.showInstance(mapActivity, selectedGpxFile, selectedGpxPoint, trackAnalysis, routeKey, bundle); } else { diff --git a/OsmAnd/src/net/osmand/plus/views/layers/NetworkRouteSelectionLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/NetworkRouteSelectionLayer.java index be9503aa55d..5d7959ef482 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/NetworkRouteSelectionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/NetworkRouteSelectionLayer.java @@ -154,7 +154,7 @@ private void saveAndOpenGpx(@NonNull GpxFile gpxFile, @NonNull Pair Date: Tue, 19 Nov 2024 20:02:24 +0100 Subject: [PATCH 07/60] Refactor buildGpxFile to support TravelGpx (draft) --- .../plus/wikivoyage/data/TravelObfHelper.java | 62 +++++++++++-------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 01922b4d1ae..d6e40d38672 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -44,6 +44,7 @@ import net.osmand.OsmAndCollator; import net.osmand.PlatformUtil; import net.osmand.ResultMatcher; +import net.osmand.plus.Version; import net.osmand.plus.shared.SharedUtil; import net.osmand.binary.BinaryMapDataObject; import net.osmand.binary.BinaryMapIndexReader; @@ -1087,15 +1088,10 @@ public void saveOrRemoveArticle(@NonNull TravelArticle article, boolean save) { } } - @Nullable - private synchronized GpxFile buildGpxFile(@NonNull List readers, TravelArticle article) { - List segmentList = new ArrayList<>(); - Map gpxFileExtensions = new HashMap<>(); - List pointList = new ArrayList<>(); - List pgNames = new ArrayList<>(); - List pgIcons = new ArrayList<>(); - List pgColors = new ArrayList<>(); - List pgBackgrounds = new ArrayList<>(); + private void fetchSegmentsAndPoints(List readers, TravelArticle article, + List segmentList, List pointList, + Map gpxFileExtensions, List pgNames, + List pgIcons, List pgColors, List pgBackgrounds) { for (BinaryMapIndexReader reader : readers) { try { if (article.file != null && !article.file.equals(reader.getFile())) { @@ -1116,7 +1112,6 @@ public boolean publish(BinaryMapDataObject object) { } return false; } - @Override public boolean isCancelled() { return false; @@ -1127,7 +1122,6 @@ public boolean isCancelled() { } reader.searchMapIndex(sr); } - BinaryMapIndexReader.SearchRequest pointRequest = BinaryMapIndexReader.buildSearchPoiRequest( 0, 0, Algorithms.emptyIfNull(article.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, getSearchFilter(article.getMainFilterString(), article.getPointFilterString()), @@ -1154,6 +1148,8 @@ public boolean publish(Amenity amenity) { } else if (OBF_POINTS_GROUPS_BACKGROUNDS.equals(key)) { pgBackgrounds.addAll(values); } + } else { + // TODO detect relation_gpx==yes and store tags with osm_ prefix } } } else if (ROUTE_TRACK_POINT.equals(amenity.getSubType())) { @@ -1167,7 +1163,6 @@ public boolean publish(Amenity amenity) { } return false; } - @Override public boolean isCancelled() { return false; @@ -1188,9 +1183,36 @@ public boolean isCancelled() { LOG.error(e.getMessage()); } } - GpxFile gpxFile = null; - String description = article.getDescription(); - String title = FileUtils.isValidFileName(description) ? description : article.getTitle(); + } + + @Nullable + private synchronized GpxFile buildGpxFile(@NonNull List readers, TravelArticle article) { + List segmentList = new ArrayList<>(); + Map gpxFileExtensions = new HashMap<>(); + List pointList = new ArrayList<>(); + List pgNames = new ArrayList<>(); + List pgIcons = new ArrayList<>(); + List pgColors = new ArrayList<>(); + List pgBackgrounds = new ArrayList<>(); + + fetchSegmentsAndPoints(readers, article, segmentList, pointList, gpxFileExtensions, + pgNames, pgIcons, pgColors, pgBackgrounds); + + GpxFile gpxFile; + + if (article instanceof TravelGpx) { + gpxFile = new GpxFile(Version.getFullVersion(app)); + // TODO set activity, name, description, etc (gpxFileExtensions) + } else { + String description = article.getDescription(); + String title = FileUtils.isValidFileName(description) ? description : article.getTitle(); + gpxFile = new GpxFile(title, article.getLang(), article.getContent()); + } + + if (!Algorithms.isEmpty(article.getImageTitle())) { + gpxFile.getMetadata().setLink(TravelArticle.getImageUrl(article.getImageTitle(), false)); + } + if (!segmentList.isEmpty()) { boolean hasAltitude = false; Track track = new Track(); @@ -1216,10 +1238,6 @@ public boolean isCancelled() { } track.getSegments().add(trkSegment); } - gpxFile = new GpxFile(title, article.getLang(), article.getContent()); - if (!Algorithms.isEmpty(article.getImageTitle())) { - gpxFile.getMetadata().setLink(TravelArticle.getImageUrl(article.getImageTitle(), false)); - } gpxFile.setTracks(new ArrayList<>()); gpxFile.getTracks().add(track); gpxFile.setRef(article.ref); @@ -1228,12 +1246,6 @@ public boolean isCancelled() { } reconstructPointsGroups(gpxFile, pgNames, pgIcons, pgColors, pgBackgrounds); // create groups before points if (!pointList.isEmpty()) { - if (gpxFile == null) { - gpxFile = new GpxFile(title, article.getLang(), article.getContent()); - if (!Algorithms.isEmpty(article.getImageTitle())) { - gpxFile.getMetadata().setLink(TravelArticle.getImageUrl(article.getImageTitle(), false)); - } - } for (Amenity wayPoint : pointList) { gpxFile.addPoint(article.createWptPt(wayPoint, article.getLang())); } From 589b1a12d06e516c50785882748d9d575baea3c4 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Thu, 21 Nov 2024 17:10:49 +0100 Subject: [PATCH 08/60] Replace ROUTE_ACTIVITIES_PREFIX with ROUTES_PREFIX --- OsmAnd-java/src/main/java/net/osmand/data/Amenity.java | 4 ++-- OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java | 2 +- .../src/main/java/net/osmand/search/SearchUICore.java | 4 ++-- OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java | 4 ++-- OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java | 2 +- .../net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java index 39364c4bb48..bd6787c2eb9 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java @@ -2,7 +2,7 @@ import static net.osmand.gpx.GPXUtilities.AMENITY_PREFIX; import static net.osmand.gpx.GPXUtilities.OSM_PREFIX; -import static net.osmand.osm.MapPoiTypes.ROUTE_ACTIVITIES_PREFIX; +import static net.osmand.osm.MapPoiTypes.ROUTES_PREFIX; import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK; import net.osmand.Location; @@ -552,7 +552,7 @@ public boolean isPrivateAccess() { } public boolean isRouteTrack() { - return subType != null && (subType.equals(ROUTE_TRACK) || subType.startsWith(ROUTE_ACTIVITIES_PREFIX)); + return subType != null && (subType.equals(ROUTE_TRACK) || subType.startsWith(ROUTES_PREFIX)); } public JSONObject toJSON() { diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 561d71e32fa..9e769098df1 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -49,7 +49,7 @@ public class MapPoiTypes { public static final String ROUTE_ARTICLE_POINT = "route_article_point"; public static final String CATEGORY = "category"; public static final String ROUTE_TRACK = "route_track"; // routes:route_track (no activity) - public static final String ROUTE_ACTIVITIES_PREFIX = "activities_"; // routes:activity_xxx (without :route_track) + public static final String ROUTES_PREFIX = "routes_"; // routes:routes_xxx (activity type) public static final String ROUTE_TRACK_POINT = "route_track_point"; private PoiTranslator poiTranslator = null; diff --git a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java index ccd3acf7067..e9ff6ea2594 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -1,7 +1,7 @@ package net.osmand.search; import static net.osmand.data.Amenity.ROUTE_ID; -import static net.osmand.osm.MapPoiTypes.ROUTE_ACTIVITIES_PREFIX; +import static net.osmand.osm.MapPoiTypes.ROUTES_PREFIX; import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK; import net.osmand.CallbackWithObject; @@ -294,7 +294,7 @@ public boolean sameSearchResult(SearchResult r1, SearchResult r2) { similarityRadius = 50000; } if (Algorithms.stringsEqual(a1.getAdditionalInfo(ROUTE_ID), a2.getAdditionalInfo(ROUTE_ID)) - && (subType1.startsWith(ROUTE_ACTIVITIES_PREFIX) || subType1.equals(ROUTE_TRACK))) { + && (subType1.startsWith(ROUTES_PREFIX) || subType1.equals(ROUTE_TRACK))) { similarityRadius = 50000; } } diff --git a/OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java b/OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java index 30d7ce493e0..61f344c0ab6 100644 --- a/OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java +++ b/OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java @@ -3,7 +3,7 @@ import static net.osmand.IProgress.EMPTY_PROGRESS; import static net.osmand.IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT; import static net.osmand.IndexConstants.WIKIVOYAGE_INDEX_DIR; -import static net.osmand.osm.MapPoiTypes.ROUTE_ACTIVITIES_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; @@ -276,7 +276,7 @@ public void updateRouteTrackFilters() { PoiCategory routes = app.getPoiTypes().getRoutes(); for (PoiType subType : routes.getPoiTypes()) { String subTypeKeyName = subType.getKeyName(); - if (subTypeKeyName.startsWith(ROUTE_ACTIVITIES_PREFIX)) { + if (subTypeKeyName.startsWith(ROUTES_PREFIX)) { routeTrackFilters.add(app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + subTypeKeyName)); } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java index 6ed1469905b..97f87992b76 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java @@ -101,6 +101,6 @@ public String getPointFilterString() { @NonNull @Override public String getMainFilterString() { - return ROUTE_TRACK; // considered together with ROUTE_ACTIVITIES_PREFIX + return ROUTE_TRACK; // considered together with ROUTES_PREFIX } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index d6e40d38672..d94a6e7cab4 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -4,7 +4,7 @@ import static net.osmand.data.Amenity.REF; import static net.osmand.data.Amenity.ROUTE; import static net.osmand.data.Amenity.ROUTE_ID; -import static net.osmand.osm.MapPoiTypes.ROUTE_ACTIVITIES_PREFIX; +import static net.osmand.osm.MapPoiTypes.ROUTES_PREFIX; import static net.osmand.osm.MapPoiTypes.ROUTE_ARTICLE; import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK; import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK_POINT; @@ -332,8 +332,8 @@ public boolean accept(PoiCategory type, String subcategory) { if (subcategory.equals(filter)) { return true; } - if (ROUTE_TRACK.equals(filter) && subcategory.startsWith(ROUTE_ACTIVITIES_PREFIX)) { - return true; // include routes:activites_xxx by routes:route_track filter + if (ROUTE_TRACK.equals(filter) && subcategory.startsWith(ROUTES_PREFIX)) { + return true; // include routes:routes_xxx by routes:route_track filter } } return false; From d15c1dd0f9bc9a46e73764e52eed0992a2846534 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Thu, 21 Nov 2024 17:12:48 +0100 Subject: [PATCH 09/60] Change poi_activities_ to poi_routes_ in phrases --- OsmAnd/res/values-b+sr+Latn/phrases.xml | 22 +++++++++++----------- OsmAnd/res/values-cs/phrases.xml | 22 +++++++++++----------- OsmAnd/res/values-de/phrases.xml | 22 +++++++++++----------- OsmAnd/res/values-eo/phrases.xml | 22 +++++++++++----------- OsmAnd/res/values-es-rAR/phrases.xml | 22 +++++++++++----------- OsmAnd/res/values-es-rUS/phrases.xml | 22 +++++++++++----------- OsmAnd/res/values-es/phrases.xml | 22 +++++++++++----------- OsmAnd/res/values-et/phrases.xml | 22 +++++++++++----------- OsmAnd/res/values-hu/phrases.xml | 18 +++++++++--------- OsmAnd/res/values-is/phrases.xml | 22 +++++++++++----------- OsmAnd/res/values-pt-rBR/phrases.xml | 20 ++++++++++---------- OsmAnd/res/values-sr/phrases.xml | 22 +++++++++++----------- OsmAnd/res/values-uk/phrases.xml | 22 +++++++++++----------- OsmAnd/res/values-zh-rTW/phrases.xml | 22 +++++++++++----------- OsmAnd/res/values/phrases.xml | 22 +++++++++++----------- 15 files changed, 162 insertions(+), 162 deletions(-) diff --git a/OsmAnd/res/values-b+sr+Latn/phrases.xml b/OsmAnd/res/values-b+sr+Latn/phrases.xml index 1c36c26ec7f..09148ee6f52 100644 --- a/OsmAnd/res/values-b+sr+Latn/phrases.xml +++ b/OsmAnd/res/values-b+sr+Latn/phrases.xml @@ -4884,17 +4884,17 @@ Tačke na putovanjima Druge rute Tačke drugih ruta - Bicikl - Pešačenje - Trčanje - Hodanje - Sportovi na vodi - Zimski sportovi - Koturaljke - Jahanje konja - Motorne sanke - Staze za trčanje - Brdski biciklizam + Bicikl + Pešačenje + Trčanje + Hodanje + Sportovi na vodi + Zimski sportovi + Koturaljke + Jahanje konja + Motorne sanke + Staze za trčanje + Brdski biciklizam Etimologija imena Naziv leve strane Naziv desne strane diff --git a/OsmAnd/res/values-cs/phrases.xml b/OsmAnd/res/values-cs/phrases.xml index ade19578473..799f6de2c9d 100644 --- a/OsmAnd/res/values-cs/phrases.xml +++ b/OsmAnd/res/values-cs/phrases.xml @@ -4884,15 +4884,15 @@ Body na cestách Další trasy Další body trasy - Kolo - Pěší turistika - Běh - Chůze - Vodní sporty - Jízda na koni - Zimní sporty - Sněžný skútr - Fitness stezky - Inline brusle - Horská cyklistika + Kolo + Pěší turistika + Běh + Chůze + Vodní sporty + Jízda na koni + Zimní sporty + Sněžný skútr + Fitness stezky + Inline brusle + Horská cyklistika \ No newline at end of file diff --git a/OsmAnd/res/values-de/phrases.xml b/OsmAnd/res/values-de/phrases.xml index ed910d31937..1b215de9826 100644 --- a/OsmAnd/res/values-de/phrases.xml +++ b/OsmAnd/res/values-de/phrases.xml @@ -4881,20 +4881,20 @@ Tunnel für Fußgänger verboten Tunnel für Radfahrer verboten Reisepunkte - Wassersport - Gehen - Reiten + Wassersport + Gehen + Reiten Reiseartikel Andere Routen Weitere Routenpunkte - Fahrrad - Wandern - Laufen - Wintersport - Schneemobil - Fitness-Parcour - Inline-Skate - Mountainbiken + Fahrrad + Wandern + Laufen + Wintersport + Schneemobil + Fitness-Parcour + Inline-Skate + Mountainbiken Namensetymologie Name der linken Seite Name der rechten Seite diff --git a/OsmAnd/res/values-eo/phrases.xml b/OsmAnd/res/values-eo/phrases.xml index 34592601754..2dad38deff3 100644 --- a/OsmAnd/res/values-eo/phrases.xml +++ b/OsmAnd/res/values-eo/phrases.xml @@ -4880,17 +4880,17 @@ Vojaĝaj punktoj Aliaj kursoj Aliaj kursoj: punktoj - Biciklado - Marŝado - Kurado - Irado - Akvaj sportoj - Ĉevalrajdado - Vintraj sportoj - Motorsledado - Vojetoj de sportiloj - Rulglitado - Montbiciklado + Biciklado + Marŝado + Kurado + Irado + Akvaj sportoj + Ĉevalrajdado + Vintraj sportoj + Motorsledado + Vojetoj de sportiloj + Rulglitado + Montbiciklado Parco Parco malakceptata Parkster diff --git a/OsmAnd/res/values-es-rAR/phrases.xml b/OsmAnd/res/values-es-rAR/phrases.xml index 83caaec0af0..4a6b004506c 100644 --- a/OsmAnd/res/values-es-rAR/phrases.xml +++ b/OsmAnd/res/values-es-rAR/phrases.xml @@ -4884,15 +4884,15 @@ Puntos turísticos Otras rutas Otros puntos de ruta - Bicicleta - Senderismo - Correr - Peatón - Deportes acuáticos - Equitación - Deportes de invierno - Motonieve - Circuitos aeróbicos - Patines en línea - Ciclismo de montaña + Bicicleta + Senderismo + Correr + Peatón + Deportes acuáticos + Equitación + Deportes de invierno + Motonieve + Circuitos aeróbicos + Patines en línea + Ciclismo de montaña \ No newline at end of file diff --git a/OsmAnd/res/values-es-rUS/phrases.xml b/OsmAnd/res/values-es-rUS/phrases.xml index 44dae07f6ea..9662da400c3 100644 --- a/OsmAnd/res/values-es-rUS/phrases.xml +++ b/OsmAnd/res/values-es-rUS/phrases.xml @@ -4979,15 +4979,15 @@ Puntos turísticos Otras rutas Otros puntos de ruta - Bicicleta - Senderismo - Correr - Peatón - Deportes acuáticos - Equitación - Deportes de invierno - Motonieve - Circuitos aeróbicos - Patines en línea - Ciclismo de montaña + Bicicleta + Senderismo + Correr + Peatón + Deportes acuáticos + Equitación + Deportes de invierno + Motonieve + Circuitos aeróbicos + Patines en línea + Ciclismo de montaña \ No newline at end of file diff --git a/OsmAnd/res/values-es/phrases.xml b/OsmAnd/res/values-es/phrases.xml index a2740517963..e9f931345ed 100644 --- a/OsmAnd/res/values-es/phrases.xml +++ b/OsmAnd/res/values-es/phrases.xml @@ -4880,21 +4880,21 @@ Parco Túnel prohibido para peatones Túnel prohibido para ciclistas - Bicicleta - Senderismo - Correr - Peatonal - Deportes acuáticos - Equitación - Motonieve - Circuitos aeróbicos - Patines en línea - Bicicleta de montaña + Bicicleta + Senderismo + Correr + Peatonal + Deportes acuáticos + Equitación + Motonieve + Circuitos aeróbicos + Patines en línea + Bicicleta de montaña Artículos de viajes Puntos del viaje Otras rutas Otros puntos de la ruta - Deportes de invierno + Deportes de invierno Nombre en el lado izquierdo Etimología del nombre Nombre en el lado derecho diff --git a/OsmAnd/res/values-et/phrases.xml b/OsmAnd/res/values-et/phrases.xml index 53c9720e90f..297f5ffcd0b 100644 --- a/OsmAnd/res/values-et/phrases.xml +++ b/OsmAnd/res/values-et/phrases.xml @@ -4872,19 +4872,19 @@ Rattateede võrgustik Kategooria: määramine Kategooria: servituut - Veespordialad - Kõndimine - Jooksmine - Matkamine - Rattasõit + Veespordialad + Kõndimine + Jooksmine + Matkamine + Rattasõit Muud teekonnapunktid Muud teekonnad - Talispordialad - Ratsutamine - Rulluisutamine üherealiste uiskudega - Terviserajad - Mootorsaanisõit - Mägirattasõit + Talispordialad + Ratsutamine + Rulluisutamine üherealiste uiskudega + Terviserajad + Mootorsaanisõit + Mägirattasõit Parksteri teenus pole kasutatav Parkster Parco teenus pole kasutatav diff --git a/OsmAnd/res/values-hu/phrases.xml b/OsmAnd/res/values-hu/phrases.xml index 7aad4e32fa8..52040a5dd36 100644 --- a/OsmAnd/res/values-hu/phrases.xml +++ b/OsmAnd/res/values-hu/phrases.xml @@ -4880,14 +4880,14 @@ Parcót nem fogad el Parkster Parkstert nem fogad el - Vízi sportok - Lovaglás - Téli sportok - Hójáró - Hegyi kerékpározás + Vízi sportok + Lovaglás + Téli sportok + Hójáró + Hegyi kerékpározás Egyéb útvonalak - Kerékpározás - Futás - Gyaloglás - Túrázás + Kerékpározás + Futás + Gyaloglás + Túrázás \ No newline at end of file diff --git a/OsmAnd/res/values-is/phrases.xml b/OsmAnd/res/values-is/phrases.xml index 0bbfa51f5e5..2e048be1665 100644 --- a/OsmAnd/res/values-is/phrases.xml +++ b/OsmAnd/res/values-is/phrases.xml @@ -4932,23 +4932,23 @@ Flúð Fjársjóðaleit á strönd Túlkunarsvæði - Línuskautar - Fjallahjólreiðar + Línuskautar + Fjallahjólreiðar Göng bönnuð fyrir gangandi Göng bönnuð fyrir hjólandi Ferðagreinar Punktar ferðar Aðrar leiðir Punktar í öðrum leiðum - Hjólandi - Gönguferðir - Hlaupandi - Gangandi - Vatnaíþróttir - Hestaferðir - Vetraríþróttir - Vélsleðar - Fitness-leiðir + Hjólandi + Gönguferðir + Hlaupandi + Gangandi + Vatnaíþróttir + Hestaferðir + Vetraríþróttir + Vélsleðar + Fitness-leiðir Nafn hægra megin Orðsifjar nafns Nafn vinstra megin diff --git a/OsmAnd/res/values-pt-rBR/phrases.xml b/OsmAnd/res/values-pt-rBR/phrases.xml index 6f9c21b7334..fa5ecd5dbe2 100644 --- a/OsmAnd/res/values-pt-rBR/phrases.xml +++ b/OsmAnd/res/values-pt-rBR/phrases.xml @@ -4874,21 +4874,21 @@ Depósito de dinheiro Acesso Outras rotas - Corrida + Corrida Túnel proibido para pedestres Túnel proibido para ciclistas Artigos de viagem Pontos de viagem Outros pontos de rotas - Bicicleta - Caminhada - A pé - Esportes aquáticos - Local de equitação - Esportes de inverno - Moto de neve - Trilhas de exercícios - Patins em linha + Bicicleta + Caminhada + A pé + Esportes aquáticos + Local de equitação + Esportes de inverno + Moto de neve + Trilhas de exercícios + Patins em linha Parco não aceito Parkster não aceito \ No newline at end of file diff --git a/OsmAnd/res/values-sr/phrases.xml b/OsmAnd/res/values-sr/phrases.xml index e7331ffac03..6bb8e7448a2 100644 --- a/OsmAnd/res/values-sr/phrases.xml +++ b/OsmAnd/res/values-sr/phrases.xml @@ -4884,20 +4884,20 @@ Тунел забрањен за бициклисте Тунел забрањен за пешаке Тачке на путовањима - Планинарење - Спортови на води - Јахање коња - Зимски спортови - Моторне санке - Брдски бициклизам + Планинарење + Спортови на води + Јахање коња + Зимски спортови + Моторне санке + Брдски бициклизам Чланци о путовањима Друге руте Тачке других рута - Бицикл - Пешачење - Трчање - Стазе за трчање - Котураљке + Бицикл + Пешачење + Трчање + Стазе за трчање + Котураљке Етимологија имена Назив леве стране Назив десне стране diff --git a/OsmAnd/res/values-uk/phrases.xml b/OsmAnd/res/values-uk/phrases.xml index 00b5b82fd35..32ac7a102cc 100644 --- a/OsmAnd/res/values-uk/phrases.xml +++ b/OsmAnd/res/values-uk/phrases.xml @@ -4881,17 +4881,17 @@ Пункти Інші маршрути Інші пункти маршруту - Велосипед - Піший туризм - Біг - Ходьба - Водні види спорту - Верхова їзда - Зимові види спорту - Снігохід - Фітнес-стежки - Роликові ковзани - Катання на гірських велосипедах + Велосипед + Піший туризм + Біг + Ходьба + Водні види спорту + Верхова їзда + Зимові види спорту + Снігохід + Фітнес-стежки + Роликові ковзани + Катання на гірських велосипедах Паркомісце не прийнято Паркомісце Паркер не прийнято diff --git a/OsmAnd/res/values-zh-rTW/phrases.xml b/OsmAnd/res/values-zh-rTW/phrases.xml index a8b2b3b4382..bff96cd335e 100644 --- a/OsmAnd/res/values-zh-rTW/phrases.xml +++ b/OsmAnd/res/values-zh-rTW/phrases.xml @@ -4882,19 +4882,19 @@ 隧道禁止腳踏車騎士通行 其他路線 其他路線點 - 腳踏車 - 騎馬 - 冬季運動 - 雪地摩托車 - 直排輪鞋 - 山區騎乘 + 腳踏車 + 騎馬 + 冬季運動 + 雪地摩托車 + 直排輪鞋 + 山區騎乘 旅遊點 旅遊文章 - 健行 - 跑步 - 步行 - 水上運動 - 健身路徑 + 健行 + 跑步 + 步行 + 水上運動 + 健身路徑 名稱詞源學 左側的名稱 右側的名稱 diff --git a/OsmAnd/res/values/phrases.xml b/OsmAnd/res/values/phrases.xml index c59350606b3..bf7d2b21ae5 100644 --- a/OsmAnd/res/values/phrases.xml +++ b/OsmAnd/res/values/phrases.xml @@ -5455,17 +5455,17 @@ Travel Points Other routes Other routes points - Bicycle - Hiking - Running - Walking - Water sports - Horse riding - Winter sports - Snowmobile - Fitness trails - Inline skates - Mountain biking + Bicycle + Hiking + Running + Walking + Water sports + Horse riding + Winter sports + Snowmobile + Fitness trails + Inline skates + Mountain biking Name etymology Name of the left side From 3c0cf79461dda7c0d8e86e1be2d5d0185bef7bcb Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Fri, 22 Nov 2024 14:51:53 +0100 Subject: [PATCH 10/60] Fix incorrect parseFloat / parseDouble "try" block --- .../plus/wikivoyage/data/TravelGpx.java | 2 ++ .../plus/wikivoyage/data/TravelObfHelper.java | 27 +++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java index 97f87992b76..20ff2a5ba3c 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java @@ -27,6 +27,8 @@ public class TravelGpx extends TravelArticle { public static final String MAX_ELEVATION = "max_ele"; public static final String MIN_ELEVATION = "min_ele"; public static final String AVERAGE_ELEVATION = "avg_ele"; + public static final String START_ELEVATION = "start_ele"; + public static final String ELE_GRAPH = "ele_graph"; public static final String ROUTE_RADIUS = "route_radius"; public static final String USER = "user"; public static final String ACTIVITY_TYPE = "route_activity_type"; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index d94a6e7cab4..bc1bea48b74 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -14,10 +14,13 @@ import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELEVATION_DOWN; import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELEVATION_UP; import static net.osmand.plus.wikivoyage.data.TravelGpx.DISTANCE; +import static net.osmand.plus.wikivoyage.data.TravelGpx.ELE_GRAPH; 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_RADIUS; +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.OSM_PREFIX; import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_BACKGROUNDS; import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_COLORS; import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_DELIMITER; @@ -91,6 +94,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -306,12 +310,18 @@ private TravelGpx getTravelGpx(File file, Amenity amenity) { travelGpx.activityType = Algorithms.emptyIfNull(amenity.getTagContent(ACTIVITY_TYPE)); travelGpx.ref = Algorithms.emptyIfNull(amenity.getRef()); try { - travelGpx.totalDistance = Float.parseFloat(Algorithms.emptyIfNull(amenity.getTagContent(DISTANCE))); - travelGpx.diffElevationUp = Double.parseDouble(Algorithms.emptyIfNull(amenity.getTagContent(DIFF_ELEVATION_UP))); - travelGpx.diffElevationDown = Double.parseDouble(Algorithms.emptyIfNull(amenity.getTagContent(DIFF_ELEVATION_DOWN))); - travelGpx.maxElevation = Double.parseDouble(Algorithms.emptyIfNull(amenity.getTagContent(MAX_ELEVATION))); - travelGpx.minElevation = Double.parseDouble(Algorithms.emptyIfNull(amenity.getTagContent(MIN_ELEVATION))); - travelGpx.avgElevation = Double.parseDouble(Algorithms.emptyIfNull(amenity.getTagContent(AVERAGE_ELEVATION))); + travelGpx.totalDistance = Float.parseFloat(Objects.requireNonNullElse( + amenity.getTagContent(DISTANCE), "0")); + travelGpx.diffElevationUp = Double.parseDouble(Objects.requireNonNullElse( + amenity.getTagContent(DIFF_ELEVATION_UP), "0")); + travelGpx.diffElevationDown = Double.parseDouble(Objects.requireNonNullElse( + amenity.getTagContent(DIFF_ELEVATION_DOWN), "0")); + travelGpx.minElevation = Double.parseDouble(Objects.requireNonNullElse( + amenity.getTagContent(MIN_ELEVATION), "0")); + travelGpx.avgElevation = Double.parseDouble(Objects.requireNonNullElse( + amenity.getTagContent(AVERAGE_ELEVATION), "0")); + travelGpx.maxElevation = Double.parseDouble(Objects.requireNonNullElse( + amenity.getTagContent(MAX_ELEVATION), "0")); String radius = amenity.getTagContent(ROUTE_RADIUS); if (radius != null) { travelGpx.routeRadius = MapUtils.convertCharToDist(radius.charAt(0), TRAVEL_GPX_CONVERT_FIRST_LETTER, @@ -1224,13 +1234,14 @@ private synchronized GpxFile buildGpxFile(@NonNull List re point.setLon(MapUtils.get31LongitudeX(segment.getPoint31XTile(i))); trkSegment.getPoints().add(point); } - String ele_graph = segment.getTagValue("ele_graph"); + String ele_graph = segment.getTagValue(ELE_GRAPH); if (!Algorithms.isEmpty(ele_graph)) { hasAltitude = true; List heightRes = KMapAlgorithms.INSTANCE.decodeIntHeightArrayGraph(ele_graph, 3); double startEle = 0; try { - startEle = Double.parseDouble(segment.getTagValue("start_ele")); + startEle = Double.parseDouble(Objects.requireNonNullElse( + segment.getTagValue(START_ELEVATION), "0")); } catch (NumberFormatException e) { LOG.debug(e.getMessage(), e); } From 2b8cde44b4e38fb018e19ec735069d0c53416b1a Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Fri, 22 Nov 2024 19:13:02 +0100 Subject: [PATCH 11/60] Implement better gpxFileName scheme for TravelGpx --- .../src/main/java/net/osmand/data/Amenity.java | 16 ++++++++++++++++ .../search/dialogs/QuickSearchListFragment.java | 2 +- .../osmand/plus/views/layers/POIMapLayer.java | 4 ++-- .../plus/views/layers/TravelSelectionLayer.java | 2 +- .../plus/wikivoyage/data/TravelArticle.java | 4 ++++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java index bd6787c2eb9..f7d21c7792c 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java @@ -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; @@ -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); diff --git a/OsmAnd/src/net/osmand/plus/search/dialogs/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/dialogs/QuickSearchListFragment.java index b00aacdea09..f45244446e5 100644 --- a/OsmAnd/src/net/osmand/plus/search/dialogs/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/dialogs/QuickSearchListFragment.java @@ -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(), diff --git a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java index 26f682376dd..56a428e3296 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java @@ -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; @@ -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; } } diff --git a/OsmAnd/src/net/osmand/plus/views/layers/TravelSelectionLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/TravelSelectionLayer.java index 3bb499d159d..bac5fe3b222 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/TravelSelectionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/TravelSelectionLayer.java @@ -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; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java index 0272ad2f932..da340c0ebf9 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java @@ -127,6 +127,10 @@ public String getRouteId() { return routeId; } + public String getGpxFileName() { + return !Algorithms.isEmpty(title) ? title : routeId; + } + public String getRouteSource() { return routeSource; } From 7fd3bbc68303267c03ea8c01c6019f98fcc16842 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Sun, 24 Nov 2024 16:10:25 +0100 Subject: [PATCH 12/60] Allow Amenity OpenTrack menu for ROUTE_TRACK_POINT --- .../controllers/AmenityMenuController.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index a7e5bba8abf..5a305084da1 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -1,6 +1,7 @@ package net.osmand.plus.mapcontextmenu.controllers; import static net.osmand.osm.MapPoiTypes.ROUTE_ARTICLE_POINT; +import static net.osmand.osm.MapPoiTypes.ROUTE_TRACK_POINT; import android.graphics.drawable.Drawable; import android.text.TextUtils; @@ -25,6 +26,7 @@ import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.wikipedia.WikipediaDialogFragment; import net.osmand.plus.wikivoyage.data.TravelArticle; +import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelHelper; import net.osmand.util.Algorithms; import net.osmand.util.OpeningHoursParser; @@ -69,7 +71,8 @@ public AmenityMenuController(@NonNull MapActivity mapActivity, new MapMarkerMenuController(mapActivity, marker.getPointDescription(mapActivity), marker); leftTitleButtonController = markerMenuController.getLeftTitleButtonController(); rightTitleButtonController = markerMenuController.getRightTitleButtonController(); - } else if (amenity.getSubType().equals(ROUTE_ARTICLE_POINT)) { + } else if (amenity.getSubType().equals(ROUTE_ARTICLE_POINT) || + amenity.getSubType().equals(ROUTE_TRACK_POINT)) { TitleButtonController openTrackButtonController = new TitleButtonController() { @Override public void buttonPressed() { @@ -101,11 +104,18 @@ public void buttonPressed() { void openTrack(MapActivity mapActivity) { TravelHelper travelHelper = mapActivity.getMyApplication().getTravelHelper(); - String lang = amenity.getTagSuffix(Amenity.LANG_YES + ":"); - String name = amenity.getTagContent(Amenity.ROUTE_NAME); - TravelArticle article = travelHelper.getArticleByTitle(name, lang, true, null); - if (article != null) { - travelHelper.openTrackMenu(article, mapActivity, name, amenity.getLocation(), false); + if (amenity.getSubType().equals(ROUTE_ARTICLE_POINT)) { + String lang = amenity.getTagSuffix(Amenity.LANG_YES + ":"); + String name = amenity.getTagContent(Amenity.ROUTE_NAME); + TravelArticle article = travelHelper.getArticleByTitle(name, lang, true, null); + if (article != null) { + travelHelper.openTrackMenu(article, mapActivity, name, amenity.getLocation(), false); + } + } else if (amenity.getSubType().equals(ROUTE_TRACK_POINT)) { + TravelGpx travelGpx = travelHelper.searchGpx(amenity.getLocation(), amenity.getRouteId(), amenity.getRef()); + if (travelGpx != null) { + travelHelper.openTrackMenu(travelGpx, mapActivity, travelGpx.getTitle(), amenity.getLocation(), false); + } } } From c22f9f1e2be618a489b0e910725f5202e0b6e981 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Sun, 24 Nov 2024 18:05:49 +0100 Subject: [PATCH 13/60] Allow v2 getAmenity() to find route=point w/o name --- .../src/main/java/net/osmand/data/Amenity.java | 5 +++++ .../plus/views/layers/MapSelectionHelper.java | 13 +++++++++++-- .../net/osmand/plus/wikivoyage/data/TravelGpx.java | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java index f7d21c7792c..438ba0d2034 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java @@ -6,6 +6,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.osm.MapPoiTypes.ROUTE_TRACK_POINT; import net.osmand.Location; import net.osmand.binary.BinaryMapIndexReader.TagValuePair; @@ -571,6 +572,10 @@ public boolean isRouteTrack() { return subType != null && (subType.equals(ROUTE_TRACK) || subType.startsWith(ROUTES_PREFIX)); } + public boolean isRoutePoint() { + return subType != null && (subType.equals(ROUTE_TRACK_POINT) || subType.equals(ROUTE_ARTICLE_POINT)); + } + public JSONObject toJSON() { JSONObject json = super.toJSON(); json.put("subType", subType); diff --git a/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java b/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java index 32fc98ef436..7f4690ba4db 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java @@ -2,11 +2,13 @@ import static net.osmand.IndexConstants.GPX_FILE_EXT; import static net.osmand.binary.BinaryMapIndexReader.ACCEPT_ALL_POI_TYPE_FILTER; +import static net.osmand.data.Amenity.ROUTE; import static net.osmand.data.Amenity.ROUTE_ID; import static net.osmand.data.FavouritePoint.DEFAULT_BACKGROUND_TYPE; import static net.osmand.data.MapObject.AMENITY_ID_RIGHT_SHIFT; import static net.osmand.osm.OsmRouteType.HIKING; import static net.osmand.plus.transport.TransportLinesMenu.RENDERING_CATEGORY_TRANSPORT; +import static net.osmand.plus.wikivoyage.data.TravelGpx.TRAVEL_OSM_ID_TAG; import static net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN; import static net.osmand.router.network.NetworkRouteSelector.NetworkRouteSelectorFilter; import static net.osmand.router.network.NetworkRouteSelector.RouteKey; @@ -357,7 +359,7 @@ private void selectObjectsFromOpenGl(@NonNull MapSelectionResult result, @NonNul latLon = l == null ? latLon : l; tags.remove(TAG_POI_LAT_LON); } - amenity = getAmenity(latLon, obfMapObject); + amenity = getAmenity(latLon, obfMapObject, tags); if (amenity != null) { amenity.setMapIconName(getMapIconName(symbolInfo)); } else if (!isOsmRoute && !isTravelGpx) { @@ -438,13 +440,16 @@ private RasterMapSymbol getRasterMapSymbol(@NonNull MapSymbolInformation symbolI return null; } - private Amenity getAmenity(LatLon latLon, ObfMapObject obfMapObject) { + private Amenity getAmenity(LatLon latLon, ObfMapObject obfMapObject, Map tags) { Amenity amenity; List names = getValues(obfMapObject.getCaptionsInAllLanguages()); String caption = obfMapObject.getCaptionInNativeLanguage(); if (!caption.isEmpty()) { names.add(caption); } + if (!Algorithms.isEmpty(tags) && tags.containsKey(TRAVEL_OSM_ID_TAG) && "point".equals(tags.get(ROUTE))) { + names.add(tags.get(TRAVEL_OSM_ID_TAG)); // additional attribute for TravelGpx points (osm_id) + } long id = obfMapObject.getId().getId().longValue(); amenity = findAmenity(app, latLon, names, id); if (amenity != null && obfMapObject.getPoints31().size() > 1) { @@ -711,10 +716,14 @@ public static Amenity findAmenityByOsmId(@NonNull List amenities, long public static Amenity findAmenityByName(@NonNull List amenities, @Nullable List names) { if (!Algorithms.isEmpty(names)) { for (Amenity amenity : amenities) { + String travelOsmId = amenity.isRoutePoint() ? amenity.getAdditionalInfo(TRAVEL_OSM_ID_TAG) : null; for (String name : names) { if (name.equals(amenity.getName()) && !amenity.isClosed()) { return amenity; } + if (travelOsmId != null && name.equals(travelOsmId)) { + return amenity; + } } } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java index 20ff2a5ba3c..cac34ab8af6 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java @@ -32,6 +32,7 @@ public class TravelGpx extends TravelArticle { public static final String ROUTE_RADIUS = "route_radius"; public static final String USER = "user"; public static final String ACTIVITY_TYPE = "route_activity_type"; + public static final String TRAVEL_OSM_ID_TAG = "osm_id"; public String user; public String activityType; From 7f5a9c5df95c6d6d8d503bd436283c0e89cd15b8 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Mon, 25 Nov 2024 14:17:54 +0100 Subject: [PATCH 14/60] Split methods, add GPX tags reconstruction (draft) --- .../plus/wikivoyage/data/TravelObfHelper.java | 189 ++++++++++++------ 1 file changed, 126 insertions(+), 63 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index bc1bea48b74..a1e50048ab7 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -47,6 +47,7 @@ import net.osmand.OsmAndCollator; import net.osmand.PlatformUtil; import net.osmand.ResultMatcher; +import net.osmand.osm.PoiType; import net.osmand.plus.Version; import net.osmand.plus.shared.SharedUtil; import net.osmand.binary.BinaryMapDataObject; @@ -70,6 +71,7 @@ import net.osmand.shared.gpx.GpxFile; import net.osmand.shared.gpx.GpxHelper; import net.osmand.shared.gpx.GpxUtilities; +import net.osmand.shared.gpx.RouteActivityHelper; import net.osmand.shared.gpx.primitives.Track; import net.osmand.shared.gpx.primitives.TrkSegment; import net.osmand.shared.gpx.primitives.WptPt; @@ -1110,23 +1112,7 @@ private void fetchSegmentsAndPoints(List readers, TravelAr if (article instanceof TravelGpx) { BinaryMapIndexReader.SearchRequest sr = BinaryMapIndexReader.buildSearchRequest( 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, 15, null, - new ResultMatcher() { - @Override - public boolean publish(BinaryMapDataObject object) { - if (object.getPointsLength() > 1) { - if (object.getTagValue(REF).equals(article.ref) - && (object.getTagValue(ROUTE_ID).equals(article.routeId) - || createTitle(object.getName()).equals(article.getTitle()))) { - segmentList.add(object); - } - } - return false; - } - @Override - public boolean isCancelled() { - return false; - } - }); + matchSegmentsByRefTitleRouteId(article, segmentList)); if (article.routeRadius >= 0) { sr.setBBoxRadius(article.lat, article.lon, article.routeRadius); } @@ -1135,49 +1121,8 @@ public boolean isCancelled() { BinaryMapIndexReader.SearchRequest pointRequest = BinaryMapIndexReader.buildSearchPoiRequest( 0, 0, Algorithms.emptyIfNull(article.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, getSearchFilter(article.getMainFilterString(), article.getPointFilterString()), - new ResultMatcher() { - @Override - public boolean publish(Amenity amenity) { - if (amenity.getRouteId().equals(article.getRouteId())) { - if (amenity.isRouteTrack()) { - for (String key : amenity.getAdditionalInfoKeys()) { - if (key.startsWith(OBF_GPX_EXTENSION_TAG_PREFIX)) { - String tag = key.replaceFirst(OBF_GPX_EXTENSION_TAG_PREFIX, ""); - String val = amenity.getAdditionalInfo(key); - gpxFileExtensions.put(tag, val); - } else if (key.startsWith(OBF_POINTS_GROUPS_PREFIX)) { - final String delimiter = OBF_POINTS_GROUPS_DELIMITER; - String joinedValues = amenity.getAdditionalInfo(key); - List values = Arrays.asList(joinedValues.split(delimiter)); - if (OBF_POINTS_GROUPS_NAMES.equals(key)) { - pgNames.addAll(values); - } else if (OBF_POINTS_GROUPS_ICONS.equals(key)) { - pgIcons.addAll(values); - } else if (OBF_POINTS_GROUPS_COLORS.equals(key)) { - pgColors.addAll(values); - } else if (OBF_POINTS_GROUPS_BACKGROUNDS.equals(key)) { - pgBackgrounds.addAll(values); - } - } else { - // TODO detect relation_gpx==yes and store tags with osm_ prefix - } - } - } else if (ROUTE_TRACK_POINT.equals(amenity.getSubType())) { - pointList.add(amenity); - } else { - String amenityLang = amenity.getTagSuffix(Amenity.LANG_YES + ":"); - if (Algorithms.stringsEqual(article.lang, amenityLang)) { - pointList.add(amenity); - } - } - } - return false; - } - @Override - public boolean isCancelled() { - return false; - } - }, null); + matchPointsAndTags(article, pointList, gpxFileExtensions, pgNames, pgIcons, pgColors, pgBackgrounds), + null); if (article.routeRadius >= 0) { pointRequest.setBBoxRadius(article.lat, article.lon, article.routeRadius); } @@ -1195,6 +1140,115 @@ public boolean isCancelled() { } } + private static final Set avoidAmenityGpxTags = Set.of( + "date", + "distance", + "route_id", + "route_name", + "route_radius" + ); + + // name, ref, type, route will be processed in a special way + private static final Set keepAsIsAmenityGpxTags = Set.of( + "osm_id", + "relation_gpx", + "shield_" // prefix + ); + + @NonNull + private ResultMatcher matchPointsAndTags(TravelArticle article, List pointList, Map gpxFileExtensions, List pgNames, List pgIcons, List pgColors, List pgBackgrounds) { + return new ResultMatcher() { + @Override + public boolean publish(Amenity amenity) { + if (amenity.getRouteId().equals(article.getRouteId())) { + reconstructGpxTagsFromAmenityType(amenity, gpxFileExtensions); + if (amenity.isRouteTrack()) { + for (String tag : amenity.getAdditionalInfoKeys()) { + String value = amenity.getAdditionalInfo(tag); + if (tag.startsWith(OBF_POINTS_GROUPS_PREFIX)) { + final String delimiter = OBF_POINTS_GROUPS_DELIMITER; + List values = Arrays.asList(value.split(delimiter)); + if (OBF_POINTS_GROUPS_NAMES.equals(tag)) { + pgNames.addAll(values); + } else if (OBF_POINTS_GROUPS_ICONS.equals(tag)) { + pgIcons.addAll(values); + } else if (OBF_POINTS_GROUPS_COLORS.equals(tag)) { + pgColors.addAll(values); + } else if (OBF_POINTS_GROUPS_BACKGROUNDS.equals(tag)) { + pgBackgrounds.addAll(values); + } + } else { + if (tag.startsWith(OBF_GPX_EXTENSION_TAG_PREFIX)) { + String gpxTag = tag.replaceFirst(OBF_GPX_EXTENSION_TAG_PREFIX, ""); + gpxFileExtensions.put(gpxTag, value); + } else if (!avoidAmenityGpxTags.contains(tag)) { + String gpxTag = OSM_PREFIX + tag; + for (String prefix : keepAsIsAmenityGpxTags) { + if (tag.startsWith(prefix)) { + gpxTag = tag; + break; + } + } + gpxFileExtensions.put(gpxTag, value); + } + } + } + } else if (ROUTE_TRACK_POINT.equals(amenity.getSubType())) { + pointList.add(amenity); + } else { + String amenityLang = amenity.getTagSuffix(Amenity.LANG_YES + ":"); + if (Algorithms.stringsEqual(article.lang, amenityLang)) { + pointList.add(amenity); + } + } + } + return false; + } + @Override + public boolean isCancelled() { + return false; + } + }; + } + + private void reconstructGpxTagsFromAmenityType(Amenity amenity, Map gpxFileExtensions) { + if (amenity.isRouteTrack() && amenity.getSubType() != null) { + String subType = amenity.getSubType(); + if (subType.startsWith(ROUTES_PREFIX)) { + String osmValue = amenity.getType().getPoiTypeByKeyName(subType).getOsmValue(); + if (!Algorithms.isEmpty(osmValue)) { + gpxFileExtensions.put(OSM_PREFIX + "type", "route"); + gpxFileExtensions.put(OSM_PREFIX + "route", osmValue); + RouteActivityHelper helper = app.getRouteActivityHelper(); + // TODO wrong way round + gpxFileExtensions.put(GpxUtilities.ACTIVITY_TYPE, subType.replace(ROUTES_PREFIX, "")); + } + } + } + } + + @NonNull + private ResultMatcher matchSegmentsByRefTitleRouteId( + TravelArticle article, List segmentList) { + return new ResultMatcher() { + @Override + public boolean publish(BinaryMapDataObject object) { + if (object.getPointsLength() > 1) { + if (object.getTagValue(REF).equals(article.ref) + && (object.getTagValue(ROUTE_ID).equals(article.routeId) + || createTitle(object.getName()).equals(article.getTitle()))) { + segmentList.add(object); + } + } + return false; + } + @Override + public boolean isCancelled() { + return false; + } + }; + } + @Nullable private synchronized GpxFile buildGpxFile(@NonNull List readers, TravelArticle article) { List segmentList = new ArrayList<>(); @@ -1209,14 +1263,19 @@ private synchronized GpxFile buildGpxFile(@NonNull List re pgNames, pgIcons, pgColors, pgBackgrounds); GpxFile gpxFile; - if (article instanceof TravelGpx) { gpxFile = new GpxFile(Version.getFullVersion(app)); - // TODO set activity, name, description, etc (gpxFileExtensions) + gpxFile.getMetadata().setName(Objects.requireNonNullElse(article.title, article.routeId)); // path is name + if (!Algorithms.isEmpty(article.title)) { + gpxFileExtensions.putIfAbsent(OSM_PREFIX + "name", article.title); + } + if (!Algorithms.isEmpty(article.description)) { + gpxFile.getMetadata().setDesc(article.description); + } } else { String description = article.getDescription(); String title = FileUtils.isValidFileName(description) ? description : article.getTitle(); - gpxFile = new GpxFile(title, article.getLang(), article.getContent()); + gpxFile = new GpxFile(title, article.getLang(), article.getContent()); } if (!Algorithms.isEmpty(article.getImageTitle())) { @@ -1254,6 +1313,10 @@ private synchronized GpxFile buildGpxFile(@NonNull List re gpxFile.setRef(article.ref); gpxFile.setHasAltitude(hasAltitude); gpxFile.getExtensionsToWrite().putAll(gpxFileExtensions); + if (gpxFileExtensions.containsKey(GpxUtilities.ACTIVITY_TYPE)) { + gpxFile.getMetadata().getExtensionsToWrite() + .put(GpxUtilities.ACTIVITY_TYPE, gpxFileExtensions.get(GpxUtilities.ACTIVITY_TYPE)); + } } reconstructPointsGroups(gpxFile, pgNames, pgIcons, pgColors, pgBackgrounds); // create groups before points if (!pointList.isEmpty()) { From ea5507d1fdb2ac925e15552f2d0b1a95a554704b Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Mon, 25 Nov 2024 15:27:01 +0100 Subject: [PATCH 15/60] Add tags support in Kotlin RouteActivityHelper --- .../net/osmand/shared/gpx/RouteActivityHelper.kt | 12 +++++++++++- .../osmand/shared/gpx/primitives/RouteActivity.kt | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/RouteActivityHelper.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/RouteActivityHelper.kt index be00343dc93..877081cb40d 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/RouteActivityHelper.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/RouteActivityHelper.kt @@ -45,6 +45,15 @@ object RouteActivityHelper { return cachedActivities } + fun findActivityByTag(tag: String): RouteActivity? { + for (activity in getActivities()) { + if (activity.tags != null && activity.tags.contains(tag)) { + return activity + } + } + return null + } + fun saveRouteActivity(trackItems: Collection, routeActivity: RouteActivity?) { runAsync { trackItems.forEach { trackItem -> @@ -121,7 +130,8 @@ object RouteActivityHelper { val activityId = activityJson["id"]!!.jsonPrimitive.content val activityLabel = activityJson["label"]!!.jsonPrimitive.content val iconName = activityJson["icon_name"]!!.jsonPrimitive.content - val activity = RouteActivity(activityId, activityLabel, iconName, activitiesGroup) + val tags = activityJson["tags"]?.jsonArray?.map { it.jsonPrimitive.content }?.toSet() + val activity = RouteActivity(activityId, activityLabel, iconName, activitiesGroup, tags) cachedActivities.add(activity) activities.add(activity) } diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/RouteActivity.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/RouteActivity.kt index ffa8981e566..4df75a8906d 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/RouteActivity.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/RouteActivity.kt @@ -4,7 +4,8 @@ data class RouteActivity( val id: String, val label: String, val iconName: String, - val group: RouteActivityGroup + val group: RouteActivityGroup, + val tags: Set? = null ) { override fun toString(): String { return id From 20a8861d426702b3188d123bc4b3055a9411c1f6 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Mon, 25 Nov 2024 15:27:33 +0100 Subject: [PATCH 16/60] Support GpxUtilities.ACTIVITY_TYPE for TravelGpx --- .../osmand/plus/wikivoyage/data/TravelObfHelper.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index a1e50048ab7..89ccb89f6f8 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -72,6 +72,7 @@ import net.osmand.shared.gpx.GpxHelper; 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; @@ -1220,8 +1221,10 @@ private void reconstructGpxTagsFromAmenityType(Amenity amenity, Map re gpxFile.getTracks().add(track); gpxFile.setRef(article.ref); gpxFile.setHasAltitude(hasAltitude); - gpxFile.getExtensionsToWrite().putAll(gpxFileExtensions); if (gpxFileExtensions.containsKey(GpxUtilities.ACTIVITY_TYPE)) { gpxFile.getMetadata().getExtensionsToWrite() .put(GpxUtilities.ACTIVITY_TYPE, gpxFileExtensions.get(GpxUtilities.ACTIVITY_TYPE)); + gpxFileExtensions.remove(GpxUtilities.ACTIVITY_TYPE); // activities live in the metadata } + gpxFile.getExtensionsToWrite().putAll(gpxFileExtensions); // finally } reconstructPointsGroups(gpxFile, pgNames, pgIcons, pgColors, pgBackgrounds); // create groups before points if (!pointList.isEmpty()) { From 537b1d46d6c0820947383c37c15155be548bfd40 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Mon, 25 Nov 2024 16:46:22 +0100 Subject: [PATCH 17/60] Fix "missed-duplicate" bug in isUniqueGpx() --- .../net/osmand/plus/views/layers/MapSelectionHelper.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java b/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java index 7f4690ba4db..4fc7b17d5ab 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java @@ -477,8 +477,9 @@ private boolean addTravelGpx(@NonNull MapSelectionResult result, @Nullable Strin private boolean isUniqueGpx(@NonNull Map selectedObjects, @NonNull TravelGpx travelGpx) { + String travelGpxFileName = travelGpx.getGpxFileName() + GPX_FILE_EXT; String tracksDir = app.getAppPath(IndexConstants.GPX_TRAVEL_DIR).getPath(); - File file = new File(tracksDir, travelGpx.getRouteId() + GPX_FILE_EXT); + File file = new File(tracksDir, travelGpxFileName); if (file.exists()) { return false; } @@ -490,6 +491,12 @@ private boolean isUniqueGpx(@NonNull Map selectedO return false; } } + if (entry.getKey() instanceof SelectedGpxPoint && entry.getValue() instanceof GPXLayer) { + SelectedGpxPoint selectedGpxPoint = (SelectedGpxPoint) entry.getKey(); + if (selectedGpxPoint.getSelectedGpxFile().getGpxFile().getPath().endsWith(travelGpxFileName)) { + return false; + } + } } return true; } From 18d10ba23b5c4d921cc0242606b77ec4631660be Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Tue, 26 Nov 2024 14:54:04 +0100 Subject: [PATCH 18/60] Do not clutter GPX with useless OBF tags --- .../plus/wikivoyage/data/TravelObfHelper.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 89ccb89f6f8..b9069b55490 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -1141,15 +1141,30 @@ private void fetchSegmentsAndPoints(List readers, TravelAr } } + // Do not clutter GPX with tags that are only used to display OBF data. private static final Set avoidAmenityGpxTags = Set.of( "date", "distance", "route_id", "route_name", - "route_radius" + "route_radius", + "avg_ele", + "min_ele", + "max_ele", + "start_ele", + "ele_graph", + "diff_ele_up", + "diff_ele_down", + "avg_speed", + "min_speed", + "max_speed", + "time_moving", + "time_moving_no_gaps", + "time_span", + "time_span_no_gaps" ); - // name, ref, type, route will be processed in a special way + // Keep important tags. Note: name, ref, type, and route tags will be processed in a special way. private static final Set keepAsIsAmenityGpxTags = Set.of( "osm_id", "relation_gpx", From b07320a5d2d699f0a5d13140423af5d2a6703331 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Tue, 26 Nov 2024 17:11:10 +0100 Subject: [PATCH 19/60] Cleanup OSM tags in GPX files saved by TravelGpx --- .../osmand/plus/wikivoyage/data/TravelObfHelper.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index b9069b55490..855d33e85d9 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -1290,6 +1290,12 @@ private synchronized GpxFile buildGpxFile(@NonNull List re if (!Algorithms.isEmpty(article.description)) { gpxFile.getMetadata().setDesc(article.description); } + final String[] cleanupByPresenceTags = { "ref", "name", "description" }; // osm_ref_present, etc + for (String tag : cleanupByPresenceTags) { + if (!gpxFileExtensions.containsKey("osm_" + tag + "_present")) { + gpxFileExtensions.remove(OSM_PREFIX + tag); + } + } } else { String description = article.getDescription(); String title = FileUtils.isValidFileName(description) ? description : article.getTitle(); @@ -1328,7 +1334,9 @@ private synchronized GpxFile buildGpxFile(@NonNull List re } gpxFile.setTracks(new ArrayList<>()); gpxFile.getTracks().add(track); - gpxFile.setRef(article.ref); + if (!(article instanceof TravelGpx)) { + gpxFile.setRef(article.ref); + } gpxFile.setHasAltitude(hasAltitude); if (gpxFileExtensions.containsKey(GpxUtilities.ACTIVITY_TYPE)) { gpxFile.getMetadata().getExtensionsToWrite() From 57f760334445f1369df826067c72aa87f42dc3c1 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Tue, 26 Nov 2024 18:56:58 +0100 Subject: [PATCH 20/60] Use route_id instead of osm_id in findAmenityByName --- .../osmand/plus/views/layers/MapSelectionHelper.java | 10 +++++----- .../src/net/osmand/plus/wikivoyage/data/TravelGpx.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java b/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java index 4fc7b17d5ab..970c9461033 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java @@ -8,7 +8,7 @@ import static net.osmand.data.MapObject.AMENITY_ID_RIGHT_SHIFT; import static net.osmand.osm.OsmRouteType.HIKING; import static net.osmand.plus.transport.TransportLinesMenu.RENDERING_CATEGORY_TRANSPORT; -import static net.osmand.plus.wikivoyage.data.TravelGpx.TRAVEL_OSM_ID_TAG; +import static net.osmand.plus.wikivoyage.data.TravelGpx.TRAVEL_MAP_TO_POI_TAG; import static net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN; import static net.osmand.router.network.NetworkRouteSelector.NetworkRouteSelectorFilter; import static net.osmand.router.network.NetworkRouteSelector.RouteKey; @@ -447,8 +447,8 @@ private Amenity getAmenity(LatLon latLon, ObfMapObject obfMapObject, Map amenities, long public static Amenity findAmenityByName(@NonNull List amenities, @Nullable List names) { if (!Algorithms.isEmpty(names)) { for (Amenity amenity : amenities) { - String travelOsmId = amenity.isRoutePoint() ? amenity.getAdditionalInfo(TRAVEL_OSM_ID_TAG) : null; + String travelRouteId = amenity.isRoutePoint() ? amenity.getAdditionalInfo(TRAVEL_MAP_TO_POI_TAG) : null; for (String name : names) { if (name.equals(amenity.getName()) && !amenity.isClosed()) { return amenity; } - if (travelOsmId != null && name.equals(travelOsmId)) { + if (travelRouteId != null && name.equals(travelRouteId)) { return amenity; } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java index cac34ab8af6..bafb290f38c 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java @@ -32,7 +32,7 @@ public class TravelGpx extends TravelArticle { public static final String ROUTE_RADIUS = "route_radius"; public static final String USER = "user"; public static final String ACTIVITY_TYPE = "route_activity_type"; - public static final String TRAVEL_OSM_ID_TAG = "osm_id"; + public static final String TRAVEL_MAP_TO_POI_TAG = "route_id"; public String user; public String activityType; From b0f6ecfca0fe4f5e487bb5a8d28885791ee2f398 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Tue, 26 Nov 2024 19:07:20 +0100 Subject: [PATCH 21/60] Use TreeMap to sort gpxFileExtensions for GPX out --- .../src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 855d33e85d9..ebb48cea30e 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -99,6 +99,7 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.Set; +import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import gnu.trove.set.TLongSet; @@ -1270,7 +1271,7 @@ public boolean isCancelled() { @Nullable private synchronized GpxFile buildGpxFile(@NonNull List readers, TravelArticle article) { List segmentList = new ArrayList<>(); - Map gpxFileExtensions = new HashMap<>(); + Map gpxFileExtensions = new TreeMap<>(); List pointList = new ArrayList<>(); List pgNames = new ArrayList<>(); List pgIcons = new ArrayList<>(); From 8d5315a4802d85156747575d67913ff397d958e9 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Wed, 27 Nov 2024 10:43:47 +0100 Subject: [PATCH 22/60] Fix import --- OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 1 - 1 file changed, 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index ebb48cea30e..06a211eefb8 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -47,7 +47,6 @@ import net.osmand.OsmAndCollator; import net.osmand.PlatformUtil; import net.osmand.ResultMatcher; -import net.osmand.osm.PoiType; import net.osmand.plus.Version; import net.osmand.plus.shared.SharedUtil; import net.osmand.binary.BinaryMapDataObject; From dcde16bad2da6bd73df392d8061c5c3d39672580 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Thu, 28 Nov 2024 20:57:31 +0100 Subject: [PATCH 23/60] Rename relation_gpx to use_osmc_colors --- OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 06a211eefb8..b740597cbfe 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -1167,7 +1167,7 @@ private void fetchSegmentsAndPoints(List readers, TravelAr // Keep important tags. Note: name, ref, type, and route tags will be processed in a special way. private static final Set keepAsIsAmenityGpxTags = Set.of( "osm_id", - "relation_gpx", + "use_osmc_colors", "shield_" // prefix ); From fe3d143cbdc90e68842bd729be1bbbcbd8941500 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Fri, 29 Nov 2024 13:14:54 +0100 Subject: [PATCH 24/60] Refactor getGPXName() to use getGpxFileName() --- .../osmand/plus/wikivoyage/data/TravelDbHelper.java | 11 +++++++++-- .../osmand/plus/wikivoyage/data/TravelObfHelper.java | 9 +++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java index 2b9a2a4519c..e8099720145 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java @@ -1,5 +1,7 @@ package net.osmand.plus.wikivoyage.data; +import static net.osmand.IndexConstants.GPX_FILE_EXT; + import android.text.TextUtils; import androidx.annotation.NonNull; @@ -731,8 +733,13 @@ public void openTrackMenu(@NonNull TravelArticle article, @NonNull MapActivity m @NonNull @Override public String getGPXName(@NonNull TravelArticle article) { - return article.getTitle().replace('/', '_').replace('\'', '_') - .replace('\"', '_') + IndexConstants.GPX_FILE_EXT; + return article.getGpxFileName() + .replace('/', '_') + .replace('\'', '_') + .replace('\"', '_') + .replace('\r', '_') + .replace('\n', '_') + + GPX_FILE_EXT; } @NonNull diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index b740597cbfe..24657b5171c 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -1068,8 +1068,13 @@ public ArrayList getArticleLangs(@NonNull TravelArticleIdentifier articl @NonNull @Override public String getGPXName(@NonNull TravelArticle article) { - return article.getTitle().replace('/', '_').replace('\'', '_') - .replace('\"', '_') + GPX_FILE_EXT; + return article.getGpxFileName() + .replace('/', '_') + .replace('\'', '_') + .replace('\"', '_') + .replace('\r', '_') + .replace('\n', '_') + + GPX_FILE_EXT; } @NonNull From 565c98d7c7d8d063998264978f9ec118a62d7cc2 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Fri, 29 Nov 2024 13:32:01 +0100 Subject: [PATCH 25/60] Fix and log possible NPE, fix bug in isUniqueGpx() --- .../controllers/AmenityMenuController.java | 7 +++++++ .../plus/search/dialogs/QuickSearchListFragment.java | 11 ++++++++++- .../osmand/plus/views/layers/MapSelectionHelper.java | 7 ++----- .../src/net/osmand/plus/views/layers/POIMapLayer.java | 1 + 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index 5a305084da1..f0c04329f42 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -8,6 +8,7 @@ import androidx.annotation.NonNull; +import net.osmand.PlatformUtil; import net.osmand.data.Amenity; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -28,12 +29,16 @@ import net.osmand.plus.wikivoyage.data.TravelArticle; import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelHelper; +import net.osmand.plus.wikivoyage.data.TravelObfHelper; import net.osmand.util.Algorithms; import net.osmand.util.OpeningHoursParser; +import org.apache.commons.logging.Log; + import java.util.List; public class AmenityMenuController extends MenuController { + private static final Log LOG = PlatformUtil.getLog(AmenityMenuController.class); private Amenity amenity; private final MapMarker marker; @@ -115,6 +120,8 @@ void openTrack(MapActivity mapActivity) { TravelGpx travelGpx = travelHelper.searchGpx(amenity.getLocation(), amenity.getRouteId(), amenity.getRef()); if (travelGpx != null) { travelHelper.openTrackMenu(travelGpx, mapActivity, travelGpx.getTitle(), amenity.getLocation(), false); + } else { + LOG.error("openTrack() searchGpx() travelGpx is null"); } } } diff --git a/OsmAnd/src/net/osmand/plus/search/dialogs/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/dialogs/QuickSearchListFragment.java index f45244446e5..5d6784a8ace 100644 --- a/OsmAnd/src/net/osmand/plus/search/dialogs/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/dialogs/QuickSearchListFragment.java @@ -16,10 +16,12 @@ import androidx.fragment.app.FragmentActivity; import net.osmand.IndexConstants; +import net.osmand.PlatformUtil; import net.osmand.data.Amenity; import net.osmand.data.PointDescription; import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelHelper; +import net.osmand.plus.wikivoyage.data.TravelObfHelper; import net.osmand.shared.gpx.GpxFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -46,11 +48,14 @@ import net.osmand.search.core.SearchResult; import net.osmand.util.Algorithms; +import org.apache.commons.logging.Log; + import java.io.File; import java.util.ArrayList; import java.util.List; public abstract class QuickSearchListFragment extends OsmAndListFragment { + private static final Log LOG = PlatformUtil.getLog(QuickSearchListFragment.class); protected OsmandApplication app; private QuickSearchDialogFragment dialogFragment; @@ -194,7 +199,11 @@ 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.getGpxFileName(null), amenity.getLocation(), true); + if (travelGpx != null) { + travelHelper.openTrackMenu(travelGpx, getMapActivity(), amenity.getGpxFileName(null), amenity.getLocation(), true); + } else { + LOG.error("showResultWithLocation() searchGpx() travelGpx is null"); + } } else { showOnMap(getMapActivity(), dialogFragment, searchResult.location.getLatitude(), searchResult.location.getLongitude(), diff --git a/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java b/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java index 970c9461033..612f1340053 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java @@ -471,6 +471,8 @@ private boolean addTravelGpx(@NonNull MapSelectionResult result, @Nullable Strin SelectedGpxPoint selectedGpxPoint = new SelectedGpxPoint(null, selectedPoint); result.selectedObjects.put(new Pair<>(travelGpx, selectedGpxPoint), mapLayers.getTravelSelectionLayer()); return true; + } else if (travelGpx == null) { + log.error("addTravelGpx() searchGpx() travelGpx is null"); } return false; } @@ -478,11 +480,6 @@ private boolean addTravelGpx(@NonNull MapSelectionResult result, @Nullable Strin private boolean isUniqueGpx(@NonNull Map selectedObjects, @NonNull TravelGpx travelGpx) { String travelGpxFileName = travelGpx.getGpxFileName() + GPX_FILE_EXT; - String tracksDir = app.getAppPath(IndexConstants.GPX_TRAVEL_DIR).getPath(); - File file = new File(tracksDir, travelGpxFileName); - if (file.exists()) { - return false; - } for (Map.Entry entry : selectedObjects.entrySet()) { if (entry.getKey() instanceof Pair && entry.getValue() instanceof GPXLayer && ((Pair) entry.getKey()).first instanceof TravelGpx) { diff --git a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java index 56a428e3296..2e9f8771536 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java @@ -614,6 +614,7 @@ public boolean showMenuAction(@Nullable Object object) { } else if (amenity.isRouteTrack()) { TravelGpx travelGpx = travelHelper.searchGpx(amenity.getLocation(), amenity.getRouteId(), amenity.getRef()); if (travelGpx == null) { + log.error("showMenuAction() searchGpx() travelGpx is null"); return true; } travelHelper.openTrackMenu(travelGpx, mapActivity, amenity.getGpxFileName(null), amenity.getLocation(), false); From 13a508bf65007716c95b5a6dba83a92c274b8453 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Fri, 29 Nov 2024 14:24:03 +0100 Subject: [PATCH 26/60] Fix possible NPE with amenity.getSubType().equals --- .../mapcontextmenu/controllers/AmenityMenuController.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index f0c04329f42..0ee897ea1be 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -76,8 +76,7 @@ public AmenityMenuController(@NonNull MapActivity mapActivity, new MapMarkerMenuController(mapActivity, marker.getPointDescription(mapActivity), marker); leftTitleButtonController = markerMenuController.getLeftTitleButtonController(); rightTitleButtonController = markerMenuController.getRightTitleButtonController(); - } else if (amenity.getSubType().equals(ROUTE_ARTICLE_POINT) || - amenity.getSubType().equals(ROUTE_TRACK_POINT)) { + } else if (amenity.isRoutePoint()) { TitleButtonController openTrackButtonController = new TitleButtonController() { @Override public void buttonPressed() { @@ -109,14 +108,14 @@ public void buttonPressed() { void openTrack(MapActivity mapActivity) { TravelHelper travelHelper = mapActivity.getMyApplication().getTravelHelper(); - if (amenity.getSubType().equals(ROUTE_ARTICLE_POINT)) { + if (ROUTE_ARTICLE_POINT.equals(amenity.getSubType())) { String lang = amenity.getTagSuffix(Amenity.LANG_YES + ":"); String name = amenity.getTagContent(Amenity.ROUTE_NAME); TravelArticle article = travelHelper.getArticleByTitle(name, lang, true, null); if (article != null) { travelHelper.openTrackMenu(article, mapActivity, name, amenity.getLocation(), false); } - } else if (amenity.getSubType().equals(ROUTE_TRACK_POINT)) { + } else if (ROUTE_TRACK_POINT.equals(amenity.getSubType())) { TravelGpx travelGpx = travelHelper.searchGpx(amenity.getLocation(), amenity.getRouteId(), amenity.getRef()); if (travelGpx != null) { travelHelper.openTrackMenu(travelGpx, mapActivity, travelGpx.getTitle(), amenity.getLocation(), false); From 9cdbf39c74782d6691cf2c1a5c5d9f5e69d7562c Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Fri, 29 Nov 2024 14:27:54 +0100 Subject: [PATCH 27/60] Rename Set --- OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java index 2e9f8771536..fb4d6a6aa61 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java @@ -159,7 +159,7 @@ protected List calculateResult(@NonNull QuadRect latLonBounds, int zoom int z = (int) Math.floor(zoom + Math.log(getMapDensity()) / Math.log(2)); List res = new ArrayList<>(); - Set deduplicateByRouteId = new HashSet<>(); + Set uniqueRouteIds = new HashSet<>(); PoiFilterUtils.combineStandardPoiFilters(calculatedFilters, app); for (PoiUIFilter filter : calculatedFilters) { List amenities = filter.searchAmenities(latLonBounds.top, latLonBounds.left, @@ -179,10 +179,10 @@ public boolean isCancelled() { if (amenity.isRouteTrack()) { String routeId = amenity.getRouteId(); if (routeId != null) { - if (deduplicateByRouteId.contains(routeId)) { + if (uniqueRouteIds.contains(routeId)) { continue; } - deduplicateByRouteId.add(routeId); + uniqueRouteIds.add(routeId); } } res.add(amenity); From 62134bf41d730c6dc26b28252cd33c6109beb64c Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Fri, 29 Nov 2024 14:34:54 +0100 Subject: [PATCH 28/60] Optimize uniqueRouteIds contains/add calls --- OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java index fb4d6a6aa61..479b63592b3 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java @@ -178,11 +178,8 @@ public boolean isCancelled() { for (Amenity amenity : amenities) { if (amenity.isRouteTrack()) { String routeId = amenity.getRouteId(); - if (routeId != null) { - if (uniqueRouteIds.contains(routeId)) { - continue; - } - uniqueRouteIds.add(routeId); + if (routeId != null && !uniqueRouteIds.add(routeId)) { + continue; // duplicate } } res.add(amenity); From a81a228f7f1b1d002333e59a6078fed16e4a6749 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Fri, 29 Nov 2024 14:37:36 +0100 Subject: [PATCH 29/60] Refactor "if / null / return / return" block --- OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java index 479b63592b3..b65a10c2690 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java @@ -610,11 +610,11 @@ public boolean showMenuAction(@Nullable Object object) { return true; } else if (amenity.isRouteTrack()) { TravelGpx travelGpx = travelHelper.searchGpx(amenity.getLocation(), amenity.getRouteId(), amenity.getRef()); - if (travelGpx == null) { + if (travelGpx != null) { + travelHelper.openTrackMenu(travelGpx, mapActivity, amenity.getGpxFileName(null), amenity.getLocation(), false); + } else { log.error("showMenuAction() searchGpx() travelGpx is null"); - return true; } - travelHelper.openTrackMenu(travelGpx, mapActivity, amenity.getGpxFileName(null), amenity.getLocation(), false); return true; } } From fc512ce5edfcd109c1205413ce72079f8c65cf3e Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Fri, 29 Nov 2024 14:45:47 +0100 Subject: [PATCH 30/60] Refactor using Algorithms.parseDoubleSilently --- .../plus/wikivoyage/data/TravelObfHelper.java | 38 ++++++------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 24657b5171c..6885e86f5b3 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -312,26 +312,16 @@ private TravelGpx getTravelGpx(File file, Amenity amenity) { travelGpx.user = Algorithms.emptyIfNull(amenity.getTagContent(USER)); travelGpx.activityType = Algorithms.emptyIfNull(amenity.getTagContent(ACTIVITY_TYPE)); travelGpx.ref = Algorithms.emptyIfNull(amenity.getRef()); - try { - travelGpx.totalDistance = Float.parseFloat(Objects.requireNonNullElse( - amenity.getTagContent(DISTANCE), "0")); - travelGpx.diffElevationUp = Double.parseDouble(Objects.requireNonNullElse( - amenity.getTagContent(DIFF_ELEVATION_UP), "0")); - travelGpx.diffElevationDown = Double.parseDouble(Objects.requireNonNullElse( - amenity.getTagContent(DIFF_ELEVATION_DOWN), "0")); - travelGpx.minElevation = Double.parseDouble(Objects.requireNonNullElse( - amenity.getTagContent(MIN_ELEVATION), "0")); - travelGpx.avgElevation = Double.parseDouble(Objects.requireNonNullElse( - amenity.getTagContent(AVERAGE_ELEVATION), "0")); - travelGpx.maxElevation = Double.parseDouble(Objects.requireNonNullElse( - amenity.getTagContent(MAX_ELEVATION), "0")); - String radius = amenity.getTagContent(ROUTE_RADIUS); - if (radius != null) { - travelGpx.routeRadius = MapUtils.convertCharToDist(radius.charAt(0), TRAVEL_GPX_CONVERT_FIRST_LETTER, - TRAVEL_GPX_CONVERT_FIRST_DIST, TRAVEL_GPX_CONVERT_MULT_1, TRAVEL_GPX_CONVERT_MULT_2); - } - } catch (NumberFormatException e) { - LOG.debug(e.getMessage(), e); + travelGpx.totalDistance = Algorithms.parseFloatSilently(amenity.getTagContent(DISTANCE), 0); + travelGpx.diffElevationUp = Algorithms.parseDoubleSilently(amenity.getTagContent(DIFF_ELEVATION_UP), 0); + travelGpx.diffElevationDown = Algorithms.parseDoubleSilently(amenity.getTagContent(DIFF_ELEVATION_DOWN), 0); + travelGpx.minElevation = Algorithms.parseDoubleSilently(amenity.getTagContent(MIN_ELEVATION), 0); + travelGpx.avgElevation = Algorithms.parseDoubleSilently(amenity.getTagContent(AVERAGE_ELEVATION), 0); + travelGpx.maxElevation = Algorithms.parseDoubleSilently(amenity.getTagContent(MAX_ELEVATION), 0); + String radius = amenity.getTagContent(ROUTE_RADIUS); + if (radius != null) { + travelGpx.routeRadius = MapUtils.convertCharToDist(radius.charAt(0), TRAVEL_GPX_CONVERT_FIRST_LETTER, + TRAVEL_GPX_CONVERT_FIRST_DIST, TRAVEL_GPX_CONVERT_MULT_1, TRAVEL_GPX_CONVERT_MULT_2); } return travelGpx; } @@ -1326,13 +1316,7 @@ private synchronized GpxFile buildGpxFile(@NonNull List re if (!Algorithms.isEmpty(ele_graph)) { hasAltitude = true; List heightRes = KMapAlgorithms.INSTANCE.decodeIntHeightArrayGraph(ele_graph, 3); - double startEle = 0; - try { - startEle = Double.parseDouble(Objects.requireNonNullElse( - segment.getTagValue(START_ELEVATION), "0")); - } catch (NumberFormatException e) { - LOG.debug(e.getMessage(), e); - } + double startEle = Algorithms.parseDoubleSilently(segment.getTagValue(START_ELEVATION), 0); KMapAlgorithms.INSTANCE.augmentTrkSegmentWithAltitudes(trkSegment, heightRes, startEle); } track.getSegments().add(trkSegment); From 5c48f8d332d05a52fbacc00b898ace2983d96cd9 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Fri, 29 Nov 2024 14:50:23 +0100 Subject: [PATCH 31/60] Style avoidAmenityGpxTags keepAsIsAmenityGpxTags --- .../plus/wikivoyage/data/TravelObfHelper.java | 38 ++++--------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 6885e86f5b3..57fd80fc6ec 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -123,6 +123,14 @@ public class TravelObfHelper implements TravelHelper { private final List> foundAmenities = new ArrayList<>(); public volatile int requestNumber = 0; + // Do not clutter GPX with tags that are always generated. + private static final Set avoidAmenityGpxTags = Set.of( + "date", "distance", "route_id", "route_name", "route_radius", + "avg_ele", "min_ele", "max_ele", "start_ele", "ele_graph", "diff_ele_up", "diff_ele_down", + "avg_speed", "min_speed", "max_speed", "time_moving", "time_moving_no_gaps", "time_span", "time_span_no_gaps" + ); + // Keep important tags by prefix. Note: name, ref, type, and route tags are processed in a special way. + private static final Set keepAsIsAmenityGpxTags = Set.of("osm_id", "use_osmc_colors", "shield_"); public TravelObfHelper(OsmandApplication app) { this.app = app; @@ -1136,36 +1144,6 @@ private void fetchSegmentsAndPoints(List readers, TravelAr } } - // Do not clutter GPX with tags that are only used to display OBF data. - private static final Set avoidAmenityGpxTags = Set.of( - "date", - "distance", - "route_id", - "route_name", - "route_radius", - "avg_ele", - "min_ele", - "max_ele", - "start_ele", - "ele_graph", - "diff_ele_up", - "diff_ele_down", - "avg_speed", - "min_speed", - "max_speed", - "time_moving", - "time_moving_no_gaps", - "time_span", - "time_span_no_gaps" - ); - - // Keep important tags. Note: name, ref, type, and route tags will be processed in a special way. - private static final Set keepAsIsAmenityGpxTags = Set.of( - "osm_id", - "use_osmc_colors", - "shield_" // prefix - ); - @NonNull private ResultMatcher matchPointsAndTags(TravelArticle article, List pointList, Map gpxFileExtensions, List pgNames, List pgIcons, List pgColors, List pgBackgrounds) { return new ResultMatcher() { From a2cb935b2860ab267a65a4120fc48d86676eff06 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Mon, 2 Dec 2024 18:51:11 +0100 Subject: [PATCH 32/60] Add log for null result in searchGpx() --- .../src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 57fd80fc6ec..df3f834f2a6 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -260,6 +260,9 @@ public synchronized TravelGpx searchGpx(@NonNull LatLon location, @Nullable Stri } searchRadius *= 2; } while (travelGpx == null && searchRadius < MAX_SEARCH_RADIUS); + if (travelGpx == null) { + LOG.error(String.format("searchGpx(%s, %s, %s) failed", location, filter, ref)); + } return travelGpx; } From ffca9101e13f172030fe3c806ba220fca5ea477e Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Mon, 2 Dec 2024 19:11:23 +0100 Subject: [PATCH 33/60] Refactor getGpxFileName (sanitize file name) --- .../osmand/plus/wikivoyage/data/TravelArticle.java | 14 +++++++++++++- .../plus/wikivoyage/data/TravelDbHelper.java | 8 +------- .../plus/wikivoyage/data/TravelObfHelper.java | 8 +------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java index da340c0ebf9..66e06b3f47b 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java @@ -127,8 +127,20 @@ public String getRouteId() { return routeId; } + @NonNull public String getGpxFileName() { - return !Algorithms.isEmpty(title) ? title : routeId; + String gpxFileName = !Algorithms.isEmpty(title) ? title : routeId; + if (gpxFileName != null) { + return gpxFileName + .replace('/', '_') + .replace('\'', '_') + .replace('\"', '_') + .replace('\r', '_') + .replace('\n', '_'); + } else { + LOG.error("Empty travel article in " + this.file); + return "Travel Article File"; // @NonNull + } } public String getRouteSource() { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java index e8099720145..efd1655a980 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java @@ -733,13 +733,7 @@ public void openTrackMenu(@NonNull TravelArticle article, @NonNull MapActivity m @NonNull @Override public String getGPXName(@NonNull TravelArticle article) { - return article.getGpxFileName() - .replace('/', '_') - .replace('\'', '_') - .replace('\"', '_') - .replace('\r', '_') - .replace('\n', '_') - + GPX_FILE_EXT; + return article.getGpxFileName() + GPX_FILE_EXT; } @NonNull diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index df3f834f2a6..1af40d972e6 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -1069,13 +1069,7 @@ public ArrayList getArticleLangs(@NonNull TravelArticleIdentifier articl @NonNull @Override public String getGPXName(@NonNull TravelArticle article) { - return article.getGpxFileName() - .replace('/', '_') - .replace('\'', '_') - .replace('\"', '_') - .replace('\r', '_') - .replace('\n', '_') - + GPX_FILE_EXT; + return article.getGpxFileName() + GPX_FILE_EXT; } @NonNull From 86dcec0b801178abfc7ee46177db5b704a9cea95 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Tue, 3 Dec 2024 16:36:22 +0100 Subject: [PATCH 34/60] tmp --- OsmAnd/src/net/osmand/core/android/MapRendererContext.java | 2 +- OsmAnd/src/net/osmand/plus/render/RendererRegistry.java | 2 +- gradle.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/core/android/MapRendererContext.java b/OsmAnd/src/net/osmand/core/android/MapRendererContext.java index 2132c8cc953..1b1a7aab62e 100644 --- a/OsmAnd/src/net/osmand/core/android/MapRendererContext.java +++ b/OsmAnd/src/net/osmand/core/android/MapRendererContext.java @@ -59,7 +59,7 @@ public class MapRendererContext { public static final int OBF_CONTOUR_LINES_RASTER_LAYER = 6000; public static final int OBF_SYMBOL_SECTION = 1; public static final int WEATHER_CONTOURS_SYMBOL_SECTION = 2; - public static boolean IGNORE_CORE_PRELOADED_STYLES = false; // enable to debug default.render.xml changes + public static boolean IGNORE_CORE_PRELOADED_STYLES = true; // enable to debug default.render.xml changes private final OsmandApplication app; diff --git a/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java b/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java index 1cad3a140b8..834505797b9 100644 --- a/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java +++ b/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java @@ -57,7 +57,7 @@ public class RendererRegistry { public static final String OSMASSISTANT_RENDER = "OSM Assistant"; public static final String PUBLICTRANSPORTROUTES_RENDER = "Public transport routes"; - public static boolean IGNORE_CACHED_STYLES = false; // enable to overwrite RENDERERS_DIR styles (debug) + public static boolean IGNORE_CACHED_STYLES = true; // enable to overwrite RENDERERS_DIR styles (debug) private final OsmandApplication app; diff --git a/gradle.properties b/gradle.properties index 6f3bf3d5d5d..1a0754c21a9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,4 +26,4 @@ android.enableR8.fullMode=false android.defaults.buildfeatures.buildconfig=true android.nonTransitiveRClass=false android.nonFinalResIds=false -#org.gradle.configuration-cache=true +org.gradle.configuration-cache=true From aa9f46a5eefc1e443b6dd9bbf86177838830eb71 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Tue, 3 Dec 2024 16:46:33 +0100 Subject: [PATCH 35/60] Revert "tmp" This reverts commit 86dcec0b801178abfc7ee46177db5b704a9cea95. --- OsmAnd/src/net/osmand/core/android/MapRendererContext.java | 2 +- OsmAnd/src/net/osmand/plus/render/RendererRegistry.java | 2 +- gradle.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/core/android/MapRendererContext.java b/OsmAnd/src/net/osmand/core/android/MapRendererContext.java index 1b1a7aab62e..2132c8cc953 100644 --- a/OsmAnd/src/net/osmand/core/android/MapRendererContext.java +++ b/OsmAnd/src/net/osmand/core/android/MapRendererContext.java @@ -59,7 +59,7 @@ public class MapRendererContext { public static final int OBF_CONTOUR_LINES_RASTER_LAYER = 6000; public static final int OBF_SYMBOL_SECTION = 1; public static final int WEATHER_CONTOURS_SYMBOL_SECTION = 2; - public static boolean IGNORE_CORE_PRELOADED_STYLES = true; // enable to debug default.render.xml changes + public static boolean IGNORE_CORE_PRELOADED_STYLES = false; // enable to debug default.render.xml changes private final OsmandApplication app; diff --git a/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java b/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java index 834505797b9..1cad3a140b8 100644 --- a/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java +++ b/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java @@ -57,7 +57,7 @@ public class RendererRegistry { public static final String OSMASSISTANT_RENDER = "OSM Assistant"; public static final String PUBLICTRANSPORTROUTES_RENDER = "Public transport routes"; - public static boolean IGNORE_CACHED_STYLES = true; // enable to overwrite RENDERERS_DIR styles (debug) + public static boolean IGNORE_CACHED_STYLES = false; // enable to overwrite RENDERERS_DIR styles (debug) private final OsmandApplication app; diff --git a/gradle.properties b/gradle.properties index 1a0754c21a9..6f3bf3d5d5d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,4 +26,4 @@ android.enableR8.fullMode=false android.defaults.buildfeatures.buildconfig=true android.nonTransitiveRClass=false android.nonFinalResIds=false -org.gradle.configuration-cache=true +#org.gradle.configuration-cache=true From 9a20341b7b68a4ad86d0f07a1f84506a24065e73 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Tue, 3 Dec 2024 23:13:12 +0100 Subject: [PATCH 36/60] Refactor and split use_osmc_colors into 2 new tags --- .../src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 1af40d972e6..a0eab32129a 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -130,7 +130,9 @@ public class TravelObfHelper implements TravelHelper { "avg_speed", "min_speed", "max_speed", "time_moving", "time_moving_no_gaps", "time_span", "time_span_no_gaps" ); // Keep important tags by prefix. Note: name, ref, type, and route tags are processed in a special way. - private static final Set keepAsIsAmenityGpxTags = Set.of("osm_id", "use_osmc_colors", "shield_"); + private static final Set keepAsIsAmenityGpxTags = Set.of( + "osm_id", "flexible_line_width", "translucent_line_colors", "shield_" + ); public TravelObfHelper(OsmandApplication app) { this.app = app; From da648fb9441caa5a34f1901488fa6c3dc3bf8c32 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Wed, 4 Dec 2024 12:02:49 +0100 Subject: [PATCH 37/60] Remove osm_id tag --- .../src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index a0eab32129a..f65fe98d8e2 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -125,13 +125,13 @@ public class TravelObfHelper implements TravelHelper { // Do not clutter GPX with tags that are always generated. private static final Set avoidAmenityGpxTags = Set.of( - "date", "distance", "route_id", "route_name", "route_radius", + "date", "distance", "route_name", "route_radius", "avg_ele", "min_ele", "max_ele", "start_ele", "ele_graph", "diff_ele_up", "diff_ele_down", "avg_speed", "min_speed", "max_speed", "time_moving", "time_moving_no_gaps", "time_span", "time_span_no_gaps" ); // Keep important tags by prefix. Note: name, ref, type, and route tags are processed in a special way. private static final Set keepAsIsAmenityGpxTags = Set.of( - "osm_id", "flexible_line_width", "translucent_line_colors", "shield_" + "route_id", "flexible_line_width", "translucent_line_colors", "shield_" ); public TravelObfHelper(OsmandApplication app) { From 21c37269d0fc9bc3e8db6464ff6dfb33388dd062 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Wed, 4 Dec 2024 14:41:11 +0100 Subject: [PATCH 38/60] Refactor/bugfix findAmenityByName() using stream() --- .../plus/views/layers/MapSelectionHelper.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java b/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java index 612f1340053..a8c94dcc5e6 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java @@ -719,17 +719,22 @@ public static Amenity findAmenityByOsmId(@NonNull List amenities, long @Nullable public static Amenity findAmenityByName(@NonNull List amenities, @Nullable List names) { if (!Algorithms.isEmpty(names)) { - for (Amenity amenity : amenities) { - String travelRouteId = amenity.isRoutePoint() ? amenity.getAdditionalInfo(TRAVEL_MAP_TO_POI_TAG) : null; - for (String name : names) { - if (name.equals(amenity.getName()) && !amenity.isClosed()) { - return amenity; - } - if (travelRouteId != null && name.equals(travelRouteId)) { - return amenity; - } - } - } + return amenities.stream() + .filter(amenity -> !amenity.isClosed()) + .filter(amenity -> names.contains(amenity.getName())) + .findAny() + .orElseGet(() -> + amenities.stream() + .filter(amenity -> !amenity.isClosed()) + .filter(amenity -> amenity.isRoutePoint()) + .filter(amenity -> amenity.getName().isEmpty()) + .filter(amenity -> { + String travelRouteId = amenity.getAdditionalInfo(TRAVEL_MAP_TO_POI_TAG); + return travelRouteId != null && names.contains(travelRouteId); + }) + .findAny() + .orElse(null) + ); } return null; } From 33dfd0f039e1de36cdd90cd225853ea3e7723cdf Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Wed, 4 Dec 2024 19:46:56 +0100 Subject: [PATCH 39/60] Replace osm_*_present tags with hasOsmRouteId() --- .../main/java/net/osmand/data/Amenity.java | 6 +++ .../plus/wikivoyage/data/TravelArticle.java | 5 +++ .../plus/wikivoyage/data/TravelObfHelper.java | 40 +++++++++---------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java index 438ba0d2034..22ed3196b22 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java @@ -53,6 +53,7 @@ public class Amenity extends MapObject { public static final String IS_AGGR_PART = "is_aggr_part"; public static final String CONTENT_JSON = "content_json"; public static final String ROUTE_ID = "route_id"; + public static final String ROUTE_ID_OSM_PREFIX = "OSM"; public static final String ROUTE_SOURCE = "route_source"; public static final String ROUTE_NAME = "route_name"; public static final String COLOR = "color"; @@ -452,6 +453,11 @@ public String getRouteId() { return getAdditionalInfo(ROUTE_ID); } + public boolean hasOsmRouteId() { + String routeId = getRouteId(); + return routeId != null && routeId.startsWith(ROUTE_ID_OSM_PREFIX); + } + public String getGpxFileName(String lang) { final String gpxFileName = lang != null ? getName(lang) : getEnName(true); if (!Algorithms.isEmpty(gpxFileName)) { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java index 66e06b3f47b..218a591c8a3 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java @@ -127,6 +127,11 @@ public String getRouteId() { return routeId; } + public boolean hasOsmRouteId() { + String routeId = getRouteId(); + return routeId != null && routeId.startsWith(Amenity.ROUTE_ID_OSM_PREFIX); + } + @NonNull public String getGpxFileName() { String gpxFileName = !Algorithms.isEmpty(title) ? title : routeId; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index f65fe98d8e2..7d3dcc05bfd 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -123,16 +123,16 @@ public class TravelObfHelper implements TravelHelper { private final List> foundAmenities = new ArrayList<>(); public volatile int requestNumber = 0; + // Keep important tags by prefix. Note: name, ref, type, and route tags are processed in a special way. + private static final Set saveAsIsAmenityGpxTags = Set.of( + "route_id", "flexible_line_width", "translucent_line_colors", "shield_" + ); // Do not clutter GPX with tags that are always generated. - private static final Set avoidAmenityGpxTags = Set.of( + private static final Set doNotSaveAmenityGpxTags = Set.of( "date", "distance", "route_name", "route_radius", "avg_ele", "min_ele", "max_ele", "start_ele", "ele_graph", "diff_ele_up", "diff_ele_down", "avg_speed", "min_speed", "max_speed", "time_moving", "time_moving_no_gaps", "time_span", "time_span_no_gaps" ); - // Keep important tags by prefix. Note: name, ref, type, and route tags are processed in a special way. - private static final Set keepAsIsAmenityGpxTags = Set.of( - "route_id", "flexible_line_width", "translucent_line_colors", "shield_" - ); public TravelObfHelper(OsmandApplication app) { this.app = app; @@ -1169,15 +1169,19 @@ public boolean publish(Amenity amenity) { if (tag.startsWith(OBF_GPX_EXTENSION_TAG_PREFIX)) { String gpxTag = tag.replaceFirst(OBF_GPX_EXTENSION_TAG_PREFIX, ""); gpxFileExtensions.put(gpxTag, value); - } else if (!avoidAmenityGpxTags.contains(tag)) { - String gpxTag = OSM_PREFIX + tag; - for (String prefix : keepAsIsAmenityGpxTags) { + } else if (!doNotSaveAmenityGpxTags.contains(tag)) { + boolean saveAsIs = false; + for (String prefix : saveAsIsAmenityGpxTags) { if (tag.startsWith(prefix)) { - gpxTag = tag; + saveAsIs = true; break; } } - gpxFileExtensions.put(gpxTag, value); + if (saveAsIs) { + gpxFileExtensions.put(tag, value); + } else if (amenity.hasOsmRouteId()) { + gpxFileExtensions.put(OSM_PREFIX + tag, value); + } } } } @@ -1205,8 +1209,10 @@ private void reconstructGpxTagsFromAmenityType(Amenity amenity, Map re if (article instanceof TravelGpx) { gpxFile = new GpxFile(Version.getFullVersion(app)); gpxFile.getMetadata().setName(Objects.requireNonNullElse(article.title, article.routeId)); // path is name - if (!Algorithms.isEmpty(article.title)) { + if (!Algorithms.isEmpty(article.title) && article.hasOsmRouteId()) { gpxFileExtensions.putIfAbsent(OSM_PREFIX + "name", article.title); } if (!Algorithms.isEmpty(article.description)) { gpxFile.getMetadata().setDesc(article.description); } - final String[] cleanupByPresenceTags = { "ref", "name", "description" }; // osm_ref_present, etc - for (String tag : cleanupByPresenceTags) { - if (!gpxFileExtensions.containsKey("osm_" + tag + "_present")) { - gpxFileExtensions.remove(OSM_PREFIX + tag); - } - } } else { String description = article.getDescription(); String title = FileUtils.isValidFileName(description) ? description : article.getTitle(); @@ -1307,7 +1307,7 @@ private synchronized GpxFile buildGpxFile(@NonNull List re if (gpxFileExtensions.containsKey(GpxUtilities.ACTIVITY_TYPE)) { gpxFile.getMetadata().getExtensionsToWrite() .put(GpxUtilities.ACTIVITY_TYPE, gpxFileExtensions.get(GpxUtilities.ACTIVITY_TYPE)); - gpxFileExtensions.remove(GpxUtilities.ACTIVITY_TYPE); // activities live in the metadata + gpxFileExtensions.remove(GpxUtilities.ACTIVITY_TYPE); // move activity to metadata } gpxFile.getExtensionsToWrite().putAll(gpxFileExtensions); // finally } From 93636ce13b5416bfe03617b96aea238c1ae467f7 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Thu, 5 Dec 2024 17:59:40 +0100 Subject: [PATCH 40/60] Remove unused route_name in TravelGpx --- OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 7d3dcc05bfd..2d3bb036021 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -129,7 +129,7 @@ public class TravelObfHelper implements TravelHelper { ); // Do not clutter GPX with tags that are always generated. private static final Set doNotSaveAmenityGpxTags = Set.of( - "date", "distance", "route_name", "route_radius", + "date", "distance", "route_radius", "avg_ele", "min_ele", "max_ele", "start_ele", "ele_graph", "diff_ele_up", "diff_ele_down", "avg_speed", "min_speed", "max_speed", "time_moving", "time_moving_no_gaps", "time_span", "time_span_no_gaps" ); From edb8e7392853a3c7a4aa0e13519c3d0ec6c4e3b9 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Fri, 6 Dec 2024 20:41:18 +0100 Subject: [PATCH 41/60] Add forgotten override fun write(str: String?) --- .../kotlin/net/osmand/shared/io/SinkStringWriter.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/OsmAnd-shared/src/jvmMain/kotlin/net/osmand/shared/io/SinkStringWriter.kt b/OsmAnd-shared/src/jvmMain/kotlin/net/osmand/shared/io/SinkStringWriter.kt index 936d48743b2..5eefc167256 100644 --- a/OsmAnd-shared/src/jvmMain/kotlin/net/osmand/shared/io/SinkStringWriter.kt +++ b/OsmAnd-shared/src/jvmMain/kotlin/net/osmand/shared/io/SinkStringWriter.kt @@ -15,6 +15,13 @@ class SinkStringWriter(sink: Sink) : StringWriter() { bufferedSink.writeUtf8CodePoint(c) } + @Throws(IOException::class) + override fun write(str: String?) { + if (str != null) { + bufferedSink.writeUtf8(str) + } + } + @Throws(IOException::class) override fun write(cbuf: CharArray, off: Int, len: Int) { bufferedSink.writeUtf8(String(cbuf, off, len)) From 76163f661d901edd4990b85f92cfafe94c058a3d Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Mon, 9 Dec 2024 15:04:58 +0100 Subject: [PATCH 42/60] Use insideTagDepth to differentiate osmand:route --- .../kotlin/net/osmand/shared/gpx/GpxUtilities.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt index c9c43baecf7..51659aedb65 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt @@ -999,6 +999,7 @@ object GpxUtilities { extensionsReader: GpxExtensionsReader?, addGeneralTrack: Boolean ): GpxFile { + val insideTagDepth = mutableMapOf("trk" to 0) oneOffLogParseTimeErrors = true val gpxFile = GpxFile(null) gpxFile.metadata.time = 0 @@ -1032,6 +1033,7 @@ object GpxUtilities { if (tok == XmlPullParser.START_TAG) { val parse = parserState.lastOrNull() val tag = parser.getName() ?: "" + insideTagDepth[tag]?.let { insideTagDepth[tag] = it + 1} if (extensionReadMode && parse != null && !routePointExtension) { val tagName = tag.lowercase() when { @@ -1062,8 +1064,8 @@ object GpxUtilities { } } - tagName == "route" -> routeExtension = true - tagName == "types" -> typesExtension = true + tagName == "route" && insideTagDepth["trk"]!! > 0 -> routeExtension = true + tagName == "types" && insideTagDepth["trk"]!! > 0 -> typesExtension = true tagName == "points_groups" -> pointsGroupsExtension = true tagName == "network_route" -> networkRoute = true else -> { @@ -1314,7 +1316,8 @@ object GpxUtilities { } } else if (tok == XmlPullParser.END_TAG) { val parse = parserState.lastOrNull() - val tag = parser.getName() + val tag = parser.getName() ?: "" + insideTagDepth[tag]?.let { insideTagDepth[tag] = it - 1} if (tag.equals("routepointextension", ignoreCase = true)) { routePointExtension = false From b952b8d583967bb36505855ae0fbcf363652438b Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Mon, 9 Dec 2024 16:08:41 +0100 Subject: [PATCH 43/60] Allow nameless TravelGpx in TravelSelectionLayer --- .../osmand/plus/views/layers/TravelSelectionLayer.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/layers/TravelSelectionLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/TravelSelectionLayer.java index bac5fe3b222..899aef2bc5a 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/TravelSelectionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/TravelSelectionLayer.java @@ -56,8 +56,13 @@ public PointDescription getObjectName(Object o) { Pair pair = (Pair) o; if (pair.first instanceof TravelGpx && pair.second instanceof SelectedGpxPoint) { TravelGpx travelGpx = (TravelGpx) ((Pair) o).first; - String name = Algorithms.isEmpty(travelGpx.getDescription()) ? travelGpx.getTitle() : travelGpx.getDescription(); - return new PointDescription(PointDescription.POINT_TYPE_GPX, name); + if (!Algorithms.isEmpty(travelGpx.getTitle())) { + return new PointDescription(PointDescription.POINT_TYPE_GPX, travelGpx.getTitle()); + } else if (!Algorithms.isEmpty(travelGpx.getDescription())) { + return new PointDescription(PointDescription.POINT_TYPE_GPX, travelGpx.getDescription()); + } else { + return new PointDescription(PointDescription.POINT_TYPE_GPX, travelGpx.getRouteId()); // nullable + } } } return null; From 4f1684c35c9364fff0d782c4d2e60b80cfa342e1 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Mon, 9 Dec 2024 16:50:42 +0100 Subject: [PATCH 44/60] Refactor tags, remove gpx_ and osm_tag_ prefixes --- .../shared/gpx/primitives/GpxExtensions.kt | 4 --- .../plus/wikivoyage/data/TravelObfHelper.java | 32 +++---------------- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/GpxExtensions.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/GpxExtensions.kt index dde416446f2..aa771f6ae15 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/GpxExtensions.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/GpxExtensions.kt @@ -87,8 +87,4 @@ open class GpxExtensions { fun removeColor() { getExtensionsToWrite().remove(GpxUtilities.COLOR_NAME_EXTENSION) } - - companion object { - const val OBF_GPX_EXTENSION_TAG_PREFIX = "gpx_" // enlisted in poi_types.xml under name="route_track" - } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 2d3bb036021..2eafb01ebde 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -20,7 +20,6 @@ import static net.osmand.plus.wikivoyage.data.TravelGpx.ROUTE_RADIUS; 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.OSM_PREFIX; import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_BACKGROUNDS; import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_COLORS; import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_DELIMITER; @@ -31,7 +30,6 @@ import static net.osmand.shared.gpx.GpxUtilities.TRAVEL_GPX_CONVERT_FIRST_LETTER; import static net.osmand.shared.gpx.GpxUtilities.TRAVEL_GPX_CONVERT_MULT_1; import static net.osmand.shared.gpx.GpxUtilities.TRAVEL_GPX_CONVERT_MULT_2; -import static net.osmand.shared.gpx.primitives.GpxExtensions.OBF_GPX_EXTENSION_TAG_PREFIX; import static net.osmand.util.Algorithms.capitalizeFirstLetter; import android.os.AsyncTask; @@ -123,10 +121,6 @@ public class TravelObfHelper implements TravelHelper { private final List> foundAmenities = new ArrayList<>(); public volatile int requestNumber = 0; - // Keep important tags by prefix. Note: name, ref, type, and route tags are processed in a special way. - private static final Set saveAsIsAmenityGpxTags = Set.of( - "route_id", "flexible_line_width", "translucent_line_colors", "shield_" - ); // Do not clutter GPX with tags that are always generated. private static final Set doNotSaveAmenityGpxTags = Set.of( "date", "distance", "route_radius", @@ -1165,24 +1159,8 @@ public boolean publish(Amenity amenity) { } else if (OBF_POINTS_GROUPS_BACKGROUNDS.equals(tag)) { pgBackgrounds.addAll(values); } - } else { - if (tag.startsWith(OBF_GPX_EXTENSION_TAG_PREFIX)) { - String gpxTag = tag.replaceFirst(OBF_GPX_EXTENSION_TAG_PREFIX, ""); - gpxFileExtensions.put(gpxTag, value); - } else if (!doNotSaveAmenityGpxTags.contains(tag)) { - boolean saveAsIs = false; - for (String prefix : saveAsIsAmenityGpxTags) { - if (tag.startsWith(prefix)) { - saveAsIs = true; - break; - } - } - if (saveAsIs) { - gpxFileExtensions.put(tag, value); - } else if (amenity.hasOsmRouteId()) { - gpxFileExtensions.put(OSM_PREFIX + tag, value); - } - } + } else if (!doNotSaveAmenityGpxTags.contains(tag)) { + gpxFileExtensions.put(tag, value); } } } else if (ROUTE_TRACK_POINT.equals(amenity.getSubType())) { @@ -1210,8 +1188,8 @@ private void reconstructGpxTagsFromAmenityType(Amenity amenity, Map re gpxFile = new GpxFile(Version.getFullVersion(app)); gpxFile.getMetadata().setName(Objects.requireNonNullElse(article.title, article.routeId)); // path is name if (!Algorithms.isEmpty(article.title) && article.hasOsmRouteId()) { - gpxFileExtensions.putIfAbsent(OSM_PREFIX + "name", article.title); + gpxFileExtensions.putIfAbsent("name", article.title); } if (!Algorithms.isEmpty(article.description)) { gpxFile.getMetadata().setDesc(article.description); From 58c48a997efb6410382002690e420f0a367d02f2 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Mon, 9 Dec 2024 17:02:33 +0100 Subject: [PATCH 45/60] Remove useless createTitle from TravelObfHelper --- .../net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 2eafb01ebde..2658ffecd64 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -311,7 +311,7 @@ private TravelGpx getTravelGpx(File file, Amenity amenity) { TravelGpx travelGpx = new TravelGpx(); travelGpx.file = file; String title = amenity.getName("en"); - travelGpx.title = createTitle(Algorithms.isEmpty(title) ? amenity.getName() : title); + travelGpx.title = Algorithms.isEmpty(title) ? amenity.getName() : title; travelGpx.lat = amenity.getLocation().getLatitude(); travelGpx.lon = amenity.getLocation().getLongitude(); travelGpx.description = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.DESCRIPTION)); @@ -1210,7 +1210,7 @@ public boolean publish(BinaryMapDataObject object) { if (object.getPointsLength() > 1) { if (object.getTagValue(REF).equals(article.ref) && (object.getTagValue(ROUTE_ID).equals(article.routeId) - || createTitle(object.getName()).equals(article.getTitle()))) { + || object.getName().equals(article.getTitle()))) { segmentList.add(object); } } @@ -1315,11 +1315,6 @@ private void reconstructPointsGroups(GpxFile gpxFile, List pgNames, List } } - @NonNull - public String createTitle(@NonNull String name) { - return capitalizeFirstLetter(GpxHelper.INSTANCE.getGpxTitle(name)); - } - private class GpxFileReader extends AsyncTask { private final TravelArticle article; From 3802d9a5dd1b957cf8778eae552a37462fa64aa4 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Mon, 9 Dec 2024 18:15:51 +0100 Subject: [PATCH 46/60] Revert "Remove unused route_name in TravelGpx" This reverts commit 93636ce13b5416bfe03617b96aea238c1ae467f7. --- OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 2658ffecd64..b7f15b983de 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -123,7 +123,7 @@ public class TravelObfHelper implements TravelHelper { // Do not clutter GPX with tags that are always generated. private static final Set doNotSaveAmenityGpxTags = Set.of( - "date", "distance", "route_radius", + "date", "distance", "route_name", "route_radius", "avg_ele", "min_ele", "max_ele", "start_ele", "ele_graph", "diff_ele_up", "diff_ele_down", "avg_speed", "min_speed", "max_speed", "time_moving", "time_moving_no_gaps", "time_span", "time_span_no_gaps" ); From cbe2c603e4d9b77f4f95dda355fdb5c99c49ed63 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Mon, 9 Dec 2024 18:27:41 +0100 Subject: [PATCH 47/60] Fix typo in Amenity printNames --- OsmAnd-java/src/main/java/net/osmand/data/Amenity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java index 22ed3196b22..d48a5ebd848 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java @@ -315,7 +315,7 @@ public StringBuilder printNamesAndAdditional() { private void printNames(String prefix, Map stringMap, StringBuilder s) { for (Entry e : stringMap.entrySet()) { if (e.getValue().startsWith(" gz ")) { - s.append(prefix).append(e.getKey()).append("='gzip ...'"); + s.append(prefix).append(e.getKey()).append("='gzip ...' "); } else { s.append(prefix).append(e.getKey()).append("='").append(e.getValue()).append("' "); } From 7368b2b4cc90117cbd15b2c1ab916cb9023945cb Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Mon, 9 Dec 2024 22:44:49 +0100 Subject: [PATCH 48/60] Restore route_type instead of type and route tags --- .../src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index b7f15b983de..7c9af7d092f 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -30,7 +30,6 @@ import static net.osmand.shared.gpx.GpxUtilities.TRAVEL_GPX_CONVERT_FIRST_LETTER; import static net.osmand.shared.gpx.GpxUtilities.TRAVEL_GPX_CONVERT_MULT_1; import static net.osmand.shared.gpx.GpxUtilities.TRAVEL_GPX_CONVERT_MULT_2; -import static net.osmand.util.Algorithms.capitalizeFirstLetter; import android.os.AsyncTask; import android.text.TextUtils; @@ -66,7 +65,6 @@ import net.osmand.search.core.SearchPhrase.NameStringMatcher; import net.osmand.search.core.SearchSettings; import net.osmand.shared.gpx.GpxFile; -import net.osmand.shared.gpx.GpxHelper; import net.osmand.shared.gpx.GpxUtilities; import net.osmand.shared.gpx.RouteActivityHelper; import net.osmand.shared.gpx.primitives.RouteActivity; @@ -1188,8 +1186,7 @@ private void reconstructGpxTagsFromAmenityType(Amenity amenity, Map Date: Tue, 10 Dec 2024 14:13:11 +0100 Subject: [PATCH 49/60] Make "gpx_icon" and "icon" interchangeable --- OsmAnd-java/src/main/java/net/osmand/data/Amenity.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java index d48a5ebd848..8006d1130fc 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java @@ -1,7 +1,6 @@ package net.osmand.data; -import static net.osmand.gpx.GPXUtilities.AMENITY_PREFIX; -import static net.osmand.gpx.GPXUtilities.OSM_PREFIX; +import static net.osmand.gpx.GPXUtilities.*; 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; @@ -353,10 +352,11 @@ public String getColor() { } public String getGpxIcon() { - return getAdditionalInfo(GPX_ICON); + String wikiVoyageIcon = getAdditionalInfo(GPX_ICON); + String travelGpxIcon = getAdditionalInfo(ICON_NAME_EXTENSION); + return Algorithms.isEmpty(wikiVoyageIcon) ? travelGpxIcon : wikiVoyageIcon; } - public String getContentLanguage(String tag, String lang, String defLang) { if (lang != null) { String translateName = getAdditionalInfo(tag + ":" + lang); From 677c96894d0fe55e4a70895b12db6617f2860a3d Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Tue, 10 Dec 2024 14:13:50 +0100 Subject: [PATCH 50/60] Fix broken wptPt tags in TravelGpx createWptPt --- .../plus/wikivoyage/data/TravelGpx.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java index bafb290f38c..e32035d9943 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java @@ -14,8 +14,7 @@ import net.osmand.data.Amenity; import net.osmand.util.Algorithms; -import java.util.HashMap; -import java.util.Map; +import java.util.Set; import net.osmand.shared.gpx.GpxTrackAnalysis; @@ -65,6 +64,8 @@ public GpxTrackAnalysis getAnalysis() { return analysis; } + private static final Set doNotSaveWptTags = Set.of("route_id", "route_name"); + @NonNull @Override public WptPt createWptPt(@NonNull Amenity amenity, @Nullable String lang) { @@ -75,26 +76,24 @@ public WptPt createWptPt(@NonNull Amenity amenity, @Nullable String lang) { for (String obfTag : amenity.getAdditionalInfoKeys()) { String value = amenity.getAdditionalInfo(obfTag); if (!Algorithms.isEmpty(value)) { - String gpxTag = allowedPointObfToGpxTags.get(obfTag); - if (gpxTag != null) { - wptPt.getExtensionsToWrite().put(gpxTag, value); - } if (OBF_POINTS_GROUPS_CATEGORY.equals(obfTag)) { wptPt.setCategory(value); + } else if ("name".equals(obfTag)) { + wptPt.setName(value); + } else if ("description".equals(obfTag)) { + wptPt.setDesc(value); + } else if ("note".equals(obfTag)) { + wptPt.setComment(value); + } else if ("colour".equals(obfTag) && amenity.getAdditionalInfoKeys().contains("color")) { + // ignore "colour" if "color" exists + } else if (!doNotSaveWptTags.contains(obfTag)) { + wptPt.getExtensionsToWrite().put(obfTag, value); } } } return wptPt; } - private final static Map allowedPointObfToGpxTags = new HashMap<>(); - - static { - allowedPointObfToGpxTags.put("color", "color"); - allowedPointObfToGpxTags.put("gpx_icon", "icon"); - allowedPointObfToGpxTags.put("gpx_bg", "background"); - } - @NonNull @Override public String getPointFilterString() { From 2f90b5cdb01774a8cc819630b0ab0eca2a0eda04 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Tue, 10 Dec 2024 18:09:31 +0100 Subject: [PATCH 51/60] Apply OBF_POINTS_GROUPS_EMPTY_NAME_VALUE --- .../commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt | 1 + .../src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt index 51659aedb65..941fafb9ee6 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt @@ -349,6 +349,7 @@ object GpxUtilities { const val OBF_POINTS_GROUPS_ICONS = "points_groups_icons" const val OBF_POINTS_GROUPS_COLORS = "points_groups_colors" const val OBF_POINTS_GROUPS_BACKGROUNDS = "points_groups_backgrounds" + const val OBF_POINTS_GROUPS_EMPTY_NAME_VALUE = "." // stub to store empty points_groups_names const val OBF_POINTS_GROUPS_CATEGORY = "points_groups_category" // optional category of OBF-GPX point fun parsePointsGroupAttributes(parser: XmlPullParser): PointsGroup { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 7c9af7d092f..f19a11180de 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -23,6 +23,7 @@ import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_BACKGROUNDS; import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_COLORS; import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_DELIMITER; +import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_EMPTY_NAME_VALUE; import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_ICONS; import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_NAMES; import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_PREFIX; @@ -1305,7 +1306,9 @@ private void reconstructPointsGroups(GpxFile gpxFile, List pgNames, List String icon = pgIcons.get(i); String background = pgBackgrounds.get(i); int color = KAlgorithms.INSTANCE.parseColor(pgColors.get(i)); - if (name.isEmpty()) name = GpxFile.DEFAULT_WPT_GROUP_NAME; // follow current default + if (name.isEmpty() || OBF_POINTS_GROUPS_EMPTY_NAME_VALUE.equals(name)) { + name = GpxFile.DEFAULT_WPT_GROUP_NAME; // follow current default + } GpxUtilities.PointsGroup pg = new GpxUtilities.PointsGroup(name, icon, background, color); gpxFile.addPointsGroup(pg); } From f570865164201d20367e992755acc5e1916b7371 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Tue, 10 Dec 2024 18:21:38 +0100 Subject: [PATCH 52/60] Optimize matchPointsAndTags with isAlreadyProcessed --- .../plus/wikivoyage/data/TravelObfHelper.java | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index f19a11180de..9a279dbad1b 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -1139,27 +1139,31 @@ private void fetchSegmentsAndPoints(List readers, TravelAr @NonNull private ResultMatcher matchPointsAndTags(TravelArticle article, List pointList, Map gpxFileExtensions, List pgNames, List pgIcons, List pgColors, List pgBackgrounds) { return new ResultMatcher() { + boolean isAlreadyProcessed = false; @Override public boolean publish(Amenity amenity) { if (amenity.getRouteId().equals(article.getRouteId())) { - reconstructGpxTagsFromAmenityType(amenity, gpxFileExtensions); if (amenity.isRouteTrack()) { - for (String tag : amenity.getAdditionalInfoKeys()) { - String value = amenity.getAdditionalInfo(tag); - if (tag.startsWith(OBF_POINTS_GROUPS_PREFIX)) { - final String delimiter = OBF_POINTS_GROUPS_DELIMITER; - List values = Arrays.asList(value.split(delimiter)); - if (OBF_POINTS_GROUPS_NAMES.equals(tag)) { - pgNames.addAll(values); - } else if (OBF_POINTS_GROUPS_ICONS.equals(tag)) { - pgIcons.addAll(values); - } else if (OBF_POINTS_GROUPS_COLORS.equals(tag)) { - pgColors.addAll(values); - } else if (OBF_POINTS_GROUPS_BACKGROUNDS.equals(tag)) { - pgBackgrounds.addAll(values); + if (!isAlreadyProcessed) { + isAlreadyProcessed = true; + reconstructGpxTagsFromAmenityType(amenity, gpxFileExtensions); + for (String tag : amenity.getAdditionalInfoKeys()) { + String value = amenity.getAdditionalInfo(tag); + if (tag.startsWith(OBF_POINTS_GROUPS_PREFIX)) { + final String delimiter = OBF_POINTS_GROUPS_DELIMITER; + List values = Arrays.asList(value.split(delimiter)); + if (OBF_POINTS_GROUPS_NAMES.equals(tag)) { + pgNames.addAll(values); + } else if (OBF_POINTS_GROUPS_ICONS.equals(tag)) { + pgIcons.addAll(values); + } else if (OBF_POINTS_GROUPS_COLORS.equals(tag)) { + pgColors.addAll(values); + } else if (OBF_POINTS_GROUPS_BACKGROUNDS.equals(tag)) { + pgBackgrounds.addAll(values); + } + } else if (!doNotSaveAmenityGpxTags.contains(tag)) { + gpxFileExtensions.put(tag, value); } - } else if (!doNotSaveAmenityGpxTags.contains(tag)) { - gpxFileExtensions.put(tag, value); } } } else if (ROUTE_TRACK_POINT.equals(amenity.getSubType())) { From ffd7b5db09750010f1577503005da01ed5a8a401 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Tue, 10 Dec 2024 22:34:10 +0100 Subject: [PATCH 53/60] Rename OBF_POINTS_GROUPS_EMPTY_NAME_STUB --- .../commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt | 2 +- .../src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt index 941fafb9ee6..1dd29d4f393 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt @@ -349,7 +349,7 @@ object GpxUtilities { const val OBF_POINTS_GROUPS_ICONS = "points_groups_icons" const val OBF_POINTS_GROUPS_COLORS = "points_groups_colors" const val OBF_POINTS_GROUPS_BACKGROUNDS = "points_groups_backgrounds" - const val OBF_POINTS_GROUPS_EMPTY_NAME_VALUE = "." // stub to store empty points_groups_names + const val OBF_POINTS_GROUPS_EMPTY_NAME_STUB = "." // stub to store empty points_groups_names const val OBF_POINTS_GROUPS_CATEGORY = "points_groups_category" // optional category of OBF-GPX point fun parsePointsGroupAttributes(parser: XmlPullParser): PointsGroup { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 9a279dbad1b..b670b8f0285 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -23,7 +23,7 @@ import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_BACKGROUNDS; import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_COLORS; import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_DELIMITER; -import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_EMPTY_NAME_VALUE; +import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_EMPTY_NAME_STUB; import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_ICONS; import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_NAMES; import static net.osmand.shared.gpx.GpxUtilities.PointsGroup.OBF_POINTS_GROUPS_PREFIX; @@ -1310,7 +1310,7 @@ private void reconstructPointsGroups(GpxFile gpxFile, List pgNames, List String icon = pgIcons.get(i); String background = pgBackgrounds.get(i); int color = KAlgorithms.INSTANCE.parseColor(pgColors.get(i)); - if (name.isEmpty() || OBF_POINTS_GROUPS_EMPTY_NAME_VALUE.equals(name)) { + if (name.isEmpty() || OBF_POINTS_GROUPS_EMPTY_NAME_STUB.equals(name)) { name = GpxFile.DEFAULT_WPT_GROUP_NAME; // follow current default } GpxUtilities.PointsGroup pg = new GpxUtilities.PointsGroup(name, icon, background, color); From 79c338c3067b36ee9f7a9f26e2f168a778f6c3b3 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Wed, 11 Dec 2024 15:24:17 +0100 Subject: [PATCH 54/60] Add public getPoiTypeByTagValue() --- .../main/java/net/osmand/osm/MapPoiTypes.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 9e769098df1..5ad79229d19 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -31,7 +31,7 @@ public class MapPoiTypes { - private static final String OTHER_MAP_CATEGORY = "Other"; + public static final String OTHER_MAP_CATEGORY = "Other"; private static MapPoiTypes DEFAULT_INSTANCE = null; private static final Log log = PlatformUtil.getLog(MapRenderingTypes.class); private String resourceName; @@ -971,11 +971,7 @@ public String replaceDeprecatedSubtype(PoiCategory type, String subtype) { } public Amenity parseAmenity(String tag, String val, boolean relation, Map otherTags) { - initPoiTypesByTag(); - PoiType pt = poiTypesByTag.get(tag + "/" + val); - if (pt == null) { - pt = poiTypesByTag.get(tag); - } + PoiType pt = getPoiTypeByTagValue(tag, val); if (pt == null || pt.isAdditional()) { return null; } @@ -1033,6 +1029,16 @@ public Amenity parseAmenity(String tag, String val, boolean relation, Map Date: Wed, 11 Dec 2024 16:31:33 +0100 Subject: [PATCH 55/60] Rename tags --- OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java | 2 +- .../net/osmand/plus/wikivoyage/data/TravelObfHelper.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java index e32035d9943..cbf22a3cd15 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java @@ -28,7 +28,7 @@ public class TravelGpx extends TravelArticle { public static final String AVERAGE_ELEVATION = "avg_ele"; public static final String START_ELEVATION = "start_ele"; public static final String ELE_GRAPH = "ele_graph"; - public static final String ROUTE_RADIUS = "route_radius"; + 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 TRAVEL_MAP_TO_POI_TAG = "route_id"; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index b670b8f0285..8072dcacdb0 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -17,7 +17,7 @@ import static net.osmand.plus.wikivoyage.data.TravelGpx.ELE_GRAPH; 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_RADIUS; +import static net.osmand.plus.wikivoyage.data.TravelGpx.ROUTE_BBOX_RADIUS; 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; @@ -122,7 +122,7 @@ public class TravelObfHelper implements TravelHelper { // Do not clutter GPX with tags that are always generated. private static final Set doNotSaveAmenityGpxTags = Set.of( - "date", "distance", "route_name", "route_radius", + "date", "distance", "route_name", "route_bbox_radius", "avg_ele", "min_ele", "max_ele", "start_ele", "ele_graph", "diff_ele_up", "diff_ele_down", "avg_speed", "min_speed", "max_speed", "time_moving", "time_moving_no_gaps", "time_span", "time_span_no_gaps" ); @@ -324,7 +324,7 @@ private TravelGpx getTravelGpx(File file, Amenity amenity) { travelGpx.minElevation = Algorithms.parseDoubleSilently(amenity.getTagContent(MIN_ELEVATION), 0); travelGpx.avgElevation = Algorithms.parseDoubleSilently(amenity.getTagContent(AVERAGE_ELEVATION), 0); travelGpx.maxElevation = Algorithms.parseDoubleSilently(amenity.getTagContent(MAX_ELEVATION), 0); - String radius = amenity.getTagContent(ROUTE_RADIUS); + String radius = amenity.getTagContent(ROUTE_BBOX_RADIUS); if (radius != null) { travelGpx.routeRadius = MapUtils.convertCharToDist(radius.charAt(0), TRAVEL_GPX_CONVERT_FIRST_LETTER, TRAVEL_GPX_CONVERT_FIRST_DIST, TRAVEL_GPX_CONVERT_MULT_1, TRAVEL_GPX_CONVERT_MULT_2); From a116dfd994d2144c3308c8ba14542a77e6d8d376 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Wed, 11 Dec 2024 17:22:21 +0100 Subject: [PATCH 56/60] Adapt getPoiTypeByTagValue for non-text additionals --- OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 5ad79229d19..edf34779cd4 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -1036,6 +1036,9 @@ public PoiType getPoiTypeByTagValue(String tag, String val) { if (pt == null) { pt = poiTypesByTag.get(tag); } + if (pt == null) { + pt = poiTypesByTag.get(tag + "/" + "null"); // required when no type="text" specified + } return pt; } From 1a4d69944591503c89dd5f6f2108e4a4cc8c24be Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Wed, 11 Dec 2024 18:39:03 +0100 Subject: [PATCH 57/60] Comment getPoiTypeByTagValue for non-text additionals --- OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index edf34779cd4..63f853dd390 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -1036,9 +1036,9 @@ public PoiType getPoiTypeByTagValue(String tag, String val) { if (pt == null) { pt = poiTypesByTag.get(tag); } - if (pt == null) { - pt = poiTypesByTag.get(tag + "/" + "null"); // required when no type="text" specified - } +// if (pt == null) { +// pt = poitypesbytag.get(tag + "/" + "null"); // required when no type="text" specified +// } return pt; } From 5271edba25a8e24822fc6d9bab01decd68233752 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Thu, 12 Dec 2024 16:33:55 +0100 Subject: [PATCH 58/60] Fix lastModified for deactivated maps (DateFormat) --- OsmAnd/src/net/osmand/plus/resources/ResourceManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index 9b33f16ed5f..cff31fc2397 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -1571,7 +1571,7 @@ public Map getBackupIndexes(Map map) { if (lf != null) { for (File f : lf) { if (f != null && f.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { - map.put(f.getName(), AndroidUtils.formatDate(context, f.lastModified())); + map.put(f.getName(), getDateFormat().format(f.lastModified())); } } } From 981fc8400a16ac6215f2d1df3bcb09509fefdd64 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Fri, 13 Dec 2024 11:38:45 +0100 Subject: [PATCH 59/60] Remove deprecated route_type translations --- OsmAnd/res/values-b+sr+Latn/phrases.xml | 13 +------------ OsmAnd/res/values-cs/phrases.xml | 11 ----------- OsmAnd/res/values-de/phrases.xml | 13 +------------ OsmAnd/res/values-eo/phrases.xml | 13 +------------ OsmAnd/res/values-es-rAR/phrases.xml | 11 ----------- OsmAnd/res/values-es-rUS/phrases.xml | 13 +------------ OsmAnd/res/values-es/phrases.xml | 13 +------------ OsmAnd/res/values-et/phrases.xml | 13 +------------ OsmAnd/res/values-hu/phrases.xml | 11 +---------- OsmAnd/res/values-is/phrases.xml | 13 +------------ OsmAnd/res/values-pt-rBR/phrases.xml | 12 +----------- OsmAnd/res/values-sr/phrases.xml | 13 +------------ OsmAnd/res/values-uk/phrases.xml | 13 +------------ OsmAnd/res/values-zh-rTW/phrases.xml | 13 +------------ 14 files changed, 12 insertions(+), 163 deletions(-) diff --git a/OsmAnd/res/values-b+sr+Latn/phrases.xml b/OsmAnd/res/values-b+sr+Latn/phrases.xml index bc7a9557a8e..1fb2f10f421 100644 --- a/OsmAnd/res/values-b+sr+Latn/phrases.xml +++ b/OsmAnd/res/values-b+sr+Latn/phrases.xml @@ -4884,17 +4884,6 @@ Tačke na putovanjima Druge rute Tačke drugih ruta - Bicikl - Pešačenje - Trčanje - Hodanje - Sportovi na vodi - Zimski sportovi - Koturaljke - Jahanje konja - Motorne sanke - Staze za trčanje - Brdski biciklizam Etimologija imena Naziv leve strane Naziv desne strane @@ -4904,4 +4893,4 @@ Osnovno Standardno Uslužno - \ No newline at end of file + diff --git a/OsmAnd/res/values-cs/phrases.xml b/OsmAnd/res/values-cs/phrases.xml index 94ae533fc65..1f1fa432cbe 100644 --- a/OsmAnd/res/values-cs/phrases.xml +++ b/OsmAnd/res/values-cs/phrases.xml @@ -4884,17 +4884,6 @@ Body na cestách Další trasy Další body trasy - Kolo - Pěší turistika - Běh - Chůze - Vodní sporty - Jízda na koni - Zimní sporty - Sněžný skútr - Fitness stezky - Inline brusle - Horská cyklistika Původ názvu Název pravé strany Název levé strany diff --git a/OsmAnd/res/values-de/phrases.xml b/OsmAnd/res/values-de/phrases.xml index f602d220bf7..ef8eaa990ae 100644 --- a/OsmAnd/res/values-de/phrases.xml +++ b/OsmAnd/res/values-de/phrases.xml @@ -4881,20 +4881,9 @@ Tunnel für Fußgänger verboten Tunnel für Radfahrer verboten Reisepunkte - Wassersport - Gehen - Reiten Reiseartikel Andere Routen Weitere Routenpunkte - Fahrrad - Wandern - Laufen - Wintersport - Schneemobil - Fitness-Parcour - Inlineskates - Mountainbiken Namensetymologie Name der linken Seite Name der rechten Seite @@ -4904,4 +4893,4 @@ Standard Einfach Kletterfels - \ No newline at end of file + diff --git a/OsmAnd/res/values-eo/phrases.xml b/OsmAnd/res/values-eo/phrases.xml index 71968b91e73..20f3c2bb54b 100644 --- a/OsmAnd/res/values-eo/phrases.xml +++ b/OsmAnd/res/values-eo/phrases.xml @@ -4880,17 +4880,6 @@ Vojaĝaj punktoj Aliaj kursoj Aliaj kursoj: punktoj - Biciklado - Marŝado - Kurado - Irado - Akvaj sportoj - Ĉevalrajdado - Vintraj sportoj - Motorsledado - Vojetoj de sportiloj - Rulglitado - Montbiciklado Parco Parco malakceptata Parkster @@ -4904,4 +4893,4 @@ kun necesejoj kaj akvo kun necesejoj, akvo kaj elektro luksa - \ No newline at end of file + diff --git a/OsmAnd/res/values-es-rAR/phrases.xml b/OsmAnd/res/values-es-rAR/phrases.xml index cbb967514dc..084f86324ac 100644 --- a/OsmAnd/res/values-es-rAR/phrases.xml +++ b/OsmAnd/res/values-es-rAR/phrases.xml @@ -4884,17 +4884,6 @@ Puntos turísticos Otras rutas Otros puntos de ruta - Bicicleta - Senderismo - Correr - Peatón - Deportes acuáticos - Equitación - Deportes de invierno - Motonieve - Circuitos aeróbicos - Patines en línea - Ciclismo de montaña Nombre etimológico Nombre del lado izquierdo Nombre del lado derecho diff --git a/OsmAnd/res/values-es-rUS/phrases.xml b/OsmAnd/res/values-es-rUS/phrases.xml index 9662da400c3..ad7ef86f7d8 100644 --- a/OsmAnd/res/values-es-rUS/phrases.xml +++ b/OsmAnd/res/values-es-rUS/phrases.xml @@ -4979,15 +4979,4 @@ Puntos turísticos Otras rutas Otros puntos de ruta - Bicicleta - Senderismo - Correr - Peatón - Deportes acuáticos - Equitación - Deportes de invierno - Motonieve - Circuitos aeróbicos - Patines en línea - Ciclismo de montaña - \ No newline at end of file + diff --git a/OsmAnd/res/values-es/phrases.xml b/OsmAnd/res/values-es/phrases.xml index cdebee18ec3..ac8db966179 100644 --- a/OsmAnd/res/values-es/phrases.xml +++ b/OsmAnd/res/values-es/phrases.xml @@ -4880,21 +4880,10 @@ Parco Túnel prohibido para peatones Túnel prohibido para ciclistas - Bicicleta - Senderismo - Correr - Peatonal - Deportes acuáticos - Equitación - Motonieve - Circuitos aeróbicos - Patines en línea - Bicicleta de montaña Artículos de viajes Puntos del viaje Otras rutas Otros puntos de la ruta - Deportes de invierno Nombre en el lado izquierdo Etimología del nombre Nombre en el lado derecho @@ -4904,4 +4893,4 @@ De lujo Tipo de camping Básico - \ No newline at end of file + diff --git a/OsmAnd/res/values-et/phrases.xml b/OsmAnd/res/values-et/phrases.xml index 1f5eca27146..31608e0a329 100644 --- a/OsmAnd/res/values-et/phrases.xml +++ b/OsmAnd/res/values-et/phrases.xml @@ -4872,19 +4872,8 @@ Rattateede võrgustik Kategooria: määramine Kategooria: servituut - Veespordialad - Kõndimine - Jooksmine - Matkamine - Rattasõit Muud teekonnapunktid Muud teekonnad - Talispordialad - Ratsutamine - Rulluisutamine üherealiste uiskudega - Terviserajad - Mootorsaanisõit - Mägirattasõit Parksteri teenus pole kasutatav Parkster Parco teenus pole kasutatav @@ -4897,4 +4886,4 @@ Lisateenustega Standardne Luksuslik - \ No newline at end of file + diff --git a/OsmAnd/res/values-hu/phrases.xml b/OsmAnd/res/values-hu/phrases.xml index f263f2e5a9b..5c8ae442586 100644 --- a/OsmAnd/res/values-hu/phrases.xml +++ b/OsmAnd/res/values-hu/phrases.xml @@ -4880,14 +4880,5 @@ Parcót nem fogad el Parkster Parkstert nem fogad el - Vízi sportok - Lovaglás - Téli sportok - Hójáró - Hegyi kerékpározás Egyéb útvonalak - Kerékpározás - Futás - Gyaloglás - Túrázás - \ No newline at end of file + diff --git a/OsmAnd/res/values-is/phrases.xml b/OsmAnd/res/values-is/phrases.xml index 2e048be1665..0714eac1ab4 100644 --- a/OsmAnd/res/values-is/phrases.xml +++ b/OsmAnd/res/values-is/phrases.xml @@ -4932,24 +4932,13 @@ Flúð Fjársjóðaleit á strönd Túlkunarsvæði - Línuskautar - Fjallahjólreiðar Göng bönnuð fyrir gangandi Göng bönnuð fyrir hjólandi Ferðagreinar Punktar ferðar Aðrar leiðir Punktar í öðrum leiðum - Hjólandi - Gönguferðir - Hlaupandi - Gangandi - Vatnaíþróttir - Hestaferðir - Vetraríþróttir - Vélsleðar - Fitness-leiðir Nafn hægra megin Orðsifjar nafns Nafn vinstra megin - \ No newline at end of file + diff --git a/OsmAnd/res/values-pt-rBR/phrases.xml b/OsmAnd/res/values-pt-rBR/phrases.xml index fa5ecd5dbe2..81282c24ebe 100644 --- a/OsmAnd/res/values-pt-rBR/phrases.xml +++ b/OsmAnd/res/values-pt-rBR/phrases.xml @@ -4874,21 +4874,11 @@ Depósito de dinheiro Acesso Outras rotas - Corrida Túnel proibido para pedestres Túnel proibido para ciclistas Artigos de viagem Pontos de viagem Outros pontos de rotas - Bicicleta - Caminhada - A pé - Esportes aquáticos - Local de equitação - Esportes de inverno - Moto de neve - Trilhas de exercícios - Patins em linha Parco não aceito Parkster não aceito - \ No newline at end of file + diff --git a/OsmAnd/res/values-sr/phrases.xml b/OsmAnd/res/values-sr/phrases.xml index 62389f98760..8c644c9f313 100644 --- a/OsmAnd/res/values-sr/phrases.xml +++ b/OsmAnd/res/values-sr/phrases.xml @@ -4884,20 +4884,9 @@ Тунел забрањен за бициклисте Тунел забрањен за пешаке Тачке на путовањима - Планинарење - Спортови на води - Јахање коња - Зимски спортови - Моторне санке - Брдски бициклизам Чланци о путовањима Друге руте Тачке других рута - Бицикл - Пешачење - Трчање - Стазе за трчање - Котураљке Етимологија имена Назив леве стране Назив десне стране @@ -4907,4 +4896,4 @@ Основно Стандардно Делукс - \ No newline at end of file + diff --git a/OsmAnd/res/values-uk/phrases.xml b/OsmAnd/res/values-uk/phrases.xml index fee459e6ec9..e19c1ae12b4 100644 --- a/OsmAnd/res/values-uk/phrases.xml +++ b/OsmAnd/res/values-uk/phrases.xml @@ -4881,17 +4881,6 @@ Пункти Інші маршрути Інші пункти маршруту - Велосипед - Піший туризм - Біг - Ходьба - Водні види спорту - Верхова їзда - Зимові види спорту - Снігохід - Фітнес-стежки - Роликові ковзани - Катання на гірських велосипедах Паркомісце не прийнято Паркомісце Паркер не прийнято @@ -4904,4 +4893,4 @@ Делюкс Тип турбази Стандартний - \ No newline at end of file + diff --git a/OsmAnd/res/values-zh-rTW/phrases.xml b/OsmAnd/res/values-zh-rTW/phrases.xml index 201c762139c..89a3ad1e70d 100644 --- a/OsmAnd/res/values-zh-rTW/phrases.xml +++ b/OsmAnd/res/values-zh-rTW/phrases.xml @@ -4882,19 +4882,8 @@ 隧道禁止腳踏車騎士通行 其他路線 其他路線點 - 腳踏車 - 騎馬 - 冬季運動 - 雪地摩托車 - 直排輪鞋 - 山區騎乘 旅遊點 旅遊文章 - 健行 - 跑步 - 步行 - 水上運動 - 健身路徑 名稱詞源學 左側的名稱 右側的名稱 @@ -4904,4 +4893,4 @@ 露營地類型 基本 豪華 - \ No newline at end of file + From 5dfebfd8b348616f493fa04126fed2c18261a833 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Fri, 13 Dec 2024 11:45:49 +0100 Subject: [PATCH 60/60] Actualize TravelGpx type/activity strings, fix npe --- .../main/java/net/osmand/osm/MapPoiTypes.java | 2 +- OsmAnd/res/values/phrases.xml | 22 ++++++++----------- .../plus/render/TravelRendererHelper.java | 5 ++++- .../plus/wikivoyage/data/TravelObfHelper.java | 6 ++--- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index 63f853dd390..8e14cf29fd8 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -49,7 +49,7 @@ public class MapPoiTypes { public static final String ROUTE_ARTICLE_POINT = "route_article_point"; public static final String CATEGORY = "category"; public static final String ROUTE_TRACK = "route_track"; // routes:route_track (no activity) - public static final String ROUTES_PREFIX = "routes_"; // routes:routes_xxx (activity type) + public static final String ROUTES_PREFIX = "routes_"; // routes:routes_xxx (any activity type) public static final String ROUTE_TRACK_POINT = "route_track_point"; private PoiTranslator poiTranslator = null; diff --git a/OsmAnd/res/values/phrases.xml b/OsmAnd/res/values/phrases.xml index 233b3ac0704..5b8e7cf788d 100644 --- a/OsmAnd/res/values/phrases.xml +++ b/OsmAnd/res/values/phrases.xml @@ -5454,19 +5454,15 @@ Travel Articles Travel Points - Other routes - Other routes points - Bicycle - Hiking - Running - Walking - Water sports - Horse riding - Winter sports - Snowmobile - Fitness trails - Inline skates - Mountain biking + Route points + Driving + Motorcycling + Foot + Winter sports + Cycling + Air Sports + Water sports + Other routes Name etymology Name of the left side diff --git a/OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java b/OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java index 61f344c0ab6..74cd7cc1776 100644 --- a/OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java +++ b/OsmAnd/src/net/osmand/plus/render/TravelRendererHelper.java @@ -280,7 +280,10 @@ public void updateRouteTrackFilters() { routeTrackFilters.add(app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + subTypeKeyName)); } } - routeTrackFilters.add(app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + ROUTE_TRACK)); + PoiUIFilter filter = app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + ROUTE_TRACK); + if (filter != null) { + routeTrackFilters.add(filter); + } } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 8072dcacdb0..4a44ea6b73b 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -316,7 +316,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(ACTIVITY_TYPE)); // TODO travelGpx.ref = Algorithms.emptyIfNull(amenity.getRef()); travelGpx.totalDistance = Algorithms.parseFloatSilently(amenity.getTagContent(DISTANCE), 0); travelGpx.diffElevationUp = Algorithms.parseDoubleSilently(amenity.getTagContent(DIFF_ELEVATION_UP), 0); @@ -342,7 +342,7 @@ public boolean accept(PoiCategory type, String subcategory) { return true; } if (ROUTE_TRACK.equals(filter) && subcategory.startsWith(ROUTES_PREFIX)) { - return true; // include routes:routes_xxx by routes:route_track filter + return true; // include routes:routes_xxx with routes:route_track filter } } return false; @@ -1287,7 +1287,7 @@ private synchronized GpxFile buildGpxFile(@NonNull List re 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 metadata + gpxFileExtensions.remove(GpxUtilities.ACTIVITY_TYPE); // move activity to metadata TODO fixme } gpxFile.getExtensionsToWrite().putAll(gpxFileExtensions); // finally }