Move isIdle to TrackStatisticsUpdater.

This commit is contained in:
Dennis Guse
2025-11-18 06:18:34 +01:00
parent a310f773a1
commit 911f2c525f
2 changed files with 7 additions and 20 deletions
@@ -67,8 +67,6 @@ public class SegmentStatisticUpdater {
private HeartRate avgHeartRate = null; private HeartRate avgHeartRate = null;
private Power avgPower = null; private Power avgPower = null;
private boolean isIdle;
public SegmentStatisticUpdater() { public SegmentStatisticUpdater() {
reset(); reset();
} }
@@ -80,7 +78,6 @@ public class SegmentStatisticUpdater {
*/ */
public SegmentStatisticUpdater(SegmentStatisticUpdater other) { public SegmentStatisticUpdater(SegmentStatisticUpdater other) {
this(other.getStatistics()); this(other.getStatistics());
this.isIdle = other.isIdle();
} }
public SegmentStatisticUpdater(Statistics statistics) { public SegmentStatisticUpdater(Statistics statistics) {
@@ -120,8 +117,6 @@ public class SegmentStatisticUpdater {
stopTime = stopTime.isAfter(other.stopTime) ? stopTime : other.stopTime; stopTime = stopTime.isAfter(other.stopTime) ? stopTime : other.stopTime;
} }
isIdle = other.isIdle; //TODO This implicitly assumes append mode.
if (avgHeartRate == null) { if (avgHeartRate == null) {
avgHeartRate = other.avgHeartRate; avgHeartRate = other.avgHeartRate;
} else { } else {
@@ -190,8 +185,6 @@ public class SegmentStatisticUpdater {
maxSpeed = Speed.ZERO; maxSpeed = Speed.ZERO;
totalAltitudeGain_m = null; totalAltitudeGain_m = null;
totalAltitudeLoss_m = null; totalAltitudeLoss_m = null;
isIdle = false;
} }
public void reset(Instant startTime) { public void reset(Instant startTime) {
@@ -256,14 +249,6 @@ public class SegmentStatisticUpdater {
this.movingDuration = this.movingDuration.plus(movingDuration); this.movingDuration = this.movingDuration.plus(movingDuration);
} }
public boolean isIdle() {
return isIdle;
}
public void setIdle(boolean idle) {
isIdle = idle;
}
private Speed getAverageMovingSpeed() { private Speed getAverageMovingSpeed() {
return Speed.of(totalDistance, movingDuration); return Speed.of(totalDistance, movingDuration);
} }
@@ -54,6 +54,8 @@ public class TrackStatisticsUpdater {
// Current segment's last trackPoint // Current segment's last trackPoint
private TrackPoint lastTrackPoint; private TrackPoint lastTrackPoint;
private boolean isIdle;
public TrackStatisticsUpdater() { public TrackStatisticsUpdater() {
this(new SegmentStatisticUpdater()); this(new SegmentStatisticUpdater());
} }
@@ -88,7 +90,7 @@ public class TrackStatisticsUpdater {
} }
public boolean isIdle() { public boolean isIdle() {
return currentSegment.isIdle(); return isIdle;
} }
public Statistics getCurrentSegment() { public Statistics getCurrentSegment() {
@@ -159,19 +161,19 @@ public class TrackStatisticsUpdater {
currentSegment.addTotalDistance(movingDistance); currentSegment.addTotalDistance(movingDistance);
} }
if (!currentSegment.isIdle()) { if (!isIdle) {
if (!trackPoint.isSegmentManualStart() && lastTrackPoint != null) { if (!trackPoint.isSegmentManualStart() && lastTrackPoint != null) {
currentSegment.addMovingTime(trackPoint, lastTrackPoint); currentSegment.addMovingTime(trackPoint, lastTrackPoint);
} }
} }
if (trackPoint.isIdleTriggered()) { if (trackPoint.isIdleTriggered()) {
currentSegment.setIdle(true); isIdle = true;
} else if (currentSegment.isIdle()) { } else if (isIdle) {
// Shall we switch to non-idle? // Shall we switch to non-idle?
if (movingDistance != null if (movingDistance != null
&& movingDistance.greaterOrEqualThan(PreferencesUtils.getRecordingDistanceInterval())) { && movingDistance.greaterOrEqualThan(PreferencesUtils.getRecordingDistanceInterval())) {
currentSegment.setIdle(false); isIdle = false;
} }
} }