Fixed TrackRecordingService.insertWaypoint() to allow deprecated behavior.

This commit is contained in:
Dennis Guse
2019-12-11 23:33:04 +01:00
parent 46328211c2
commit 29f92b887c
5 changed files with 10 additions and 43 deletions
@@ -190,17 +190,6 @@ public class TrackRecordingServiceTest {
Assert.assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, service.getRecordingTrackId()); Assert.assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, service.getRecordingTrackId());
} }
@MediumTest
@Test
@Deprecated
public void testInsertStatisticsMarker_noRecordingTrack() throws Exception {
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent(context)));
Assert.assertFalse(service.isRecording());
long waypointId = service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
Assert.assertEquals(-1L, waypointId);
}
// NOTE: Do not use to create a track that is currently recording. // NOTE: Do not use to create a track that is currently recording.
private void createDummyTrack(long id, long stopTime, boolean isRecording) { private void createDummyTrack(long id, long stopTime, boolean isRecording) {
Track dummyTrack = new Track(); Track dummyTrack = new Track();
@@ -218,9 +218,7 @@ public class TrackRecordingServiceTestLooper {
location.setBearing(3.0f); location.setBearing(3.0f);
service.insertTrackPoint(location); service.insertTrackPoint(location);
if (i % 10 == 0) { if (i % 7 == 0) {
service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
} else if (i % 7 == 0) {
service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT); service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT);
} }
} }
@@ -188,6 +188,7 @@ public final class Waypoint {
} }
public enum WaypointType { public enum WaypointType {
WAYPOINT, STATISTICS WAYPOINT,
STATISTICS //Always the first waypoint; only one can exist.
} }
} }
@@ -26,8 +26,7 @@ public class WaypointCreationRequest {
public final static WaypointCreationRequest DEFAULT_WAYPOINT = new WaypointCreationRequest(WaypointType.WAYPOINT, false); public final static WaypointCreationRequest DEFAULT_WAYPOINT = new WaypointCreationRequest(WaypointType.WAYPOINT, false);
public final static WaypointCreationRequest DEFAULT_STATISTICS = new WaypointCreationRequest(WaypointType.STATISTICS, false); @Deprecated // TODO Do not create per
public final static WaypointCreationRequest DEFAULT_START_TRACK = new WaypointCreationRequest(WaypointType.STATISTICS, true); public final static WaypointCreationRequest DEFAULT_START_TRACK = new WaypointCreationRequest(WaypointType.STATISTICS, true);
private WaypointType type; private WaypointType type;
@@ -49,7 +49,6 @@ import de.dennisguse.opentracks.content.LocationIterator;
import de.dennisguse.opentracks.content.SensorDataSetLocation; import de.dennisguse.opentracks.content.SensorDataSetLocation;
import de.dennisguse.opentracks.content.Track; import de.dennisguse.opentracks.content.Track;
import de.dennisguse.opentracks.content.Waypoint; import de.dennisguse.opentracks.content.Waypoint;
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
import de.dennisguse.opentracks.content.WaypointCreationRequest; import de.dennisguse.opentracks.content.WaypointCreationRequest;
import de.dennisguse.opentracks.content.sensor.SensorDataSet; import de.dennisguse.opentracks.content.sensor.SensorDataSet;
import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager; import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager;
@@ -275,23 +274,14 @@ public class TrackRecordingService extends Service {
super.onDestroy(); super.onDestroy();
} }
/**
* Returns true if the service is recording.
*/
public boolean isRecording() { public boolean isRecording() {
return PreferencesUtils.isRecording(recordingTrackId); return PreferencesUtils.isRecording(recordingTrackId);
} }
/**
* Returns true if the current recording is paused.
*/
public boolean isPaused() { public boolean isPaused() {
return recordingTrackPaused; return recordingTrackPaused;
} }
/**
* Gets the trip statistics.
*/
public TripStatistics getTripStatistics() { public TripStatistics getTripStatistics() {
if (trackTripStatisticsUpdater == null) { if (trackTripStatisticsUpdater == null) {
return null; return null;
@@ -310,31 +300,19 @@ public class TrackRecordingService extends Service {
return -1L; return -1L;
} }
WaypointType waypointType = waypointCreationRequest.getType(); String name = waypointCreationRequest.getName();
if (waypointType == WaypointType.STATISTICS) if (name == null) {
throw new RuntimeException("statistics waypoints are not supported anymore."); int nextWaypointNumber = contentProviderUtils.getNextWaypointNumber(recordingTrackId, waypointCreationRequest.getType());
// Get name
String name;
if (waypointCreationRequest.getName() != null) {
name = waypointCreationRequest.getName();
} else {
int nextWaypointNumber = contentProviderUtils.getNextWaypointNumber(recordingTrackId, waypointType);
if (nextWaypointNumber == -1) { if (nextWaypointNumber == -1) {
nextWaypointNumber = 0; nextWaypointNumber = 0;
} }
name = getString(R.string.marker_name_format, nextWaypointNumber); name = getString(R.string.marker_name_format, nextWaypointNumber);
} }
// Get category
String category = waypointCreationRequest.getCategory() != null ? waypointCreationRequest.getCategory() : ""; String category = waypointCreationRequest.getCategory() != null ? waypointCreationRequest.getCategory() : "";
// Get tripStatistics, description, and icon
String description = waypointCreationRequest.getDescription() != null ? waypointCreationRequest.getDescription() : ""; String description = waypointCreationRequest.getDescription() != null ? waypointCreationRequest.getDescription() : "";
//TODO Bundle icon?
String icon = getString(R.string.marker_waypoint_icon_url); String icon = getString(R.string.marker_waypoint_icon_url);
// Get length and duration
double length; double length;
long duration; long duration;
Location location = getLastValidTrackPointInCurrentSegment(recordingTrackId); Location location = getLastValidTrackPointInCurrentSegment(recordingTrackId);
@@ -357,7 +335,7 @@ public class TrackRecordingService extends Service {
String photoUrl = waypointCreationRequest.getPhotoUrl() != null ? waypointCreationRequest.getPhotoUrl() : ""; String photoUrl = waypointCreationRequest.getPhotoUrl() != null ? waypointCreationRequest.getPhotoUrl() : "";
// Insert waypoint // Insert waypoint
Waypoint waypoint = new Waypoint(name, description, category, icon, recordingTrackId, waypointType, length, duration, -1L, -1L, location, null, photoUrl); Waypoint waypoint = new Waypoint(name, description, category, icon, recordingTrackId, waypointCreationRequest.getType(), length, duration, -1L, -1L, location, null, photoUrl);
Uri uri = contentProviderUtils.insertWaypoint(waypoint); Uri uri = contentProviderUtils.insertWaypoint(waypoint);
return Long.parseLong(uri.getLastPathSegment()); return Long.parseLong(uri.getLastPathSegment());
} }
@@ -392,6 +370,8 @@ public class TrackRecordingService extends Service {
track.setIcon(TrackIconUtils.getIconValue(this, category)); track.setIcon(TrackIconUtils.getIconValue(this, category));
track.setTripStatistics(trackTripStatisticsUpdater.getTripStatistics()); track.setTripStatistics(trackTripStatisticsUpdater.getTripStatistics());
contentProviderUtils.updateTrack(track); contentProviderUtils.updateTrack(track);
//TODO Do not use insertWaypoint
insertWaypoint(WaypointCreationRequest.DEFAULT_START_TRACK); insertWaypoint(WaypointCreationRequest.DEFAULT_START_TRACK);
startRecording(true); startRecording(true);