Change condition of multi profile mode

This commit is contained in:
cepprice 2021-04-07 10:44:04 +05:00
parent 7fd107c97a
commit 687e5f6d81

View file

@ -2,6 +2,7 @@ package net.osmand.plus.measurementtool;
import android.util.Pair; import android.util.Pair;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.TrkSegment; import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt; import net.osmand.GPXUtilities.WptPt;
@ -1115,16 +1116,26 @@ public class MeasurementEditingContext implements IRouteSettingsListener {
} }
public boolean isInMultiProfileMode() { public boolean isInMultiProfileMode() {
if (lastCalculationMode == CalculationMode.NEXT_SEGMENT) {
return true;
}
Set<String> profiles = new HashSet<>(); Set<String> profiles = new HashSet<>();
for (RoadSegmentData segmentData : roadSegmentData.values()) { List<TrkSegment> allSegments = new ArrayList<>();
String profile = segmentData.getAppMode().getStringKey(); allSegments.addAll(beforeSegments);
if (!DEFAULT_APP_MODE.getStringKey().equals(profile)) { allSegments.addAll(afterSegments);
profiles.add(profile); for (TrkSegment segment : allSegments) {
List<WptPt> 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) { if (profiles.size() >= 2) {
lastCalculationMode = NEXT_SEGMENT;
return true; return true;
} }
} }