Refactoring to marker: TrackRecordingService.

#389
This commit is contained in:
Dennis Guse
2020-09-05 10:20:05 +02:00
parent 74e09e1fa9
commit 19d8563a76
6 changed files with 21 additions and 62 deletions
@@ -296,7 +296,7 @@ public class TrackRecordingServiceTest {
assertFalse(service.isRecording()); assertFalse(service.isRecording());
// when // when
Marker.Id waypointId = service.insertWaypoint(null, null, null, null); Marker.Id waypointId = service.insertMarker(null, null, null, null);
// then // then
assertNull(waypointId); assertNull(waypointId);
@@ -313,7 +313,7 @@ public class TrackRecordingServiceTest {
Track.Id trackId = service.getRecordingTrackId(); Track.Id trackId = service.getRecordingTrackId();
// when // when
Marker.Id waypointId = service.insertWaypoint(null, null, null, null); Marker.Id waypointId = service.insertMarker(null, null, null, null);
// then // then
assertNotEquals(-1L, waypointId); assertNotEquals(-1L, waypointId);
@@ -226,7 +226,7 @@ public class TrackRecordingServiceTestLooper {
service.newTrackPoint(trackPoint, prefAccuracy); service.newTrackPoint(trackPoint, prefAccuracy);
if (i % 7 == 0) { if (i % 7 == 0) {
service.insertWaypoint(null, null, null, null); service.insertMarker(null, null, null, null);
} }
} }
@@ -215,6 +215,7 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
return trackStatisticsUpdater.getTrackStatistics(); return trackStatisticsUpdater.getTrackStatistics();
} }
//TODO Throw exception, when not recording.
public long getTotalTime() { public long getTotalTime() {
if (trackStatisticsUpdater == null) { if (trackStatisticsUpdater == null) {
return 0; return 0;
@@ -225,27 +226,22 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
return trackStatisticsUpdater.getTrackStatistics().getTotalTime(); return trackStatisticsUpdater.getTrackStatistics().getTotalTime();
} }
/** public Marker.Id insertMarker(String name, String category, String description, String photoUrl) {
* Inserts a waypoint.
*
* @return the waypoint id
*/
public Marker.Id insertWaypoint(String name, String category, String description, String photoUrl) {
if (!isRecording() || isPaused()) { if (!isRecording() || isPaused()) {
return null; return null;
} }
if (name == null) { if (name == null) {
int nextWaypointNumber = contentProviderUtils.getNextMarkerNumber(recordingTrackId); int nextMarkerNumber = contentProviderUtils.getNextMarkerNumber(recordingTrackId);
if (nextWaypointNumber == -1) { if (nextMarkerNumber == -1) {
nextWaypointNumber = 1; nextMarkerNumber = 1;
} }
name = getString(R.string.marker_name_format, nextWaypointNumber + 1); name = getString(R.string.marker_name_format, nextMarkerNumber + 1);
} }
TrackPoint trackPoint = getLastValidTrackPointInCurrentSegment(recordingTrackId); TrackPoint trackPoint = getLastValidTrackPointInCurrentSegment(recordingTrackId);
if (trackPoint == null) { if (trackPoint == null) {
Log.i(TAG, "Could not create a waypoint as trackPoint is unknown."); Log.i(TAG, "Could not create a marker as trackPoint is unknown.");
return null; return null;
} }
@@ -258,9 +254,9 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
double length = stats.getTotalDistance(); double length = stats.getTotalDistance();
long duration = stats.getTotalTime(); long duration = stats.getTotalTime();
// Insert waypoint // Insert marker
Marker waypoint = new Marker(name, description, category, icon, recordingTrackId, length, duration, trackPoint.getLocation(), photoUrl); Marker marker = new Marker(name, description, category, icon, recordingTrackId, length, duration, trackPoint.getLocation(), photoUrl);
Uri uri = contentProviderUtils.insertMarker(waypoint); Uri uri = contentProviderUtils.insertMarker(marker);
return new Marker.Id(ContentUris.parseId(uri)); return new Marker.Id(ContentUris.parseId(uri));
} }
@@ -90,8 +90,8 @@ class TrackRecordingServiceBinder extends android.os.Binder implements TrackReco
} }
@Override @Override
public Marker.Id insertWaypoint(String name, String category, String description, String photoUrl) { public Marker.Id insertMarker(String name, String category, String description, String photoUrl) {
return trackRecordingService.insertWaypoint(name, category, description, photoUrl); return trackRecordingService.insertMarker(name, category, description, photoUrl);
} }
@Override @Override
@@ -187,10 +187,10 @@ public class TrackRecordingServiceConnection implements ServiceConnection, Death
Log.d(TAG, "Unable to add marker, no track recording service"); Log.d(TAG, "Unable to add marker, no track recording service");
} else { } else {
try { try {
Marker.Id waypoint = trackRecordingService.insertWaypoint(name, category, description, photoUrl); Marker.Id marker = trackRecordingService.insertMarker(name, category, description, photoUrl);
if (waypoint != null) { if (marker != null) {
Toast.makeText(context, R.string.marker_add_success, Toast.LENGTH_SHORT).show(); Toast.makeText(context, R.string.marker_add_success, Toast.LENGTH_SHORT).show();
return waypoint; return marker;
} }
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
Log.e(TAG, "Unable to add marker.", e); Log.e(TAG, "Unable to add marker.", e);
@@ -201,12 +201,6 @@ public class TrackRecordingServiceConnection implements ServiceConnection, Death
return null; return null;
} }
/**
* Stops the recording.
*
* @param context the context
* @param showEditor true to show the editor
*/
public void stopRecording(@NonNull Context context, boolean showEditor) { public void stopRecording(@NonNull Context context, boolean showEditor) {
TrackRecordingServiceInterface trackRecordingService = getServiceIfBound(); TrackRecordingServiceInterface trackRecordingService = getServiceIfBound();
if (trackRecordingService == null) { if (trackRecordingService == null) {
@@ -30,46 +30,20 @@ import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager;
*/ */
public interface TrackRecordingServiceInterface { public interface TrackRecordingServiceInterface {
/**
* Starts gps.
*/
void startGps(); void startGps();
/**
* Stops gps.
*/
void stopGps(); void stopGps();
/**
* Starts recording a new track.
*
* @return the track ID of the new track.
*/
Track.Id startNewTrack(); Track.Id startNewTrack();
/**
* Resumes the track identified by trackId.
*/
void resumeTrack(Track.Id trackId);
/**
* Pauses the current recording track.
*/
void pauseCurrentTrack(); void pauseCurrentTrack();
/**
* Resumes the current recording track.
*/
void resumeCurrentTrack(); void resumeCurrentTrack();
/** void resumeTrack(Track.Id trackId);
* Ends the current recording track.
*/
void endCurrentTrack(); void endCurrentTrack();
/**
* Returns true if currently recording a track.
*/
boolean isRecording(); boolean isRecording();
/** /**
@@ -88,12 +62,7 @@ public interface TrackRecordingServiceInterface {
//TODO milliseconds? //TODO milliseconds?
long getTotalTime(); long getTotalTime();
/** Marker.Id insertMarker(String name, String category, String description, String photoUrl);
* Inserts a waypoint in the current recording track.
*
* @return the ID of the inserted waypoint
*/
Marker.Id insertWaypoint(String name, String category, String description, String photoUrl);
/** /**
* Gets the current sensor data. Returns null if there is no data. * Gets the current sensor data. Returns null if there is no data.