diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/GpxImporter.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/GpxImporter.java index db98e8413..32979d853 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/GpxImporter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/GpxImporter.java @@ -102,6 +102,9 @@ public class GpxImporter extends DefaultHandler { // True if the current track has a start time private boolean hasStartTime; + + // The import time + private long importTime; // The current location private Location location; @@ -261,8 +264,9 @@ public class GpxImporter extends DefaultHandler { private void onTrackElementEnd() { flushPoints(); if (tripStatisticsUpdater == null) { - tripStatisticsUpdater = new TripStatisticsUpdater(-1L); - tripStatisticsUpdater.updateTime(-1L); + long now = System.currentTimeMillis(); + tripStatisticsUpdater = new TripStatisticsUpdater(now); + tripStatisticsUpdater.updateTime(now); } track.setStopId(getLastPointId()); track.setTripStatistics(tripStatisticsUpdater.getTripStatistics()); @@ -450,11 +454,13 @@ public class GpxImporter extends DefaultHandler { */ private void insertPoint(Location newLocation) { if (tripStatisticsUpdater == null) { - tripStatisticsUpdater = new TripStatisticsUpdater(newLocation.getTime()); hasStartTime = newLocation.getTime() != -1L; + importTime = System.currentTimeMillis(); + tripStatisticsUpdater = new TripStatisticsUpdater( + hasStartTime ? newLocation.getTime() : importTime); } if (!hasStartTime) { - newLocation.setTime(-1L); + newLocation.setTime(importTime); } tripStatisticsUpdater.addLocation(newLocation, minRecordingDistance); diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/io/file/GpxImporterTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/io/file/GpxImporterTest.java index b6c930bc5..b1d158e3c 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/io/file/GpxImporterTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/io/file/GpxImporterTest.java @@ -247,13 +247,11 @@ public class GpxImporterTest extends AndroidTestCase { public void testOneTrackTwoSegmentsNoTime() throws Exception { Capture capturedTrack = new Capture(); - Location location0 = createLocation(0, -1L); - expect(myTracksProviderUtils.insertTrack((Track) AndroidMock.anyObject())) .andReturn(TRACK_ID_0_URI); // A flush happens before getting the start point ID expect(myTracksProviderUtils.bulkInsertTrackPoint( - LocationsMatcher.eqLoc(location0), eq(1), eq(TRACK_ID_0))).andReturn(1); + (Location[]) AndroidMock.anyObject(), eq(1), eq(TRACK_ID_0))).andReturn(1); expect(myTracksProviderUtils.getFirstTrackPointId(TRACK_ID_0)).andReturn(TRACK_POINT_ID_0); // A flush happens at the end @@ -330,7 +328,9 @@ public class GpxImporterTest extends AndroidTestCase { private void verifyTrack(Track track, String name, String description, long time) { assertEquals(name, track.getName()); assertEquals(description, track.getDescription()); - assertEquals(time, track.getTripStatistics().getStartTime()); + if (time != -1L) { + assertEquals(time, track.getTripStatistics().getStartTime()); + } assertNotSame(-1, track.getStartId()); assertNotSame(-1, track.getStopId()); }