diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/GPSCoordinate.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/GPSCoordinate.java index 94c310daa..eb7552060 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/GPSCoordinate.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/GPSCoordinate.java @@ -18,6 +18,8 @@ package nodomain.freeyourgadget.gadgetbridge.model; import android.location.Location; +import androidx.annotation.NonNull; + import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Comparator; @@ -111,6 +113,7 @@ public class GPSCoordinate { return new BigDecimal(value).setScale(8, RoundingMode.HALF_UP).toPlainString(); } + @NonNull @Override public String toString() { return "lon: " + formatLocation(longitude) + ", lat: " + formatLocation(latitude) + ", alt: " + formatLocation(altitude) + "m"; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/gpx/GpxParser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/gpx/GpxParser.java index 1ebda1043..a86d1d711 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/gpx/GpxParser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/gpx/GpxParser.java @@ -226,7 +226,7 @@ public class GpxParser { while (eventType != XmlPullParser.END_TAG || !parser.getName().equals("extensions")) { if (parser.getEventType() == XmlPullParser.START_TAG) { switch (parser.getName()) { - case "gpxtpx:TrackPointExtension": + case "TrackPointExtension": parseTrackPointExtensions(trackPointBuilder); continue; } @@ -237,11 +237,11 @@ public class GpxParser { } private void parseTrackPointExtensions(final GpxTrackPoint.Builder trackPointBuilder) throws Exception { - while (eventType != XmlPullParser.END_TAG || !parser.getName().equals("gpxtpx:TrackPointExtension")) { + while (eventType != XmlPullParser.END_TAG || !parser.getName().equals("TrackPointExtension")) { if (parser.getEventType() == XmlPullParser.START_TAG) { switch (parser.getName()) { - case "gpxtpx:hr": - trackPointBuilder.withHeartRate(Integer.parseInt(parseStringContent("gpxtpx:hr"))); + case "hr": + trackPointBuilder.withHeartRate(Integer.parseInt(parseStringContent("hr"))); continue; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/gpx/model/GpxTrackPoint.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/gpx/model/GpxTrackPoint.java index 9e746d56d..6b729f0c1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/gpx/model/GpxTrackPoint.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/gpx/model/GpxTrackPoint.java @@ -16,6 +16,8 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.util.gpx.model; +import androidx.annotation.NonNull; + import java.util.Date; import java.util.Objects; @@ -59,6 +61,12 @@ public class GpxTrackPoint extends GPSCoordinate { return Objects.hash(super.hashCode(), time, heartRate); } + @NonNull + @Override + public String toString() { + return "ts: " + time.getTime() + ", " + super.toString() + ", heartRate: " + heartRate; + } + public ActivityPoint toActivityPoint() { final ActivityPoint activityPoint = new ActivityPoint(); activityPoint.setTime(time); @@ -73,7 +81,7 @@ public class GpxTrackPoint extends GPSCoordinate { private double latitude; private double altitude; private Date time; - private int heartRate; + private int heartRate = -1; public Builder withLongitude(final double longitude) { this.longitude = longitude; diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/util/gpx/GPXParserTest.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/util/gpx/GPXParserTest.java index 4b8691257..14062f21b 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/util/gpx/GPXParserTest.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/util/gpx/GPXParserTest.java @@ -33,6 +33,10 @@ public class GPXParserTest extends TestBase { Assert.assertEquals(df.format(tp.getLatitude()), "44.15"); Assert.assertThat(df.format(tp.getAltitude()), anyOf(is("40"), is("46"))); } + Assert.assertEquals( + new GpxTrackPoint(-68.200293, 44.152462, 40, new Date(1546300800000L)), + trackPoints.get(0) + ); } } @@ -45,13 +49,13 @@ public class GPXParserTest extends TestBase { Assert.assertEquals(2, gpxFile.getTracks().get(0).getTrackSegments().size()); final List segment1 = new ArrayList() {{ - add(new GpxTrackPoint(-8.2695876, -70.6666343, 790.0, new Date(1680969788000L))); - add(new GpxTrackPoint(-8.2653274, -70.6670617, 296.0, new Date(1680970639000L))); + add(new GpxTrackPoint(-8.2695876, -70.6666343, 790.0, new Date(1680969788000L), 123)); + add(new GpxTrackPoint(-8.2653274, -70.6670617, 296.0, new Date(1680970639000L), 56)); }}; final List segment2 = new ArrayList() {{ - add(new GpxTrackPoint(-8.2653274, -70.6670617, 205.0, new Date(1680971684000L))); - add(new GpxTrackPoint(-8.2695876, -70.6666343, 209.0, new Date(1680973017000L))); + add(new GpxTrackPoint(-8.2653274, -70.6670617, 205.0, new Date(1680971684000L), 85)); + add(new GpxTrackPoint(-8.2695876, -70.6666343, 209.0, new Date(1680973017000L), 150)); }}; Assert.assertEquals(gpxFile.getTracks().get(0).getTrackSegments().get(0).getTrackPoints(), segment1); @@ -68,8 +72,8 @@ public class GPXParserTest extends TestBase { Assert.assertEquals(1, gpxFile.getTracks().get(0).getTrackSegments().size()); final List segment1 = new ArrayList() {{ - add(new GpxTrackPoint(-8.2695876, -70.6666343, 790.0, new Date(1680969788000L))); - add(new GpxTrackPoint(-8.2653274, -70.6670617, 296.0, new Date(1680970639000L))); + add(new GpxTrackPoint(-8.2695876, -70.6666343, 790.0, new Date(1680969788000L), 123)); + add(new GpxTrackPoint(-8.2653274, -70.6670617, 296.0, new Date(1680970639000L), 56)); }}; Assert.assertEquals(gpxFile.getTracks().get(0).getTrackSegments().get(0).getTrackPoints(), segment1);