Cleanup: moved AggregatorGPS to GPSManager.

This commit is contained in:
Dennis Guse
2026-01-27 18:46:21 +01:00
parent 18ff96733e
commit 289e93eb5d
2 changed files with 30 additions and 15 deletions
@@ -43,6 +43,8 @@ public class GpsManager implements LocationListenerCompat, GpsStatusManager.GpsS
private Duration gpsInterval;
private Distance thresholdHorizontalAccuracy;
private AggregatorGPS aggregatorGPS;
public GpsManager(TrackPointCreator trackPointCreator, SensorManager observer) {
this.trackPointCreator = trackPointCreator;
this.observer = observer;
@@ -57,7 +59,7 @@ public class GpsManager implements LocationListenerCompat, GpsStatusManager.GpsS
gpsStatusManager = new GpsStatusManager(context, this, handler);
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
observer.onConnect(new AggregatorGPS("internal"));
this.aggregatorGPS = new AggregatorGPS("internal");
registerLocationListener();
gpsStatusManager.start();
@@ -79,12 +81,24 @@ public class GpsManager implements LocationListenerCompat, GpsStatusManager.GpsS
gpsStatusManager.stop();
gpsStatusManager = null;
observer.onDisconnect(new AggregatorGPS("internal"));
this.aggregatorGPS = null;
observer = null;
trackPointCreator = null;
}
//TODO Exposed for refactoring. Is this necessary?
@Deprecated
AggregatorGPS getAggregatorGPS() {
return aggregatorGPS;
}
//TODO Exposed for refactoring. This is very ugly.
@Deprecated
void setAggregatorGPS() {
this.aggregatorGPS = null;
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
boolean registerListener = false;
@@ -136,7 +150,8 @@ public class GpsManager implements LocationListenerCompat, GpsStatusManager.GpsS
return;
}
observer.onChange(position);
aggregatorGPS.add(observer.getNow(), position);
observer.onChange();
}
@Override
@@ -101,7 +101,7 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
if (cyclingPower != null) cyclingPower.resetAggregated();
if (runningDistanceSpeedCadence != null) runningDistanceSpeedCadence.resetAggregated();
if (barometer != null) barometer.resetAggregated();
if (gps != null) gps.resetAggregated();
if (gpsManager.getAggregatorGPS() != null) gpsManager.getAggregatorGPS().resetAggregated();
}
public GpsManager getGpsManager() {
@@ -169,8 +169,6 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
@VisibleForTesting
public AggregatorBarometer barometer;
public AggregatorGPS gps;
@VisibleForTesting
public SensorData<HeartRate> getHeartRate(Instant now) {
if (heartRate != null) {
@@ -227,6 +225,10 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
@Deprecated
public void onChange(Record data) {
update(data);
onChange();
}
public void onChange() {
observer.onChange();
}
@@ -266,10 +268,6 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
this.barometer.add(now, (AtmosphericPressure) value);
return;
}
if (value instanceof Position) {
this.gps.add(now, (Position) value);
return;
}
throw new UnsupportedOperationException(value.getClass().getCanonicalName());
}
@@ -289,10 +287,16 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
this.cyclingPower = null;
this.runningDistanceSpeedCadence = null;
this.barometer = null;
this.gps = null;
//TODO This is to ExportImportTest alive; refactor test.
if (this.gpsManager != null) {
this.gpsManager.setAggregatorGPS();
}
}
public SensorDataSet getSensorDataSet(Instant now) {
AggregatorGPS gps = gpsManager.getAggregatorGPS();
return new SensorDataSet(
gps != null && gps.hasReceivedData() ? gps.getAggregatedValueWithSensorName(now) : new SensorData<>(Position.of(now), ""),
getSpeed(now),
@@ -337,10 +341,6 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
barometer = (AggregatorBarometer) sensorData;
return;
}
if (type instanceof AggregatorGPS) {
gps = (AggregatorGPS) sensorData;
return;
}
throw new UnsupportedOperationException(type.getClass().getCanonicalName());
}