From 687e5f6d814b4642e5cd623cf86fc4bc26707565 Mon Sep 17 00:00:00 2001 From: cepprice Date: Wed, 7 Apr 2021 10:44:04 +0500 Subject: [PATCH] Change condition of multi profile mode --- .../MeasurementEditingContext.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java index af4d599afa..2de8070b58 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java @@ -2,6 +2,7 @@ package net.osmand.plus.measurementtool; import android.util.Pair; +import net.osmand.AndroidUtils; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.TrkSegment; import net.osmand.GPXUtilities.WptPt; @@ -1115,16 +1116,26 @@ public class MeasurementEditingContext implements IRouteSettingsListener { } public boolean isInMultiProfileMode() { - if (lastCalculationMode == CalculationMode.NEXT_SEGMENT) { - return true; - } Set profiles = new HashSet<>(); - for (RoadSegmentData segmentData : roadSegmentData.values()) { - String profile = segmentData.getAppMode().getStringKey(); - if (!DEFAULT_APP_MODE.getStringKey().equals(profile)) { - profiles.add(profile); + List allSegments = new ArrayList<>(); + allSegments.addAll(beforeSegments); + allSegments.addAll(afterSegments); + for (TrkSegment segment : allSegments) { + List points = segment.points; + if (Algorithms.isEmpty(points)) { + continue; + } + for (int i = 0; i < points.size() / 2 + 1; i++) { + WptPt left = points.get(i); + int rightIdx = points.size() - 1 - i; + WptPt right = points.get(rightIdx); + if (!left.isGap() && i + 1 < points.size()) { + profiles.add(left.getProfileType()); + } + if (!right.isGap() && rightIdx + 1 < points.size()) { + profiles.add(right.getProfileType()); + } if (profiles.size() >= 2) { - lastCalculationMode = NEXT_SEGMENT; return true; } }