mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-07 11:53:07 +02:00
Statistics: used when only the data is needed (instead of passing SegmentStatisticUpdater).
This commit is contained in:
@@ -20,12 +20,13 @@ public record RecordingData(Track track, TrackPoint latestTrackPoint, SensorData
|
||||
return track.getActivityTypeLocalized();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@NonNull
|
||||
public SegmentStatisticUpdater getStatisticsTrack() {
|
||||
public Statistics getStatisticsTrack() {
|
||||
if (track == null) {
|
||||
return new SegmentStatisticUpdater();
|
||||
return new SegmentStatisticUpdater().getStatistics();
|
||||
}
|
||||
|
||||
return track.getTrackStatistics();
|
||||
return track.getTrackStatistics().getStatistics();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public class TrackRecordingManager implements SharedPreferences.OnSharedPreferen
|
||||
|
||||
ALTITUDE_CORRECTION_MANAGER.correctAltitude(context, current.first);
|
||||
|
||||
Track track = contentProviderUtils.getTrack(trackId); //Get copy
|
||||
Track track = contentProviderUtils.getTrack(trackId); //Get copy TODO: Avoid re-loading data from DB
|
||||
if (track == null) {
|
||||
Log.w(TAG, "Requesting data if not recording is taking place, should not be done.");
|
||||
return null;
|
||||
|
||||
@@ -194,7 +194,7 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
||||
|
||||
startSensors();
|
||||
|
||||
voiceAnnouncementManager.start(trackRecordingManager.getTrackStatistics());
|
||||
voiceAnnouncementManager.start(trackRecordingManager.getTrackStatistics().getStatistics());
|
||||
|
||||
notificationManager.onRecordingStarted(this, recordingStatus.trackId());
|
||||
}
|
||||
|
||||
+1
-1
@@ -118,7 +118,7 @@ class TrackRecordingServiceNotificationManager implements SharedPreferences.OnSh
|
||||
previousLocationWasAccurate = currentLocationWasAccurate;
|
||||
}
|
||||
|
||||
notificationBuilder.setContentTitle(context.getString(R.string.track_distance_notification, formatter.formatDistance(recordingData.getStatisticsTrack().getTotalDistance())));
|
||||
notificationBuilder.setContentTitle(context.getString(R.string.track_distance_notification, formatter.formatDistance(recordingData.getStatisticsTrack().totalDistance())));
|
||||
String formattedSpeed = SpeedFormatter.Builder().setUnit(unitSystem).setReportSpeedOrPace(true).build(context).formatSpeed(recordingData.latestTrackPoint().getSpeed());
|
||||
notificationBuilder.setContentText(context.getString(R.string.track_speed_notification, formattedSpeed));
|
||||
notificationBuilder.setSubText(context.getString(R.string.track_recording_notification_accuracy, formattedAccuracy));
|
||||
|
||||
+10
-11
@@ -37,7 +37,7 @@ import de.dennisguse.opentracks.data.models.TrackPoint;
|
||||
import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet;
|
||||
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
||||
import de.dennisguse.opentracks.stats.SensorStatistics;
|
||||
import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
|
||||
import de.dennisguse.opentracks.stats.Statistics;
|
||||
import de.dennisguse.opentracks.ui.intervals.IntervalStatistics;
|
||||
|
||||
/**
|
||||
@@ -53,7 +53,7 @@ public class VoiceAnnouncementManager implements SharedPreferences.OnSharedPrefe
|
||||
|
||||
private TTSManager voiceAnnouncement;
|
||||
|
||||
private SegmentStatisticUpdater trackStatistics;
|
||||
private Statistics trackStatistics;
|
||||
|
||||
private static final Distance DISTANCE_OFF = Distance.of(Double.MAX_VALUE);
|
||||
private Distance distanceFrequency = DISTANCE_OFF;
|
||||
@@ -79,13 +79,13 @@ public class VoiceAnnouncementManager implements SharedPreferences.OnSharedPrefe
|
||||
intervalStatistics = new IntervalStatistics(intervalDistance);
|
||||
}
|
||||
|
||||
public void start(@Nullable SegmentStatisticUpdater trackStatistics) {
|
||||
public void start(@Nullable Statistics trackStatistics) {
|
||||
voiceAnnouncement = new TTSManager(context);
|
||||
voiceAnnouncement.start();
|
||||
update(trackStatistics);
|
||||
}
|
||||
|
||||
void update(@Nullable SegmentStatisticUpdater trackStatistics) {
|
||||
void update(@Nullable Statistics trackStatistics) {
|
||||
this.trackStatistics = trackStatistics;
|
||||
updateNextDuration();
|
||||
updateNextTaskDistance();
|
||||
@@ -126,12 +126,12 @@ public class VoiceAnnouncementManager implements SharedPreferences.OnSharedPrefe
|
||||
}
|
||||
|
||||
boolean announce = false;
|
||||
this.trackStatistics = track.getTrackStatistics();
|
||||
if (trackStatistics.getTotalDistance().greaterThan(nextTotalDistance)) {
|
||||
this.trackStatistics = track.getStatistics();
|
||||
if (trackStatistics.totalDistance().greaterThan(nextTotalDistance)) {
|
||||
updateNextTaskDistance();
|
||||
announce = true;
|
||||
}
|
||||
if (!trackStatistics.getTotalTime().minus(nextTotalTime).isNegative()) {
|
||||
if (!trackStatistics.totalTime().minus(nextTotalTime).isNegative()) {
|
||||
updateNextDuration();
|
||||
announce = true;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public class VoiceAnnouncementManager implements SharedPreferences.OnSharedPrefe
|
||||
nextTotalDistance = DISTANCE_OFF;
|
||||
} else {
|
||||
|
||||
Distance distance = trackStatistics.getTotalDistance();
|
||||
Distance distance = trackStatistics.totalDistance();
|
||||
|
||||
int index = (int) (distance.dividedBy(distanceFrequency));
|
||||
nextTotalDistance = distanceFrequency.multipliedBy(index + 1);
|
||||
@@ -195,10 +195,9 @@ public class VoiceAnnouncementManager implements SharedPreferences.OnSharedPrefe
|
||||
nextTotalTime = TOTALTIME_OFF;
|
||||
} else {
|
||||
|
||||
Duration totalTime = trackStatistics.getTotalTime();
|
||||
Duration intervalMod = Duration.ofMillis(trackStatistics.getTotalTime().toMillis() % totalTimeFrequency.toMillis());
|
||||
Duration intervalMod = Duration.ofMillis(trackStatistics.totalTime().toMillis() % totalTimeFrequency.toMillis());
|
||||
|
||||
nextTotalTime = totalTime.plus(totalTimeFrequency.minus(intervalMod));
|
||||
nextTotalTime = trackStatistics.totalTime().plus(totalTimeFrequency.minus(intervalMod));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -37,7 +37,7 @@ import de.dennisguse.opentracks.data.models.Track;
|
||||
import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet;
|
||||
import de.dennisguse.opentracks.settings.UnitSystem;
|
||||
import de.dennisguse.opentracks.stats.SensorStatistics;
|
||||
import de.dennisguse.opentracks.stats.SegmentStatisticUpdater;
|
||||
import de.dennisguse.opentracks.stats.Statistics;
|
||||
import de.dennisguse.opentracks.ui.intervals.IntervalStatistics;
|
||||
import de.dennisguse.opentracks.util.StringUtils;
|
||||
|
||||
@@ -52,7 +52,7 @@ class VoiceAnnouncementUtils {
|
||||
}
|
||||
|
||||
static Spannable createStatistics(Context context, Track track, SensorDataSet sensorDataSet, UnitSystem unitSystem, boolean isReportSpeed, @Nullable IntervalStatistics.Interval currentInterval, @Nullable SensorStatistics sensorStatistics) {
|
||||
SegmentStatisticUpdater trackStatistics = track.getTrackStatistics();
|
||||
Statistics trackStatistics = track.getStatistics();
|
||||
|
||||
SpannableStringBuilder builder = new SpannableStringBuilder();
|
||||
|
||||
@@ -60,7 +60,7 @@ class VoiceAnnouncementUtils {
|
||||
appendTime(builder, track.getStopTime());
|
||||
}
|
||||
|
||||
Distance totalDistance = trackStatistics.getTotalDistance();
|
||||
Distance totalDistance = trackStatistics.totalDistance();
|
||||
Speed averageMovingSpeed = trackStatistics.getAverageMovingSpeed();
|
||||
Speed currentDistancePerTime = currentInterval != null ? currentInterval.getSpeed() : null;
|
||||
|
||||
@@ -112,7 +112,7 @@ class VoiceAnnouncementUtils {
|
||||
boolean hasTravelledDistance = !totalDistance.isZero();
|
||||
|
||||
// Announce time
|
||||
Duration movingTime = trackStatistics.getMovingTime();
|
||||
Duration movingTime = trackStatistics.movingTime();
|
||||
if (shouldVoiceAnnounceMovingTime() && hasTravelledDistance && !movingTime.isZero()) {
|
||||
appendDuration(context, builder, movingTime);
|
||||
builder.append(".");
|
||||
|
||||
Reference in New Issue
Block a user