Cleanup: use Position and cleanup TrackPoint.

This commit is contained in:
Dennis Guse
2025-02-28 22:41:28 +01:00
parent 1d5f65be48
commit e7aa6f20d4
17 changed files with 526 additions and 428 deletions
@@ -18,7 +18,9 @@ package de.dennisguse.opentracks.chart;
import java.time.Instant; import java.time.Instant;
import de.dennisguse.opentracks.data.models.Altitude;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
@@ -27,6 +29,7 @@ import de.dennisguse.opentracks.data.models.TrackPoint;
* *
* @author Youtao Liu * @author Youtao Liu
*/ */
//TODO Move to ChartPointTest
class TrackStubUtils { class TrackStubUtils {
public static final double INITIAL_ALTITUDE = 22; public static final double INITIAL_ALTITUDE = 22;
@@ -52,12 +55,16 @@ class TrackStubUtils {
* @return a SensorDataSetLocation stub. * @return a SensorDataSetLocation stub.
*/ */
private static TrackPoint createDefaultTrackPoint(double latitude, double longitude, double altitude) { private static TrackPoint createDefaultTrackPoint(double latitude, double longitude, double altitude) {
return new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochMilli(INITIAL_TIME)) return new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(latitude) new Position(
.setLongitude(longitude) Instant.ofEpochMilli(INITIAL_TIME),
.setAltitude(altitude) latitude,
.setHorizontalAccuracy(INITIAL_ACCURACY) longitude,
.setSpeed(INITIAL_SPEED) INITIAL_ACCURACY,
.setBearing(INITIAL_BEARING); Altitude.WGS84.of(altitude),
INITIAL_ACCURACY,
INITIAL_BEARING,
INITIAL_SPEED
));
} }
} }
@@ -13,8 +13,10 @@ import java.util.List;
import de.dennisguse.opentracks.data.ContentProviderUtils; import de.dennisguse.opentracks.data.ContentProviderUtils;
import de.dennisguse.opentracks.data.TrackPointIterator; import de.dennisguse.opentracks.data.TrackPointIterator;
import de.dennisguse.opentracks.data.models.Altitude;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Marker; import de.dennisguse.opentracks.data.models.Marker;
import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
@@ -109,12 +111,17 @@ public class TestDataUtil {
} }
public static TrackPoint createTrackPoint(int i) { public static TrackPoint createTrackPoint(int i) {
TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(i)); TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT,
trackPoint.setLatitude(INITIAL_LATITUDE + (double) i / 10000.0); new Position(
trackPoint.setLongitude(INITIAL_LONGITUDE - (double) i / 10000.0); Instant.ofEpochSecond(i),
trackPoint.setHorizontalAccuracy(Distance.of(i / 100.0f)); INITIAL_LATITUDE + (double) i / 10000.0,
trackPoint.setAltitude(i * ALTITUDE_INTERVAL); INITIAL_LONGITUDE - (double) i / 10000.0,
trackPoint.setSpeed(Speed.of(5f + (i / 10f))); Distance.of(i / 100.0f),
Altitude.WGS84.of(i * ALTITUDE_INTERVAL),
null,
null,
Speed.of(5f + (i / 10f))
));
trackPoint.setHeartRate(100f + i % 80); trackPoint.setHeartRate(100f + i % 80);
trackPoint.setCadence(300f + i); trackPoint.setCadence(300f + i);
@@ -5,7 +5,9 @@ import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import de.dennisguse.opentracks.data.models.Altitude;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
@@ -16,10 +18,20 @@ public class TestSensorDataUtil {
public void add(Instant time, Float hr, Float cadence, Float power, TrackPoint.Type type) { public void add(Instant time, Float hr, Float cadence, Float power, TrackPoint.Type type) {
sensorDataList.add(new TestSensorDataUtil.SensorData(time, hr, cadence, power, type)); sensorDataList.add(new TestSensorDataUtil.SensorData(time, hr, cadence, power, type));
TrackPoint tp = new TrackPoint(type, time);
int i = trackPointList.size() + 1; int i = trackPointList.size() + 1;
tp.setLatitude(TestDataUtil.INITIAL_LATITUDE + (double) i / 10000.0);
tp.setLongitude(TestDataUtil.INITIAL_LONGITUDE - (double) i / 10000.0); TrackPoint tp = new TrackPoint(type,
new Position(
time,
TestDataUtil.INITIAL_LATITUDE + (double) i / 10000.0,
TestDataUtil.INITIAL_LONGITUDE - (double) i / 10000.0,
Distance.of(1f),
Altitude.WGS84.of(1f),
null,
null,
Speed.of(5f + (i / 10f))
)
);
if (hr != null) { if (hr != null) {
tp.setHeartRate(hr); tp.setHeartRate(hr);
} }
@@ -29,9 +41,6 @@ public class TestSensorDataUtil {
if (power != null) { if (power != null) {
tp.setPower(power); tp.setPower(power);
} }
tp.setHorizontalAccuracy(Distance.of(1f));
tp.setAltitude(1f);
tp.setSpeed(Speed.of(5f + (i / 10f)));
tp.setAltitudeGain(3f); tp.setAltitudeGain(3f);
tp.setAltitudeLoss(3f); tp.setAltitudeLoss(3f);
trackPointList.add(tp); trackPointList.add(tp);
@@ -51,9 +51,11 @@ import java.util.stream.Collectors;
import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.content.data.TestDataUtil;
import de.dennisguse.opentracks.content.data.TestSensorDataUtil; import de.dennisguse.opentracks.content.data.TestSensorDataUtil;
import de.dennisguse.opentracks.data.models.Altitude;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.HeartRate; import de.dennisguse.opentracks.data.models.HeartRate;
import de.dennisguse.opentracks.data.models.Marker; import de.dennisguse.opentracks.data.models.Marker;
import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
@@ -135,12 +137,16 @@ public class CustomContentProviderUtilsTest {
List<TrackPoint> trackPoints = new ArrayList<>(numPoints); List<TrackPoint> trackPoints = new ArrayList<>(numPoints);
for (int i = 0; i < numPoints; ++i) { for (int i = 0; i < numPoints; ++i) {
TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochMilli(i)) trackPoints.add(new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(37.0 + (double) i / 10000.0) new Position(
.setLongitude(57.0 - (double) i / 10000.0) Instant.ofEpochMilli(i),
.setHorizontalAccuracy(Distance.of(i / 100.0f)) 37.0 + (double) i / 10000.0,
.setAltitude(i * 2.5); 57.0 - (double) i / 10000.0,
trackPoints.add(trackPoint); Distance.of(i / 100.0f),
Altitude.WGS84.of(i * 2.5),
null,
null,
null)));
} }
contentProviderUtils.bulkInsertTrackPoint(trackPoints, id); contentProviderUtils.bulkInsertTrackPoint(trackPoints, id);
@@ -7,19 +7,34 @@ import org.junit.Test;
import java.time.Instant; import java.time.Instant;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
public class TrackPointTest { public class TrackPointTest {
@Test @Test
public void distanceToPrevious() { public void distanceToPrevious() {
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochMilli(0)) TrackPoint tp1 = new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(0) new Position(
.setLongitude(0.0001); Instant.ofEpochMilli(0),
0d,
0.0001,
null,
null,
null,
null,
null));
TrackPoint tp2 = new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochMilli(1)) TrackPoint tp2 = new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(0) new Position(
.setLongitude(0.0002); Instant.ofEpochMilli(1),
0d,
0.0002,
null,
null,
null,
null,
null));
// without sensor distance // without sensor distance
assertEquals(11.13, tp2.distanceToPrevious(tp1).toM(), 0.01); assertEquals(11.13, tp2.distanceToPrevious(tp1).toM(), 0.01);
@@ -49,11 +49,13 @@ import de.dennisguse.opentracks.TimezoneRule;
import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.content.data.TestDataUtil;
import de.dennisguse.opentracks.data.ContentProviderUtils; import de.dennisguse.opentracks.data.ContentProviderUtils;
import de.dennisguse.opentracks.data.models.ActivityType; import de.dennisguse.opentracks.data.models.ActivityType;
import de.dennisguse.opentracks.data.models.Altitude;
import de.dennisguse.opentracks.data.models.AltitudeGainLoss; import de.dennisguse.opentracks.data.models.AltitudeGainLoss;
import de.dennisguse.opentracks.data.models.Cadence; import de.dennisguse.opentracks.data.models.Cadence;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.HeartRate; import de.dennisguse.opentracks.data.models.HeartRate;
import de.dennisguse.opentracks.data.models.Marker; import de.dennisguse.opentracks.data.models.Marker;
import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.Power; import de.dennisguse.opentracks.data.models.Power;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
@@ -224,15 +226,17 @@ public class ExportImportTest {
List<TrackPoint> actual = TestDataUtil.getTrackPoints(contentProviderUtils, trackId); List<TrackPoint> actual = TestDataUtil.getTrackPoints(contentProviderUtils, trackId);
new TrackPointAssert().assertEquals(List.of( new TrackPointAssert().assertEquals(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse("2020-02-02T02:02:02Z")), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse("2020-02-02T02:02:02Z")),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:02:03Z")) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(3) new Position(
.setLongitude(14) Instant.parse("2020-02-02T02:02:03Z"),
.setAltitude(10) 3d, 14d, Distance.of(10),
.setSpeed(Speed.of(15)) Altitude.WGS84.of(10), null,
null,
Speed.of(15)))
.setAltitudeLoss(1f) .setAltitudeLoss(1f)
.setAltitudeGain(1f) .setAltitudeGain(1f),
.setHorizontalAccuracy(Distance.of(10)), new TrackPoint(TrackPoint.Type.TRACKPOINT,
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:02:04Z")) Instant.parse("2020-02-02T02:02:04Z"))
.setSensorDistance(Distance.of(10)) .setSensorDistance(Distance.of(10))
.setSpeed(Speed.of(15)) .setSpeed(Speed.of(15))
.setHeartRate(HeartRate.of(66)) .setHeartRate(HeartRate.of(66))
@@ -244,47 +248,49 @@ public class ExportImportTest {
.setHeartRate(HeartRate.of(68)) .setHeartRate(HeartRate.of(68))
.setCadence(3) .setCadence(3)
.setPower(50), .setPower(50),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:02:17Z")) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(3) new Position(
.setLongitude(14.001) Instant.parse("2020-02-02T02:02:17Z"),
.setAltitude(10) 3d, 14.001, Distance.of(10),
Altitude.WGS84.of(10), null,
null,
Speed.of(5)))
.setSensorDistance(Distance.of(2)) .setSensorDistance(Distance.of(2))
.setSpeed(Speed.of(5))
.setAltitudeLoss(0f) .setAltitudeLoss(0f)
.setAltitudeGain(0f) .setAltitudeGain(0f)
.setHorizontalAccuracy(Distance.of(10))
.setHeartRate(HeartRate.of(69)) .setHeartRate(HeartRate.of(69))
.setCadence(3) .setCadence(3)
.setPower(50), .setPower(50),
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse("2020-02-02T02:02:18Z")), new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse("2020-02-02T02:02:18Z")),
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse("2020-02-02T02:03:20Z")), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse("2020-02-02T02:03:20Z")),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:03:21Z")) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(3) new Position(
.setLongitude(14.002) Instant.parse("2020-02-02T02:03:21Z"),
.setAltitude(10) 3d, 14.002d, Distance.of(10),
.setSpeed(Speed.of(15)) Altitude.WGS84.of(10), null,
null,
Speed.of(15)))
.setAltitudeLoss(0f) .setAltitudeLoss(0f)
.setAltitudeGain(0f) .setAltitudeGain(0f),
.setHorizontalAccuracy(Distance.of(10)), new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC,
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2020-02-02T02:03:22Z")) new Position(Instant.parse("2020-02-02T02:03:22Z"),
.setLatitude(3) 3d, 16d, Distance.of(10),
.setLongitude(16) Altitude.WGS84.of(10), null,
.setAltitude(10) null,
.setSpeed(Speed.of(15)) Speed.of(15)))
.setAltitudeLoss(0f) .setAltitudeLoss(0f)
.setAltitudeGain(0f) .setAltitudeGain(0f),
.setHorizontalAccuracy(Distance.of(10)),
new TrackPoint(TrackPoint.Type.IDLE, Instant.parse("2020-02-02T02:03:30Z")) new TrackPoint(TrackPoint.Type.IDLE, Instant.parse("2020-02-02T02:03:30Z"))
.setAltitudeLoss(0f) .setAltitudeLoss(0f)
.setAltitudeGain(0f), .setAltitudeGain(0f),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:03:50Z")) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(3) new Position(
.setLongitude(16.001) Instant.parse("2020-02-02T02:03:50Z"),
.setAltitude(10) 3d, 16.001, Distance.of(10),
.setSpeed(Speed.of(15)) Altitude.WGS84.of(10), null,
null, Speed.of(15)))
.setAltitudeLoss(0f) .setAltitudeLoss(0f)
.setAltitudeGain(0f) .setAltitudeGain(0f),
.setHorizontalAccuracy(Distance.of(10)),
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse("2020-02-02T02:04:00Z")) new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse("2020-02-02T02:04:00Z"))
), actual); ), actual);
} }
@@ -397,50 +403,56 @@ public class ExportImportTest {
.setDelta(0.05); // speed is not fully .setDelta(0.05); // speed is not fully
List<TrackPoint> actual = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId); List<TrackPoint> actual = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId);
a.assertEquals(List.of( a.assertEquals(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2020-02-02T02:02:03Z")) new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC,
.setLatitude(3) new Position(
.setLongitude(14) Instant.parse("2020-02-02T02:02:03Z"),
.setAltitude(10) 3d, 14d, Distance.of(10),
.setSpeed(Speed.of(15)) Altitude.WGS84.of(10), null,
null,
Speed.of(15)))
.setAltitudeLoss(1f) .setAltitudeLoss(1f)
.setAltitudeGain(1f) .setAltitudeGain(1f),
.setHorizontalAccuracy(Distance.of(10)), new TrackPoint(TrackPoint.Type.TRACKPOINT,
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:02:17Z")) new Position(
.setLatitude(3) Instant.parse("2020-02-02T02:02:17Z"),
.setLongitude(14.001) 3d, 14.001, Distance.of(10),
.setAltitude(10) Altitude.WGS84.of(10), null,
.setSpeed(Speed.of(5)) null,
Speed.of(5)))
.setAltitudeLoss(1f) .setAltitudeLoss(1f)
.setAltitudeGain(1f) .setAltitudeGain(1f)
.setSensorDistance(Distance.of(12)) .setSensorDistance(Distance.of(12))
.setHeartRate(69) .setHeartRate(69)
.setPower(50f) .setPower(50f)
.setCadence(3f) .setCadence(3f),
.setHorizontalAccuracy(Distance.of(10)), new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC,
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2020-02-02T02:03:21Z")) new Position(
.setLatitude(3) Instant.parse("2020-02-02T02:03:21Z"),
.setLongitude(14.002) 3d, 14.002, Distance.of(10),
.setAltitude(10) Altitude.WGS84.of(10), null,
null,
Speed.of(15)))
.setAltitudeLoss(0f)
.setAltitudeGain(0f),
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC,
new Position(
Instant.parse("2020-02-02T02:03:22Z"),
3d, 16d, Distance.of(10),
Altitude.WGS84.of(10), null,
null,
Speed.of(15)))
.setAltitudeLoss(0f)
.setAltitudeGain(0f),
new TrackPoint(TrackPoint.Type.TRACKPOINT,
new Position(
Instant.parse("2020-02-02T02:03:50Z"),
3d, 16.001, Distance.of(10),
Altitude.WGS84.of(10), null,
null,
Speed.of(10)))
.setAltitudeLoss(0f) .setAltitudeLoss(0f)
.setAltitudeGain(0f) .setAltitudeGain(0f)
.setSpeed(Speed.of(15)) .setSpeed(Speed.of(15))
.setHorizontalAccuracy(Distance.of(10)),
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2020-02-02T02:03:22Z"))
.setLatitude(3)
.setLongitude(16)
.setAltitude(10)
.setAltitudeLoss(0f)
.setAltitudeGain(0f)
.setSpeed(Speed.of(15))
.setHorizontalAccuracy(Distance.of(10)),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:03:50Z"))
.setLatitude(3)
.setLongitude(16.001)
.setAltitude(10)
.setAltitudeLoss(0f)
.setAltitudeGain(0f)
.setSpeed(Speed.of(15))
.setHorizontalAccuracy(Distance.of(10))
), actual); ), actual);
// 3. trackstatistics // 3. trackstatistics
@@ -597,7 +609,7 @@ public class ExportImportTest {
Mockito.when(barometer.hasReceivedData()).thenReturn(true); Mockito.when(barometer.hasReceivedData()).thenReturn(true);
Mockito.when(barometer.getAggregatedValue(Mockito.any())).thenReturn(new AltitudeGainLoss(altitudeGain, altitudeGain)); Mockito.when(barometer.getAggregatedValue(Mockito.any())).thenReturn(new AltitudeGainLoss(altitudeGain, altitudeGain));
sensorDataSet.add(barometer); sensorDataSet.add(barometer);
} else { } else {
sensorDataSet.add(new AggregatorBarometer("test", null)); sensorDataSet.add(new AggregatorBarometer("test", null));
} }
} }
@@ -15,21 +15,20 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.content.data.TestDataUtil;
import de.dennisguse.opentracks.data.ContentProviderUtils; import de.dennisguse.opentracks.data.ContentProviderUtils;
import de.dennisguse.opentracks.data.models.ActivityType; import de.dennisguse.opentracks.data.models.ActivityType;
import de.dennisguse.opentracks.data.models.Altitude;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
@@ -95,28 +94,37 @@ public class GPXTrackImporterTest {
// first segment // first segment
TrackPointAssert a = new TrackPointAssert(); TrackPointAssert a = new TrackPointAssert();
a.assertEquals(List.of( a.assertEquals(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2021-01-07T21:51:59.179Z")) new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC,
.setLatitude(3) new Position(
.setLongitude(14) Instant.parse("2021-01-07T21:51:59.179Z"),
.setAltitude(10), 3d, 14d, null,
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-01-07T21:52:00.653Z")) Altitude.WGS84.of(10), null,
.setLatitude(3) null,
.setLongitude(14.001) null)),
.setAltitude(10) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setSpeed(Speed.of(75.4192)), new Position(
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-01-07T21:52:01.010Z")) Instant.parse("2021-01-07T21:52:00.653Z"),
.setLatitude(3) 3d, 14.001, null,
.setLongitude(14.002) Altitude.WGS84.of(10), null,
.setAltitude(10) null,
.setSpeed(Speed.of(311.3948)), Speed.of(75.4192))),
new TrackPoint(TrackPoint.Type.TRACKPOINT,
new Position(
Instant.parse("2021-01-07T21:52:01.010Z"),
3d, 14.002, null,
Altitude.WGS84.of(10), null,
null, Speed.of(311.3948))),
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse("2021-01-07T21:52:02.658Z")), new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse("2021-01-07T21:52:02.658Z")),
// created resume trackpoint with time of next valid trackpoint // created resume trackpoint with time of next valid trackpoint
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse("2021-01-07T21:52:03.873Z")), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse("2021-01-07T21:52:03.873Z")),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-01-07T21:52:04.103Z")) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(3) new Position(
.setLongitude(14.003) Instant.parse("2021-01-07T21:52:04.103Z"),
.setAltitude(10) 3d, 14.003, null,
Altitude.WGS84.of(10), null,
null,
null))
), importedTrackPoints); ), importedTrackPoints);
} }
@@ -151,20 +159,27 @@ public class GPXTrackImporterTest {
TrackPointAssert a = new TrackPointAssert(); TrackPointAssert a = new TrackPointAssert();
a.assertEquals(List.of( a.assertEquals(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2021-09-07T22:10:19Z")) new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC,
.setLatitude(30.14185982) new Position(
.setLongitude(-40.3863038) Instant.parse("2021-09-07T22:10:19Z"),
.setAltitude(-5), 30.14185982, -40.3863038, null,
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-09-07T22:11:07Z")) Altitude.WGS84.of(-5), null,
.setLatitude(30.14184657) null,
.setLongitude(-40.38670089) null)),
.setAltitude(-5) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setSpeed(Speed.of(0.7976524233818054)), new Position(
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-09-07T22:12:00Z")) Instant.parse("2021-09-07T22:11:07Z"),
.setLatitude(30.14185982) 30.14184657, -40.38670089, null,
.setLongitude(-40.3863038) Altitude.WGS84.of(-5), null,
.setAltitude(-5) null,
.setSpeed(Speed.of(0.7224021553993225)) Speed.of(0.7976524233818054))),
new TrackPoint(TrackPoint.Type.TRACKPOINT,
new Position(
Instant.parse("2021-09-07T22:12:00Z"),
30.14185982, -40.3863038, null,
Altitude.WGS84.of(-5), null,
null,
Speed.of(0.7224021553993225)))
), importedTrackPoints); ), importedTrackPoints);
} }
@@ -199,22 +214,27 @@ public class GPXTrackImporterTest {
TrackPointAssert a = new TrackPointAssert(); TrackPointAssert a = new TrackPointAssert();
a.assertEquals(List.of( a.assertEquals(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2021-09-07T22:10:19Z")) new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC,
.setLatitude(30.14185982) new Position(
.setLongitude(-40.3863038) Instant.parse("2021-09-07T22:10:19Z"),
.setAltitude(-5) 30.14185982, -40.3863038, null,
.setSpeed(Speed.of(5)), Altitude.WGS84.of(-5), null,
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-09-07T22:11:07Z")) null,
.setLatitude(30.14184657) Speed.of(5))),
.setLongitude(-40.38670089) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setAltitude(-5) new Position(
.setSpeed(Speed.of(0.7976524233818054)) Instant.parse("2021-09-07T22:11:07Z"),
.setSpeed(Speed.of(4)), 30.14184657, -40.38670089, null,
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-09-07T22:12:00Z")) Altitude.WGS84.of(-5), null,
.setLatitude(30.14185982) null,
.setLongitude(-40.3863038) Speed.of(4))),
.setAltitude(-5) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setSpeed(Speed.of(3)) new Position(
Instant.parse("2021-09-07T22:12:00Z"),
30.14185982, -40.3863038, null,
Altitude.WGS84.of(-5), null,
null,
Speed.of(3)))
), importedTrackPoints); ), importedTrackPoints);
} }
@@ -237,11 +257,6 @@ public class GPXTrackImporterTest {
trackExporter.writeTrack(List.of(importedTrack), outputStream); trackExporter.writeTrack(List.of(importedTrack), outputStream);
// then // then
String expected = new BufferedReader( assertEquals(new String(inputStreamExpected.readAllBytes(), StandardCharsets.UTF_8), outputStream.toString());
new InputStreamReader(inputStreamExpected, StandardCharsets.UTF_8))
.lines()
.collect(Collectors.joining("\n")) + "\n";
assertEquals(expected, outputStream.toString()); //TODO inputStream.readAllBytes() ?
} }
} }
@@ -23,7 +23,9 @@ import java.util.List;
import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.content.data.TestDataUtil;
import de.dennisguse.opentracks.data.ContentProviderUtils; import de.dennisguse.opentracks.data.ContentProviderUtils;
import de.dennisguse.opentracks.data.models.ActivityType; import de.dennisguse.opentracks.data.models.ActivityType;
import de.dennisguse.opentracks.data.models.Altitude;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
@@ -81,23 +83,30 @@ public class KMLTrackImporterTest {
// 3. trackpoints // 3. trackpoints
List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId); List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId);
TrackPointAssert a = new TrackPointAssert(); new TrackPointAssert().assertEquals(List.of(
a.assertEquals(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse("2021-05-29T18:06:21.767Z")), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse("2021-05-29T18:06:21.767Z")),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-05-29T18:06:22.042Z")) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(3) new Position(
.setLongitude(14) Instant.parse("2021-05-29T18:06:22.042Z"),
.setAltitude(10), 3d, 14d, null,
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-05-29T18:06:22.192Z")) Altitude.WGS84.of(10), null,
.setLatitude(3) null,
.setLongitude(14.001) null)),
.setAltitude(10) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setSpeed(Speed.of(741.1196)), new Position(
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-05-29T18:06:22.318Z")) Instant.parse("2021-05-29T18:06:22.192Z"),
.setLatitude(3) 3d, 14.001, null,
.setLongitude(14.002) Altitude.WGS84.of(10), null,
.setAltitude(10) null,
.setSpeed(Speed.of(882.2853)), Speed.of(741.1196)
)),
new TrackPoint(TrackPoint.Type.TRACKPOINT,
new Position(
Instant.parse("2021-05-29T18:06:22.318Z"),
3d, 14.002, null,
Altitude.WGS84.of(10), null,
null,
Speed.of(882.2853))),
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse("2021-05-29T18:06:22.512Z")) new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse("2021-05-29T18:06:22.512Z"))
), importedTrackPoints); ), importedTrackPoints);
} }
@@ -131,12 +140,13 @@ public class KMLTrackImporterTest {
// 3. trackpoints // 3. trackpoints
List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId); List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId);
TrackPointAssert a = new TrackPointAssert(); new TrackPointAssert().assertEquals(List.of(
a.assertEquals(List.of( new TrackPoint(TrackPoint.Type.TRACKPOINT,
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-05-29T18:06:21.767Z")) new Position(Instant.parse("2021-05-29T18:06:21.767Z"),
.setLatitude(3) 3d, 14d, null,
.setLongitude(14) Altitude.WGS84.of(10), null,
.setAltitude(10), null,
null)),
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse("2021-05-29T18:06:22.042Z")) new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse("2021-05-29T18:06:22.042Z"))
), importedTrackPoints); ), importedTrackPoints);
} }
@@ -171,47 +181,57 @@ public class KMLTrackImporterTest {
// 3. trackpoints // 3. trackpoints
List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId); List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId);
TrackPointAssert a = new TrackPointAssert(); new TrackPointAssert().assertEquals(List.of(
a.assertEquals(List.of(
// first 3 trackpoints // first 3 trackpoints
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2020-11-28T17:06:22.401Z")) new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC,
.setLatitude(12.340097) new Position(
.setLongitude(1.234156) Instant.parse("2020-11-28T17:06:22.401Z"),
.setAltitude(469.286376953125) 12.340097, 1.234156, null,
.setAltitudeGain(0f) Altitude.WGS84.of(469.286376953125), null,
.setSpeed(Speed.of(0.539)), null,
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-11-28T17:06:25.448Z")) Speed.of(0.539)))
.setLatitude(12.340036) .setAltitudeGain(0f),
.setLongitude(1.23415) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setAltitude(439.1626281738281) new Position(
.setAltitudeGain(0f) Instant.parse("2020-11-28T17:06:25.448Z"),
.setSpeed(Speed.of(0.1577)), 12.340036, 1.23415, null,
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-11-28T17:06:47.888Z")) Altitude.WGS84.of(439.1626281738281), null,
.setLatitude(12.340057) null,
.setLongitude(1.23405) Speed.of(0.1577)))
.setAltitude(421.8070983886719) .setAltitudeGain(0f),
.setAltitudeGain(0f) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setSpeed(Speed.of(0)), new Position(
Instant.parse("2020-11-28T17:06:47.888Z"),
12.340057, 1.23405, null,
Altitude.WGS84.of(421.8070983886719), null,
null,
Speed.of(0)))
.setAltitudeGain(0f),
// created resume trackpoint with time of next valid trackpoint // created resume trackpoint with time of next valid trackpoint
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2020-11-28T17:06:55.861Z")) new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC,
.setLatitude(12.340057) new Position(
.setLongitude(1.23405) Instant.parse("2020-11-28T17:06:55.861Z"),
.setAltitude(419.93902587890625) 12.340057, 1.23405, null,
Altitude.WGS84.of(419.93902587890625), null,
null,
Speed.of(0)))
.setAltitudeGain(0f),
new TrackPoint(TrackPoint.Type.TRACKPOINT,
new Position(
Instant.parse("2020-11-28T17:06:56.905Z"),
12.340057, 1.23405, null,
Altitude.WGS84.of(419.9036560058594), null,
null,
Speed.of(0)))
.setAltitudeGain(0f),
new TrackPoint(TrackPoint.Type.TRACKPOINT,
new Position(
Instant.parse("2020-11-28T17:07:20.870Z"),
12.340082, 1.234046, null,
Altitude.WGS84.of(417.99432373046875), null,
null,
Speed.of(0)))
.setAltitudeGain(0f) .setAltitudeGain(0f)
.setSpeed(Speed.of(0)),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-11-28T17:06:56.905Z"))
.setLatitude(12.340057)
.setLongitude(1.23405)
.setAltitude(419.9036560058594)
.setAltitudeGain(0f)
.setSpeed(Speed.of(0)),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-11-28T17:07:20.870Z"))
.setLatitude(12.340082)
.setLongitude(1.234046)
.setAltitude(417.99432373046875)
.setAltitudeGain(0f)
.setSpeed(Speed.of(0))
), importedTrackPoints); ), importedTrackPoints);
} }
@@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@@ -44,6 +45,7 @@ public class GpsStatusTest {
private final static Location ok = new Location("gps"); private final static Location ok = new Location("gps");
static { static {
badFix.setAccuracy(50); badFix.setAccuracy(50);
ok.setAccuracy(10); ok.setAccuracy(10);
@@ -80,16 +82,16 @@ public class GpsStatusTest {
// when / then // when / then
subject.start(); subject.start();
subject.onNewTrackPoint(new TrackPoint(badFix, Instant.now())); subject.onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(badFix, Instant.now())));
assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_BAD), statusList); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_BAD), statusList);
subject.onNewTrackPoint(new TrackPoint(ok, Instant.now())); subject.onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(ok, Instant.now())));
assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_BAD, GPS_SIGNAL_FIX), statusList); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_BAD, GPS_SIGNAL_FIX), statusList);
subject.onNewTrackPoint(new TrackPoint(ok, Instant.now())); subject.onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(ok, Instant.now())));
assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_BAD, GPS_SIGNAL_FIX), statusList); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_BAD, GPS_SIGNAL_FIX), statusList);
subject.onNewTrackPoint(new TrackPoint(badFix, Instant.now())); subject.onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(badFix, Instant.now())));
assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_BAD, GPS_SIGNAL_FIX, GPS_SIGNAL_BAD), statusList); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_BAD, GPS_SIGNAL_FIX, GPS_SIGNAL_BAD), statusList);
} }
@@ -104,13 +106,13 @@ public class GpsStatusTest {
// when / then // when / then
subject.start(); subject.start();
subject.onNewTrackPoint(new TrackPoint(ok, Instant.now().minusMillis(1000))); subject.onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(ok, Instant.now().minusMillis(1000))));
assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX), statusList); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX), statusList);
subject.determineGpsStatusByTime(Instant.now()); subject.determineGpsStatusByTime(Instant.now());
assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX, GPS_SIGNAL_LOST), statusList); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX, GPS_SIGNAL_LOST), statusList);
subject.onNewTrackPoint(new TrackPoint(ok, Instant.now())); subject.onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(ok, Instant.now())));
assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX, GPS_SIGNAL_LOST, GPS_SIGNAL_FIX), statusList); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX, GPS_SIGNAL_LOST, GPS_SIGNAL_FIX), statusList);
} }
@@ -131,13 +133,13 @@ public class GpsStatusTest {
Thread.sleep(100); Thread.sleep(100);
assertEquals(List.of(GPS_ENABLED), statusList); assertEquals(List.of(GPS_ENABLED), statusList);
subject.onNewTrackPoint(new TrackPoint(ok, Instant.now())); subject.onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(ok, Instant.now())));
assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX), statusList); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX), statusList);
Thread.sleep(100); Thread.sleep(100);
assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX, GPS_SIGNAL_LOST), statusList); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX, GPS_SIGNAL_LOST), statusList);
subject.onNewTrackPoint(new TrackPoint(badFix, Instant.now())); subject.onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(badFix, Instant.now())));
assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX, GPS_SIGNAL_LOST, GPS_SIGNAL_BAD), statusList); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX, GPS_SIGNAL_LOST, GPS_SIGNAL_BAD), statusList);
Thread.sleep(100); Thread.sleep(100);
@@ -19,7 +19,6 @@ import org.junit.BeforeClass;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mockito;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
@@ -34,6 +33,7 @@ import de.dennisguse.opentracks.data.ContentProviderUtils;
import de.dennisguse.opentracks.data.models.AltitudeGainLoss; import de.dennisguse.opentracks.data.models.AltitudeGainLoss;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.HeartRate; import de.dennisguse.opentracks.data.models.HeartRate;
import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
@@ -95,11 +95,9 @@ public class TrackRecordingServiceRecordingTest {
@MediumTest @MediumTest
@Test @Test
public void recording_startStop() { public void recording_startStop() {
// given // given
TrackPointCreator trackPointCreator = service.getTrackPointCreator(); TrackPointCreator trackPointCreator = service.getTrackPointCreator();
// when // when
String startTime = "2020-02-02T02:02:02Z"; String startTime = "2020-02-02T02:02:02Z";
trackPointCreator.setClock(startTime); trackPointCreator.setClock(startTime);
@@ -140,7 +138,6 @@ public class TrackRecordingServiceRecordingTest {
@MediumTest @MediumTest
@Test @Test
public void recording_startIdle() throws InterruptedException { public void recording_startIdle() throws InterruptedException {
// given // given
TrackPointCreator trackPointCreator = service.getTrackPointCreator(); TrackPointCreator trackPointCreator = service.getTrackPointCreator();
String startTime = "2020-02-02T02:02:02Z"; String startTime = "2020-02-02T02:02:02Z";
@@ -159,16 +156,20 @@ public class TrackRecordingServiceRecordingTest {
// then // then
new TrackPointAssert().assertEquals(List.of( new TrackPointAssert().assertEquals(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps1)) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(45) new Position(
.setLongitude(35) Instant.parse(gps1),
.setHorizontalAccuracy(Distance.of(1)) 45d, 35d, Distance.of(1),
.setSpeed(Speed.of(15)), null, null,
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps2)) null,
.setLatitude(45) Speed.of(15))),
.setLongitude(35) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setHorizontalAccuracy(Distance.of(1)) new Position(
.setSpeed(Speed.of(15)), Instant.parse(gps2),
45d, 35d, Distance.of(1),
null, null,
null,
Speed.of(15))),
new TrackPoint(TrackPoint.Type.IDLE, Instant.parse(idleTime)) new TrackPoint(TrackPoint.Type.IDLE, Instant.parse(idleTime))
), TestDataUtil.getTrackPoints(contentProviderUtils, trackId)); ), TestDataUtil.getTrackPoints(contentProviderUtils, trackId));
} }
@@ -244,8 +245,7 @@ public class TrackRecordingServiceRecordingTest {
assertFalse(service.isRecording()); assertFalse(service.isRecording());
List<TrackPoint> trackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, trackId); List<TrackPoint> trackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, trackId);
TrackPointAssert a = new TrackPointAssert(); new TrackPointAssert().assertEquals(List.of(
a.assertEquals(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(starTime)), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(starTime)),
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(pauseTime)) new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(pauseTime))
.setAltitudeGain(0f) .setAltitudeGain(0f)
@@ -264,7 +264,6 @@ public class TrackRecordingServiceRecordingTest {
Track.Id trackId = service.startNewTrack(); Track.Id trackId = service.startNewTrack();
mockAltitudeChange(trackPointCreator, 0); mockAltitudeChange(trackPointCreator, 0);
String stopTime = "2020-02-02T02:02:03Z"; String stopTime = "2020-02-02T02:02:03Z";
trackPointCreator.setClock(stopTime); trackPointCreator.setClock(stopTime);
service.endCurrentTrack(); service.endCurrentTrack();
@@ -275,7 +274,6 @@ public class TrackRecordingServiceRecordingTest {
service.resumeTrack(trackId); service.resumeTrack(trackId);
mockAltitudeChange(trackPointCreator, 0); mockAltitudeChange(trackPointCreator, 0);
// then // then
new TrackPointAssert().assertEquals(List.of( new TrackPointAssert().assertEquals(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)),
@@ -374,25 +372,31 @@ public class TrackRecordingServiceRecordingTest {
new TrackPointAssert().assertEquals(List.of( new TrackPointAssert().assertEquals(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps1)) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(45) new Position(
.setLongitude(35) Instant.parse(gps1),
.setHorizontalAccuracy(Distance.of(1)) 45d, 35d, Distance.of(1),
.setSpeed(Speed.of(15)) null, null,
null,
Speed.of(15)))
.setAltitudeGain(0f) .setAltitudeGain(0f)
.setAltitudeLoss(0f), .setAltitudeLoss(0f),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps2)) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(45.0001) new Position(
.setLongitude(35) Instant.parse(gps2),
.setHorizontalAccuracy(Distance.of(1)) 45.001, 35d, Distance.of(1),
.setSpeed(Speed.of(15)) null, null,
null,
Speed.of(15)))
.setAltitudeGain(0f) .setAltitudeGain(0f)
.setAltitudeLoss(0f), .setAltitudeLoss(0f),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps3)) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(45.0001) new Position(
.setLongitude(35) Instant.parse(gps3),
.setHorizontalAccuracy(Distance.of(1)) 45.001, 35d, Distance.of(1),
.setSpeed(Speed.of(15)) null, null,
null,
Speed.of(15)))
.setAltitudeGain(0f) .setAltitudeGain(0f)
.setAltitudeLoss(0f), .setAltitudeLoss(0f),
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime)) new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime))
@@ -411,7 +415,6 @@ public class TrackRecordingServiceRecordingTest {
Track.Id trackId = service.startNewTrack(); Track.Id trackId = service.startNewTrack();
mockAltitudeChange(trackPointCreator, 0); mockAltitudeChange(trackPointCreator, 0);
// when // when
String gps1 = "2020-02-02T02:02:03Z"; String gps1 = "2020-02-02T02:02:03Z";
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 1, 15); TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 1, 15);
@@ -434,7 +437,6 @@ public class TrackRecordingServiceRecordingTest {
// then // then
assertEquals(gps1Statistics, contentProviderUtils.getTrack(trackId).getTrackStatistics()); assertEquals(gps1Statistics, contentProviderUtils.getTrack(trackId).getTrackStatistics());
// when // when
String stopTime = "2020-02-02T02:02:12Z"; String stopTime = "2020-02-02T02:02:12Z";
trackPointCreator.setClock(stopTime); trackPointCreator.setClock(stopTime);
@@ -446,25 +448,31 @@ public class TrackRecordingServiceRecordingTest {
new TrackPointAssert().assertEquals(List.of( new TrackPointAssert().assertEquals(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps1)) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(45) new Position(
.setLongitude(35) Instant.parse(gps1),
.setHorizontalAccuracy(Distance.of(1)) 45d, 35d, Distance.of(1),
.setSpeed(Speed.of(15)) null, null,
null,
Speed.of(15)))
.setAltitudeGain(0f) .setAltitudeGain(0f)
.setAltitudeLoss(0f), .setAltitudeLoss(0f),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps3)) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(45.00002) new Position(
.setLongitude(35) Instant.parse(gps3),
.setHorizontalAccuracy(Distance.of(1)) 45.00002, 35d, Distance.of(1),
.setSpeed(Speed.of(15)) null, null,
null,
Speed.of(15)))
.setAltitudeGain(0f) .setAltitudeGain(0f)
.setAltitudeLoss(0f), .setAltitudeLoss(0f),
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime)) new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL,
.setLatitude(45.00002) new Position(
.setLongitude(35) Instant.parse(stopTime),
.setHorizontalAccuracy(Distance.of(1)) 45.00002, 35d, Distance.of(1),
.setSpeed(Speed.of(15)) null, null,
null,
Speed.of(15)))
.setAltitudeGain(0f) .setAltitudeGain(0f)
.setAltitudeLoss(0f) .setAltitudeLoss(0f)
), TestDataUtil.getTrackPoints(contentProviderUtils, trackId)); ), TestDataUtil.getTrackPoints(contentProviderUtils, trackId));
@@ -501,20 +509,24 @@ public class TrackRecordingServiceRecordingTest {
// then // then
new TrackPointAssert().assertEquals(List.of( new TrackPointAssert().assertEquals(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps1)) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(45) new Position(
.setLongitude(35) Instant.parse(gps1),
.setHorizontalAccuracy(Distance.of(1)) 45d, 35d, Distance.of(1),
null, null,
null,
Speed.of(15)))
.setAltitudeGain(0f) .setAltitudeGain(0f)
.setAltitudeLoss(0f) .setAltitudeLoss(0f),
.setSpeed(Speed.of(15)), new TrackPoint(TrackPoint.Type.TRACKPOINT,
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps3)) new Position(
.setLatitude(45) Instant.parse(gps3),
.setLongitude(35) 45d, 35d, Distance.of(1),
.setHorizontalAccuracy(Distance.of(1)) null, null,
null,
Speed.of(15)))
.setAltitudeGain(0f) .setAltitudeGain(0f)
.setAltitudeLoss(0f) .setAltitudeLoss(0f),
.setSpeed(Speed.of(15)),
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime)) new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime))
.setAltitudeGain(0f) .setAltitudeGain(0f)
.setAltitudeLoss(0f) .setAltitudeLoss(0f)
@@ -531,7 +543,6 @@ public class TrackRecordingServiceRecordingTest {
Track.Id trackId = service.startNewTrack(); Track.Id trackId = service.startNewTrack();
mockAltitudeChange(trackPointCreator, 0); mockAltitudeChange(trackPointCreator, 0);
// when // when
String gps1 = "2020-02-02T02:02:03Z"; String gps1 = "2020-02-02T02:02:03Z";
TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 100, 15); TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 100, 15);
@@ -605,18 +616,22 @@ public class TrackRecordingServiceRecordingTest {
// then // then
new TrackPointAssert().assertEquals(List.of( new TrackPointAssert().assertEquals(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps1)) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(45) new Position(
.setLongitude(35) Instant.parse(gps1),
.setHorizontalAccuracy(Distance.of(1)) 45d, 35d, Distance.of(1),
.setSpeed(Speed.of(15)) null, null,
null,
Speed.of(15)))
.setAltitudeGain(0f) .setAltitudeGain(0f)
.setAltitudeLoss(0f), .setAltitudeLoss(0f),
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse(gps2)) new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC,
.setLatitude(45.1) new Position(
.setLongitude(35) Instant.parse(gps2),
.setHorizontalAccuracy(Distance.of(1)) 45.1, 35d, Distance.of(1),
.setSpeed(Speed.of(15)) null, null,
null,
Speed.of(15)))
.setAltitudeGain(0f) .setAltitudeGain(0f)
.setAltitudeLoss(0f), .setAltitudeLoss(0f),
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime)) new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime))
@@ -695,42 +710,55 @@ public class TrackRecordingServiceRecordingTest {
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(sensor2)) //First moving TrackPoint: store as the time might be interesting. new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(sensor2)) //First moving TrackPoint: store as the time might be interesting.
.setSpeed(Speed.of(5)) .setSpeed(Speed.of(5))
.setSensorDistance(Distance.of(2)), .setSensorDistance(Distance.of(2)),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps1)) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(45) new Position(
.setLongitude(35) Instant.parse(gps1),
.setHorizontalAccuracy(Distance.of(1)) 45d, 35d, Distance.of(1),
.setSpeed(Speed.of(5)) null, null,
null,
Speed.of(5)))
.setSensorDistance(Distance.of(0)), .setSensorDistance(Distance.of(0)),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(sensor3)) new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(sensor3))
.setSpeed(Speed.of(5)) .setSpeed(Speed.of(5))
.setSensorDistance(Distance.of(10)), .setSensorDistance(Distance.of(10)),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps3)) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(45.001) new Position(
.setLongitude(35) Instant.parse(gps3),
.setHorizontalAccuracy(Distance.of(1)) 45.001, 35d, Distance.of(1),
.setSpeed(Speed.of(5)) null, null,
null,
Speed.of(5)))
.setSensorDistance(Distance.of(4.0)), .setSensorDistance(Distance.of(4.0)),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps4)) new TrackPoint(TrackPoint.Type.TRACKPOINT,
.setLatitude(45.001) new Position(
.setLongitude(35) Instant.parse(gps4),
.setHorizontalAccuracy(Distance.of(1)) 45.001, 35d, Distance.of(1),
.setSpeed(Speed.of(5)) null, null,
null,
Speed.of(5)))
.setSensorDistance(Distance.of(0)), .setSensorDistance(Distance.of(0)),
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime)) new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL,
.setLatitude(45.001) new Position(
.setLongitude(35) Instant.parse(stopTime),
.setHorizontalAccuracy(Distance.of(1)) 45.001, 35d, Distance.of(1),
.setSensorDistance(Distance.of(11)) null, null,
.setSpeed(Speed.of(0)) //Sensor data is now outdated, but we do not fall back to GPS. null,
Speed.of(0))) //Sensor data is now outdated, but we do not fall back to GPS.
.setSensorDistance(Distance.of(0)) .setSensorDistance(Distance.of(0))
), TestDataUtil.getTrackPoints(contentProviderUtils, trackId)); ), TestDataUtil.getTrackPoints(contentProviderUtils, trackId));
} }
private void mockAltitudeChange(TrackPointCreator trackPointCreator, float altitudeGain) { private void mockAltitudeChange(TrackPointCreator trackPointCreator, float altitudeGain) {
AggregatorBarometer barometer = Mockito.mock(AggregatorBarometer.class); trackPointCreator.getSensorManager().sensorDataSet.barometer = new AggregatorBarometer("", "") {
Mockito.when(barometer.hasReceivedData()).thenReturn(true); @Override
Mockito.when(barometer.getAggregatedValue(Mockito.any())).thenReturn(new AltitudeGainLoss(altitudeGain, altitudeGain)); public boolean hasReceivedData() {
return true;
}
trackPointCreator.getSensorManager().sensorDataSet.barometer = barometer; @Override
public AltitudeGainLoss getAggregatedValue(Instant now) {
return new AltitudeGainLoss(altitudeGain, altitudeGain);
}
};
} }
} }
@@ -17,6 +17,7 @@ import java.util.List;
import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.content.data.TestDataUtil;
import de.dennisguse.opentracks.data.models.Altitude; import de.dennisguse.opentracks.data.models.Altitude;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
@@ -104,8 +105,8 @@ public class TrackStatisticsUpdaterTest {
TrackStatisticsUpdater subject = new TrackStatisticsUpdater(); TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000)); TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000));
TrackPoint tp2 = new TrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000)); TrackPoint tp2 = createTrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000));
TrackPoint tp3 = new TrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000)); TrackPoint tp3 = createTrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000));
tp3.setSpeed(Speed.of(5f)); tp3.setSpeed(Speed.of(5f));
// when // when
@@ -123,11 +124,11 @@ public class TrackStatisticsUpdaterTest {
TrackStatisticsUpdater subject = new TrackStatisticsUpdater(); TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000)); TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000));
TrackPoint tp2 = new TrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000)); TrackPoint tp2 = createTrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000));
tp2.setSpeed(Speed.of(5f)); tp2.setSpeed(Speed.of(5f));
TrackPoint tp3 = new TrackPoint(0.001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000)); TrackPoint tp3 = createTrackPoint(0.001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000));
tp3.setSpeed(Speed.of(5f)); tp3.setSpeed(Speed.of(5f));
TrackPoint tp4 = new TrackPoint(0.001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(4000)); TrackPoint tp4 = createTrackPoint(0.001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(4000));
tp4.setSpeed(Speed.of(5f)); tp4.setSpeed(Speed.of(5f));
tp4.setSensorDistance(Distance.of(5f)); tp4.setSensorDistance(Distance.of(5f));
TrackPoint tp5 = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochMilli(5000)); TrackPoint tp5 = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochMilli(5000));
@@ -155,12 +156,12 @@ public class TrackStatisticsUpdaterTest {
TrackStatisticsUpdater subject = new TrackStatisticsUpdater(); TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000)); TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000));
TrackPoint tp2 = new TrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000)); TrackPoint tp2 = createTrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000));
tp2.setSpeed(Speed.of(5f)); tp2.setSpeed(Speed.of(5f));
TrackPoint tp3 = new TrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000)); TrackPoint tp3 = createTrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000));
tp3.setSensorDistance(Distance.of(5f)); tp3.setSensorDistance(Distance.of(5f));
tp3.setSpeed(Speed.of(5f)); tp3.setSpeed(Speed.of(5f));
TrackPoint tp4 = new TrackPoint(0.0005, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(4000)); TrackPoint tp4 = createTrackPoint(0.0005, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(4000));
tp4.setSpeed(Speed.of(5f)); tp4.setSpeed(Speed.of(5f));
TrackPoint tp5 = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochMilli(5000)); TrackPoint tp5 = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochMilli(5000));
@@ -187,9 +188,9 @@ public class TrackStatisticsUpdaterTest {
subject.addTrackPoints(List.of( subject.addTrackPoints(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)),
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1)) createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1))
.setSpeed(Speed.of(2f)), .setSpeed(Speed.of(2f)),
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(2)) createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(2))
.setSpeed(Speed.of(2f)), .setSpeed(Speed.of(2f)),
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(4)) new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(4))
)); ));
@@ -198,9 +199,9 @@ public class TrackStatisticsUpdaterTest {
// when // when
subject.addTrackPoints(List.of( subject.addTrackPoints(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(5)), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(5)),
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(6)) createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(6))
.setSpeed(Speed.of(1f)), .setSpeed(Speed.of(1f)),
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(7)) createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(7))
.setSpeed(Speed.of(1f)), .setSpeed(Speed.of(1f)),
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(8)) new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(8))
)); ));
@@ -216,9 +217,9 @@ public class TrackStatisticsUpdaterTest {
// when // when
subject.addTrackPoints(List.of( subject.addTrackPoints(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)),
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1)) createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1))
.setSpeed(Speed.of(2f)), .setSpeed(Speed.of(2f)),
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(2)) createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(2))
.setSpeed(Speed.of(2f)), .setSpeed(Speed.of(2f)),
new TrackPoint(TrackPoint.Type.IDLE, Instant.ofEpochSecond(30)), new TrackPoint(TrackPoint.Type.IDLE, Instant.ofEpochSecond(30)),
@@ -226,8 +227,8 @@ public class TrackStatisticsUpdaterTest {
.setHeartRate(50), .setHeartRate(50),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(45)) new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(45))
.setHeartRate(50), .setHeartRate(50),
new TrackPoint(0, 1, Altitude.WGS84.of(0), Instant.ofEpochSecond(50)), createTrackPoint(0, 1, Altitude.WGS84.of(0), Instant.ofEpochSecond(50)),
new TrackPoint(0, 2, Altitude.WGS84.of(0), Instant.ofEpochSecond(55)), createTrackPoint(0, 2, Altitude.WGS84.of(0), Instant.ofEpochSecond(55)),
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(60)) new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(60))
)); ));
@@ -243,9 +244,9 @@ public class TrackStatisticsUpdaterTest {
// when // when
subject.addTrackPoints(List.of( subject.addTrackPoints(List.of(
new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)),
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1)) createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1))
.setSensorDistance(Distance.of(10)), .setSensorDistance(Distance.of(10)),
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(2)) createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(2))
.setSensorDistance(Distance.of(10)), .setSensorDistance(Distance.of(10)),
new TrackPoint(TrackPoint.Type.IDLE, Instant.ofEpochSecond(30)) new TrackPoint(TrackPoint.Type.IDLE, Instant.ofEpochSecond(30))
@@ -254,9 +255,9 @@ public class TrackStatisticsUpdaterTest {
.setHeartRate(50), .setHeartRate(50),
new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(45)) new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(45))
.setHeartRate(50), .setHeartRate(50),
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(50)) createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(50))
.setSensorDistance(Distance.of(10)), .setSensorDistance(Distance.of(10)),
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(55)) createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(55))
.setSensorDistance(Distance.of(10)), .setSensorDistance(Distance.of(10)),
new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(60)) new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(60))
@@ -274,7 +275,7 @@ public class TrackStatisticsUpdaterTest {
// when // when
subject.addTrackPoint(new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0))); subject.addTrackPoint(new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)));
subject.addTrackPoint( subject.addTrackPoint(
new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(10)) createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(10))
.setSensorDistance(Distance.of(10))); .setSensorDistance(Distance.of(10)));
subject.addTrackPoint(new TrackPoint(TrackPoint.Type.IDLE, Instant.ofEpochSecond(30))); subject.addTrackPoint(new TrackPoint(TrackPoint.Type.IDLE, Instant.ofEpochSecond(30)));
@@ -330,11 +331,11 @@ public class TrackStatisticsUpdaterTest {
TrackStatisticsUpdater subject = new TrackStatisticsUpdater(); TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000)); TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000));
TrackPoint tp2 = new TrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000)); TrackPoint tp2 = createTrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000));
tp2.setSpeed(Speed.of(5f)); tp2.setSpeed(Speed.of(5f));
TrackPoint tp3 = new TrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000)); TrackPoint tp3 = createTrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000));
tp3.setSpeed(Speed.of(5f)); tp3.setSpeed(Speed.of(5f));
TrackPoint tp4 = new TrackPoint(0.0005, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(4000)); TrackPoint tp4 = createTrackPoint(0.0005, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(4000));
tp4.setSpeed(Speed.of(5f)); tp4.setSpeed(Speed.of(5f));
TrackPoint tp5 = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochMilli(5000)); TrackPoint tp5 = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochMilli(5000));
@@ -352,4 +353,18 @@ public class TrackStatisticsUpdaterTest {
assertEquals(55.287, subject.getTrackStatistics().getTotalDistance().toM(), 0.01); assertEquals(55.287, subject.getTrackStatistics().getTotalDistance().toM(), 0.01);
assertEquals(55.287, copy.getTrackStatistics().getTotalDistance().toM(), 0.01); assertEquals(55.287, copy.getTrackStatistics().getTotalDistance().toM(), 0.01);
} }
public TrackPoint createTrackPoint(double latitude, double longitude, Altitude altitude, Instant time) {
return new TrackPoint(TrackPoint.Type.TRACKPOINT,
new Position(
time,
latitude,
longitude,
null,
altitude,
null,
null,
null
));
}
} }
@@ -23,7 +23,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.Optional; import java.util.Optional;
@@ -31,13 +30,11 @@ import java.util.Optional;
* Sensor and/or location information for a specific point in time. * Sensor and/or location information for a specific point in time.
* <p> * <p>
* Time is created using the {@link de.dennisguse.opentracks.services.handlers.MonotonicClock}, because system time jump backwards. * Time is created using the {@link de.dennisguse.opentracks.services.handlers.MonotonicClock}, because system time jump backwards.
* GPS time is ignored as for non-GPS events, we could not create timestamps. * GPS time is ignored as for non-GPS events, we could not create GPS-based timestamps.
*/ */
//TODO Should be a record (with final properties) //TODO Should be a record (with final properties)
public class TrackPoint { public class TrackPoint {
private static final Duration MAX_LOCATION_AGE = Duration.ofMinutes(1);
@Nullable @Nullable
private TrackPoint.Id id; private TrackPoint.Id id;
@@ -98,40 +95,11 @@ public class TrackPoint {
//TODO Refactor constructors //TODO Refactor constructors
public TrackPoint(@NonNull Type type, @NonNull Instant time) { public TrackPoint(@NonNull Type type, @NonNull Instant time) {
this.type = type; this(null, type, Position.of(time));
this.position = Position.of(time);
} }
@Deprecated public TrackPoint(@NonNull Type type, @NonNull Position position) {
public TrackPoint(@NonNull Location location, @NonNull Instant time) { this(null, type, position);
this.type = Type.TRACKPOINT;
this.position = Position.of(location, time);
}
public TrackPoint(@NonNull Position position) {
this(null, Type.TRACKPOINT, position);
}
public TrackPoint(@NonNull Type type, @NonNull Location location, @NonNull Instant time) {
this.type = type;
this.position = Position.of(location, time);
}
//TODO Remove; only used for TrackStatisticUpdaterTest
@Deprecated
@VisibleForTesting
public TrackPoint(double latitude, double longitude, Altitude altitude, Instant time) {
this.type = Type.TRACKPOINT;
this.position = new Position(
time,
latitude,
longitude,
null,
altitude,
null,
null,
null
);
} }
public static TrackPoint createSegmentStartManualWithTime(Instant time) { public static TrackPoint createSegmentStartManualWithTime(Instant time) {
@@ -147,6 +115,7 @@ public class TrackPoint {
return type; return type;
} }
@Deprecated //Should not be needed.
public TrackPoint setType(@NonNull Type type) { public TrackPoint setType(@NonNull Type type) {
this.type = type; this.type = type;
return this; return this;
@@ -186,29 +155,12 @@ public class TrackPoint {
return position.latitude(); return position.latitude();
} }
@Deprecated
public TrackPoint setLatitude(double latitude) {
this.position = position.withCoordinates(latitude, getLongitude());
return this;
}
//TODO Should be double //TODO Should be double
@Deprecated //Use getPosition() @Deprecated //Use getPosition()
public Double getLongitude() { public Double getLongitude() {
return position.longitude(); return position.longitude();
} }
@Deprecated
public TrackPoint setLongitude(double longitude) {
setCoordinates(getLatitude(), longitude);
return this;
}
public TrackPoint setCoordinates(double latitude, double longitude) {
this.position = this.position.withCoordinates(latitude, longitude);
return this;
}
@NonNull @NonNull
public Position getPosition() { public Position getPosition() {
return position; return position;
@@ -233,6 +185,7 @@ public class TrackPoint {
return altitudeGain_m; return altitudeGain_m;
} }
@Deprecated
public TrackPoint setAltitudeGain(Float altitudeGain_m) { public TrackPoint setAltitudeGain(Float altitudeGain_m) {
this.altitudeGain_m = altitudeGain_m; this.altitudeGain_m = altitudeGain_m;
return this; return this;
@@ -246,6 +199,7 @@ public class TrackPoint {
return altitudeLoss_m; return altitudeLoss_m;
} }
@Deprecated
public TrackPoint setAltitudeLoss(Float altitudeLoss_m) { public TrackPoint setAltitudeLoss(Float altitudeLoss_m) {
this.altitudeLoss_m = altitudeLoss_m; this.altitudeLoss_m = altitudeLoss_m;
return this; return this;
@@ -264,12 +218,14 @@ public class TrackPoint {
return position.altitude(); return position.altitude();
} }
@Deprecated
@VisibleForTesting @VisibleForTesting
public TrackPoint setAltitude(double altitude_m) { public TrackPoint setAltitude(double altitude_m) {
setAltitude(Altitude.WGS84.of(altitude_m)); setAltitude(Altitude.WGS84.of(altitude_m));
return this; return this;
} }
@Deprecated
public TrackPoint setAltitude(Altitude altitude) { public TrackPoint setAltitude(Altitude altitude) {
position = position.with(altitude); position = position.with(altitude);
return this; return this;
@@ -283,6 +239,7 @@ public class TrackPoint {
return position.speed(); return position.speed();
} }
@Deprecated
public TrackPoint setSpeed(Speed speed) { public TrackPoint setSpeed(Speed speed) {
this.position = position.with(speed); this.position = position.with(speed);
return this; return this;
@@ -309,6 +266,7 @@ public class TrackPoint {
return position.horizontalAccuracy(); return position.horizontalAccuracy();
} }
@Deprecated
public TrackPoint setHorizontalAccuracy(Distance horizontalAccuracy) { public TrackPoint setHorizontalAccuracy(Distance horizontalAccuracy) {
this.position = this.position.withHorizontalAccuracy(horizontalAccuracy); this.position = this.position.withHorizontalAccuracy(horizontalAccuracy);
return this; return this;
@@ -331,7 +331,9 @@ public class GpxTrackImporter extends DefaultHandler implements XMLImporter.Trac
} }
} }
TrackPoint trackPoint = new TrackPoint(new Position( TrackPoint trackPoint = new TrackPoint(
TrackPoint.Type.TRACKPOINT,
new Position(
parsedTime.toInstant(), parsedTime.toInstant(),
latitudeParsed, latitudeParsed,
longitudeParsed, longitudeParsed,
@@ -430,7 +432,7 @@ public class GpxTrackImporter extends DefaultHandler implements XMLImporter.Trac
TrackPoint trackPoint = createTrackPoint(); TrackPoint trackPoint = createTrackPoint();
if (!trackPoint.hasLocation()) { if (!trackPoint.hasLocation()) {
Log.w(TAG, "Marker with invalid coordinates ignored: " + trackPoint.getLocation()); Log.w(TAG, "Marker with invalid coordinates ignored: " + trackPoint.getPosition());
return; return;
} }
Marker marker = new Marker(null, trackPoint); Marker marker = new Marker(null, trackPoint);
@@ -35,6 +35,7 @@ import java.util.Locale;
import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Distance;
import de.dennisguse.opentracks.data.models.Marker; import de.dennisguse.opentracks.data.models.Marker;
import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
@@ -94,7 +95,7 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
private ZoneOffset zoneOffset; private ZoneOffset zoneOffset;
private final ArrayList<Instant> whenList = new ArrayList<>(); private final ArrayList<Instant> whenList = new ArrayList<>();
private final ArrayList<Location> locationList = new ArrayList<>(); private final ArrayList<Position> positionList = new ArrayList<>();
private String dataType; private String dataType;
@@ -255,13 +256,14 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
return; return;
} }
Location location = createLocation(longitude, latitude, altitude); Position position = createPosition(latitude, longitude, altitude);
if (location == null) { if (position == null) {
Log.w(TAG, "Marker with invalid coordinates ignored: " + location); Log.w(TAG, "Marker with invalid coordinates ignored: " + latitude + " " + longitude);
return; return;
} }
position = position.with(whenList.get(0));
Marker marker = new Marker(null, new TrackPoint(TrackPoint.Type.TRACKPOINT, location, whenList.get(0))); //TODO Creating marker without need Marker marker = new Marker(null, new TrackPoint(TrackPoint.Type.TRACKPOINT, position)); //TODO Creating marker without need
marker.setName(name != null ? name : ""); marker.setName(name != null ? name : "");
marker.setDescription(description != null ? description : ""); marker.setDescription(description != null ? description : "");
marker.setCategory(activityTypeLocalized != null ? activityTypeLocalized : ""); marker.setCategory(activityTypeLocalized != null ? activityTypeLocalized : "");
@@ -288,7 +290,7 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
} }
private void onTrackSegmentStart() { private void onTrackSegmentStart() {
locationList.clear(); positionList.clear();
whenList.clear(); whenList.clear();
trackpointTypeList.clear(); trackpointTypeList.clear();
@@ -304,24 +306,23 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
} }
private void onTrackSegmentEnd() { private void onTrackSegmentEnd() {
if (locationList.size() != whenList.size()) { if (positionList.size() != whenList.size()) {
throw new ImportParserException("<coords> and <when> should have the same count."); throw new ImportParserException("<coords> and <when> should have the same count.");
} }
// Close a track segment by inserting the segment locations // Close a track segment by inserting the segment locations
for (int i = 0; i < locationList.size(); i++) { for (int i = 0; i < positionList.size(); i++) {
Instant time = whenList.get(i); Instant time = whenList.get(i);
Location location = locationList.get(i); Position position = positionList.get(i);
TrackPoint trackPoint; TrackPoint trackPoint;
if (location == null) { if (position == null) {
trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, time); trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(time));
} else { } else {
trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, location, time); trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, position.with(time));
} }
if (i < trackpointTypeList.size() && trackpointTypeList.get(i) != null) { if (i < trackpointTypeList.size() && trackpointTypeList.get(i) != null) {
TrackPoint.Type type = TrackPoint.Type.valueOf(trackpointTypeList.get(i)); TrackPoint.Type type = TrackPoint.Type.valueOf(trackpointTypeList.get(i));
trackPoint.setType(type); trackPoint.setType(type);
} }
@@ -363,7 +364,7 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
} else { } else {
type = TrackPoint.Type.SEGMENT_START_AUTOMATIC; type = TrackPoint.Type.SEGMENT_START_AUTOMATIC;
} }
} else if (i == locationList.size() - 1 && !trackPoint.wasCreatedManually()) { } else if (i == positionList.size() - 1 && !trackPoint.wasCreatedManually()) {
//last //last
type = TrackPoint.Type.SEGMENT_END_MANUAL; type = TrackPoint.Type.SEGMENT_END_MANUAL;
} }
@@ -381,18 +382,16 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
altitude = parts.length == 3 ? parts[2] : null; altitude = parts.length == 3 ? parts[2] : null;
} }
locationList.add(createLocation(longitude, latitude, altitude)); positionList.add(createPosition(latitude, longitude, altitude));
longitude = null; longitude = null;
latitude = null; latitude = null;
altitude = null; altitude = null;
} }
private Location createLocation(String longitude, String latitude, String altitude) { private Position createPosition(String latitude, String longitude, String altitude) {
Location location = null; if (longitude != null && latitude != null) {
if (longitude != null || latitude != null) { Location location = new Location("import");
location = new Location("import");
try { try {
location.setLatitude(Double.parseDouble(latitude)); location.setLatitude(Double.parseDouble(latitude));
location.setLongitude(Double.parseDouble(longitude)); location.setLongitude(Double.parseDouble(longitude));
@@ -407,8 +406,10 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
throw new ParsingException(createErrorMessage(String.format(Locale.US, "Unable to parse altitude: %s", altitude)), e); throw new ParsingException(createErrorMessage(String.format(Locale.US, "Unable to parse altitude: %s", altitude)), e);
} }
} }
return Position.of(location, null);
} }
return location;
return null;
} }
private void onExtendedDataValueEnd() throws SAXException { private void onExtendedDataValueEnd() throws SAXException {
@@ -124,7 +124,7 @@ public class GpsManager implements SensorConnector, LocationListenerCompat, GpsS
@Override @Override
public void onLocationChanged(@NonNull Location location) { public void onLocationChanged(@NonNull Location location) {
// Send each update to the status; please note that this TrackPoint is not stored. // Send each update to the status; please note that this TrackPoint is not stored.
TrackPoint trackPoint = new TrackPoint(location, trackPointCreator.createNow()); TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(location, trackPointCreator.createNow()));
gpsStatusManager.onNewTrackPoint(trackPoint); gpsStatusManager.onNewTrackPoint(trackPoint);
if (!trackPoint.getPosition().hasValidLocation()) { if (!trackPoint.getPosition().hasValidLocation()) {
@@ -61,7 +61,7 @@ public class SettingsCustomLayoutEditAdapter extends RecyclerView.Adapter<Recycl
Speed.zero() Speed.zero()
); );
demoData = new RecordingData(track, new TrackPoint(position), null); demoData = new RecordingData(track, new TrackPoint(TrackPoint.Type.TRACKPOINT, position), null);
} }
private RecordingLayout recordingLayout; private RecordingLayout recordingLayout;
@@ -47,6 +47,7 @@ import java.time.Instant;
import de.dennisguse.opentracks.AbstractActivity; import de.dennisguse.opentracks.AbstractActivity;
import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.data.models.Marker; import de.dennisguse.opentracks.data.models.Marker;
import de.dennisguse.opentracks.data.models.Position;
import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.databinding.MarkerEditBinding; import de.dennisguse.opentracks.databinding.MarkerEditBinding;
@@ -169,7 +170,7 @@ public class MarkerEditActivity extends AbstractActivity {
} }
private LiveData<Marker> createNewMarker() { private LiveData<Marker> createNewMarker() {
TrackPoint trackPoint = new TrackPoint(location, Instant.now()); TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(location, Instant.now()));
return viewModel.createNewMarker(trackId, trackPoint); return viewModel.createNewMarker(trackId, trackPoint);
} }