mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Allowing certain data hub operations to work even if not started yet.
This commit is contained in:
@@ -362,6 +362,12 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
Log.d(TAG, "MyTracks.onStart");
|
||||
super.onStart();
|
||||
dataHub.start();
|
||||
|
||||
// Ensure that service is running if we're supposed to be recording
|
||||
if (dataHub.isRecording()) {
|
||||
Intent startIntent = new Intent(this, TrackRecordingService.class);
|
||||
startService(startIntent);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.google.android.apps.mytracks.content.TrackPointsColumns;
|
||||
import com.google.android.apps.mytracks.content.TracksColumns;
|
||||
import com.google.android.apps.mytracks.content.Waypoint;
|
||||
import com.google.android.apps.mytracks.content.WaypointsColumns;
|
||||
import com.google.android.apps.mytracks.services.TrackRecordingService;
|
||||
import com.google.android.apps.mytracks.util.ApiFeatures;
|
||||
import com.google.android.apps.mytracks.util.LocationUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
@@ -281,17 +280,7 @@ public class TrackDataHub {
|
||||
started = true;
|
||||
|
||||
sharedPreferences.registerOnSharedPreferenceChangeListener(preferenceListener);
|
||||
selectedTrackId = sharedPreferences.getLong(SELECTED_TRACK_KEY, -1);
|
||||
recordingTrackId = sharedPreferences.getLong(RECORDING_TRACK_KEY, -1);
|
||||
useMetricUnits = sharedPreferences.getBoolean(METRIC_UNITS_KEY, true);
|
||||
reportSpeed = sharedPreferences.getBoolean(SPEED_REPORTING_KEY, true);
|
||||
minRequiredAccuracy = sharedPreferences.getInt(MIN_REQUIRED_ACCURACY_KEY,
|
||||
Constants.DEFAULT_MIN_REQUIRED_ACCURACY);
|
||||
|
||||
if (recordingTrackId > 0) {
|
||||
Intent startIntent = new Intent(context, TrackRecordingService.class);
|
||||
context.startService(startIntent);
|
||||
}
|
||||
loadSharedPreferences();
|
||||
|
||||
// This may or may not register internal listeners, depending on whether
|
||||
// we already had external listeners.
|
||||
@@ -302,6 +291,15 @@ public class TrackDataHub {
|
||||
reloadDataFor(getRegisteredListenerArray());
|
||||
}
|
||||
|
||||
private void loadSharedPreferences() {
|
||||
selectedTrackId = sharedPreferences.getLong(SELECTED_TRACK_KEY, -1);
|
||||
recordingTrackId = sharedPreferences.getLong(RECORDING_TRACK_KEY, -1);
|
||||
useMetricUnits = sharedPreferences.getBoolean(METRIC_UNITS_KEY, true);
|
||||
reportSpeed = sharedPreferences.getBoolean(SPEED_REPORTING_KEY, true);
|
||||
minRequiredAccuracy = sharedPreferences.getInt(MIN_REQUIRED_ACCURACY_KEY,
|
||||
Constants.DEFAULT_MIN_REQUIRED_ACCURACY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops listening to data sources and reporting the data to external
|
||||
* listeners.
|
||||
@@ -396,26 +394,31 @@ public class TrackDataHub {
|
||||
|
||||
/** Returns the ID of the currently-selected track. */
|
||||
public long getSelectedTrackId() {
|
||||
checkStarted();
|
||||
if (!started) {
|
||||
loadSharedPreferences();
|
||||
}
|
||||
return selectedTrackId;
|
||||
}
|
||||
|
||||
/** Returns whether there's a track currently selected. */
|
||||
public boolean isATrackSelected() {
|
||||
checkStarted();
|
||||
return selectedTrackId > 0;
|
||||
return getSelectedTrackId() > 0;
|
||||
}
|
||||
|
||||
/** Returns whether we're currently recording a track. */
|
||||
public boolean isRecording() {
|
||||
checkStarted();
|
||||
if (!started) {
|
||||
loadSharedPreferences();
|
||||
}
|
||||
return recordingTrackId > 0;
|
||||
}
|
||||
|
||||
/** Returns whether the selected track is still being recorded. */
|
||||
public boolean isRecordingSelected() {
|
||||
checkStarted();
|
||||
return isRecording() && recordingTrackId == selectedTrackId;
|
||||
if (!started) {
|
||||
loadSharedPreferences();
|
||||
}
|
||||
return recordingTrackId > 0 && recordingTrackId == selectedTrackId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user