TrackRecordingService: generate timestamps for TrackPoints in HandlerServer.

Part of #822.
This commit is contained in:
Dennis Guse
2021-07-12 23:03:37 +02:00
parent 223ad70d36
commit 7d24262b38
15 changed files with 122 additions and 110 deletions
@@ -49,7 +49,7 @@ public class TrackPoint {
private TrackPoint.Id id;
@NonNull
private Instant time;
private final Instant time;
private Double latitude;
private Double longitude;
@@ -96,18 +96,13 @@ public class TrackPoint {
private Float altitudeGain_m = null;
private Float altitudeLoss_m = null;
public TrackPoint(@NonNull Type type) {
public TrackPoint(@NonNull Type type, @NonNull Instant time) {
this.type = type;
this.time = Instant.now(); //TODO This may result in #800
}
public TrackPoint(@NonNull Type type, Instant time) {
this(type);
this.time = time;
}
public TrackPoint(@NonNull Location location) {
this(Type.TRACKPOINT, location, Instant.now()); //TODO This may result in #800
public TrackPoint(@NonNull Location location, @NonNull Instant time) {
this(Type.TRACKPOINT, location, time);
}
public TrackPoint(@NonNull Type type, @NonNull Location location, @NonNull Instant time) {
@@ -130,28 +125,14 @@ public class TrackPoint {
this.altitude = altitude;
}
@Deprecated //See #316
public static TrackPoint createSegmentStartManual() {
return createSegmentStartManualWithTime(Instant.now());
}
public static TrackPoint createSegmentStartManualWithTime(Instant time) {
return new TrackPoint(Type.SEGMENT_START_MANUAL, time);
}
@Deprecated //See #316
public static TrackPoint createSegmentStartAutomatic() {
return createSegmentStartAutomaticWithTime(Instant.now());
}
public static TrackPoint createSegmentStartAutomaticWithTime(Instant time) {
return new TrackPoint(Type.SEGMENT_START_AUTOMATIC, time);
}
public static TrackPoint createSegmentEnd() {
return createSegmentEndWithTime(Instant.now());
}
public static TrackPoint createSegmentEndWithTime(Instant time) {
return new TrackPoint(Type.SEGMENT_END_MANUAL, time);
}
@@ -256,15 +237,11 @@ public class TrackPoint {
return this;
}
@NonNull
public Instant getTime() {
return time;
}
public TrackPoint setTime(Instant time) {
this.time = time;
return this;
}
public boolean isRecent() {
return Instant.now()
.isBefore(time.plus(MAX_LOCATION_AGE));
@@ -506,7 +506,8 @@ public class ContentProviderUtils {
* @param indexes the cached trackPoints indexes
*/
static TrackPoint fillTrackPoint(Cursor cursor, CachedTrackPointsIndexes indexes) {
TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.getById(cursor.getInt(indexes.typeIndex)));
Instant time = Instant.ofEpochMilli(cursor.getLong(indexes.timeIndex));
TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.getById(cursor.getInt(indexes.typeIndex)), time);
trackPoint.setId(new TrackPoint.Id(cursor.getInt(indexes.idIndex)));
if (!cursor.isNull(indexes.longitudeIndex)) {
@@ -515,9 +516,6 @@ public class ContentProviderUtils {
if (!cursor.isNull(indexes.latitudeIndex)) {
trackPoint.setLatitude(((double) cursor.getInt(indexes.latitudeIndex)) / 1E6);
}
if (!cursor.isNull(indexes.timeIndex)) {
trackPoint.setTime(Instant.ofEpochMilli(cursor.getLong(indexes.timeIndex)));
}
if (!cursor.isNull(indexes.altitudeIndex)) {
trackPoint.setAltitude(Altitude.WGS84.of(cursor.getFloat(indexes.altitudeIndex)));
}