GPSStatus: update initial and final status.

This commit is contained in:
Dennis Guse
2021-05-02 08:13:05 +02:00
parent 1baf652b81
commit 49219de46a
4 changed files with 20 additions and 13 deletions
@@ -577,7 +577,10 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
public void newGpsStatus(GpsStatusValue gpsStatusValue) { public void newGpsStatus(GpsStatusValue gpsStatusValue) {
notificationManager.updateContent(getString(gpsStatusValue.message)); notificationManager.updateContent(getString(gpsStatusValue.message));
gpsStatusObservable.postValue(gpsStatusValue); //TODO This check should not be necessary, but prevents a crash; somehow the shutdown is not working correctly as we should not receive a notification then.
if (gpsStatusObservable != null) {
gpsStatusObservable.postValue(gpsStatusValue);
}
} }
/** /**
@@ -767,13 +770,14 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
return isRecording() && !isPaused(); return isRecording() && !isPaused();
} }
public RecordingStatus pause() { // TODO Use
return new RecordingStatus(getTrackId(), true); // public RecordingStatus pause() {
} // return new RecordingStatus(getTrackId(), true);
// }
public RecordingStatus record(@NonNull Track.Id track) { //
return new RecordingStatus(trackId, false); // public RecordingStatus record(@NonNull Track.Id trackId) {
} // return new RecordingStatus(trackId, false);
// }
public RecordingStatus stop() { public RecordingStatus stop() {
return STATUS_DEFAULT; return STATUS_DEFAULT;
@@ -14,7 +14,7 @@ import de.dennisguse.opentracks.content.data.TrackPoint;
import de.dennisguse.opentracks.util.PreferencesUtils; import de.dennisguse.opentracks.util.PreferencesUtils;
/** /**
* This class handle GPS status according to received locations and some thresholds. * This class handle GPS status according to received locations` and some thresholds.
*/ */
//TODO should handle sharedpreference changes //TODO should handle sharedpreference changes
class GpsStatus { class GpsStatus {
@@ -56,6 +56,7 @@ class GpsStatus {
public void stop() { public void stop() {
stopped = true; stopped = true;
sendStatus(gpsStatus, GpsStatusValue.GPS_NONE);
} }
} }
@@ -75,10 +76,15 @@ class GpsStatus {
gpsStatusHandler = new Handler(); gpsStatusHandler = new Handler();
} }
public void start() {
client.onGpsStatusChanged(GpsStatusValue.GPS_NONE, GpsStatusValue.GPS_ENABLED);
}
/** /**
* The client that uses GpsStatus has to call this method to stop the Runnable if needed. * The client that uses GpsStatus has to call this method to stop the Runnable if needed.
*/ */
public void stop() { public void stop() {
client.onGpsStatusChanged(gpsStatus, GpsStatusValue.GPS_NONE);
client = null; client = null;
if (gpsStatusRunner != null) { if (gpsStatusRunner != null) {
gpsStatusRunner.stop(); gpsStatusRunner.stop();
@@ -63,10 +63,6 @@ public class HandlerServer {
service.newGpsStatus(gpsStatusValue); service.newGpsStatus(gpsStatusValue);
} }
public GpsStatusValue getGpsStatus() {
return locationHandler.getGpsStatus();
}
public interface HandlerServerInterface { public interface HandlerServerInterface {
void newTrackPoint(TrackPoint trackPoint, int gpsAccuracy); void newTrackPoint(TrackPoint trackPoint, int gpsAccuracy);
void newGpsStatus(GpsStatusValue gpsStatusValue); void newGpsStatus(GpsStatusValue gpsStatusValue);
@@ -38,6 +38,7 @@ class LocationHandler implements HandlerServer.Handler, LocationListener, GpsSta
gpsStatus = new GpsStatus(context, this); gpsStatus = new GpsStatus(context, this);
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
registerLocationListener(); registerLocationListener();
gpsStatus.start();
} }
@Override @Override