mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-03 18:03:06 +02:00
@@ -9,12 +9,10 @@ import de.dennisguse.opentracks.data.models.Track;
|
||||
|
||||
public class RecordingStatus {
|
||||
private final Track.Id trackId;
|
||||
private final boolean paused;
|
||||
|
||||
@VisibleForTesting
|
||||
RecordingStatus(Track.Id trackId, boolean paused) {
|
||||
RecordingStatus(Track.Id trackId) {
|
||||
this.trackId = trackId;
|
||||
this.paused = paused;
|
||||
}
|
||||
|
||||
public Track.Id getTrackId() {
|
||||
@@ -25,24 +23,12 @@ public class RecordingStatus {
|
||||
return trackId != null;
|
||||
}
|
||||
|
||||
public boolean isPaused() {
|
||||
return paused;
|
||||
}
|
||||
|
||||
public boolean isRecordingAndNotPaused() {
|
||||
return isRecording() && !isPaused();
|
||||
}
|
||||
|
||||
static RecordingStatus notRecording() {
|
||||
return new RecordingStatus(null, false);
|
||||
return new RecordingStatus(null);
|
||||
}
|
||||
|
||||
static RecordingStatus record(@NonNull Track.Id trackId) {
|
||||
return new RecordingStatus(trackId, false);
|
||||
}
|
||||
|
||||
RecordingStatus pause() {
|
||||
return new RecordingStatus(getTrackId(), true);
|
||||
return new RecordingStatus(trackId);
|
||||
}
|
||||
|
||||
public RecordingStatus stop() {
|
||||
@@ -54,7 +40,6 @@ public class RecordingStatus {
|
||||
public String toString() {
|
||||
return "RecordingStatus{" +
|
||||
"trackId=" + trackId +
|
||||
", paused=" + paused +
|
||||
'}';
|
||||
}
|
||||
|
||||
@@ -63,11 +48,11 @@ public class RecordingStatus {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
RecordingStatus that = (RecordingStatus) o;
|
||||
return paused == that.paused && Objects.equals(trackId, that.trackId);
|
||||
return Objects.equals(trackId, that.trackId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(trackId, paused);
|
||||
return Objects.hash(trackId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,25 +82,23 @@ class TrackRecordingManager implements SharedPreferences.OnSharedPreferenceChang
|
||||
return trackId;
|
||||
}
|
||||
|
||||
//TODO Handle non-existing trackId? Start a new track or exception?
|
||||
void resumeExistingTrack(@NonNull Track.Id resumeTrackId, @NonNull TrackPointCreator trackPointCreator) {
|
||||
/**
|
||||
* @return if the recording could be started.
|
||||
*/
|
||||
boolean resumeExistingTrack(@NonNull Track.Id resumeTrackId, @NonNull TrackPointCreator trackPointCreator) {
|
||||
trackId = resumeTrackId;
|
||||
Track track = contentProviderUtils.getTrack(trackId);
|
||||
if (track == null) {
|
||||
Log.e(TAG, "Ignore resumeTrack. Track " + trackId.getId() + " does not exists.");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
trackStatisticsUpdater = new TrackStatisticsUpdater(track.getTrackStatistics());
|
||||
onNewTrackPoint(trackPointCreator.createSegmentStartManual());
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
void pause(TrackPointCreator trackPointCreator) {
|
||||
insertTrackPoint(trackPointCreator.createSegmentEnd(), true);
|
||||
|
||||
reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
void end(TrackPointCreator trackPointCreator) {
|
||||
|
||||
@@ -30,7 +30,6 @@ import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.data.models.Distance;
|
||||
import de.dennisguse.opentracks.data.models.Marker;
|
||||
import de.dennisguse.opentracks.data.models.Track;
|
||||
@@ -178,23 +177,16 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
||||
|
||||
public void resumeTrack(Track.Id trackId) {
|
||||
trackPointCreator.reset();
|
||||
trackRecordingManager.resumeExistingTrack(trackId, trackPointCreator);
|
||||
if (!trackRecordingManager.resumeExistingTrack(trackId, trackPointCreator)) {
|
||||
Log.w(TAG, "Cannot resume a non-existing track.");
|
||||
return;
|
||||
}
|
||||
|
||||
updateRecordingStatus(RecordingStatus.record(trackId));
|
||||
|
||||
startRecording();
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
|
||||
public void resumeCurrentTrack() {
|
||||
if (!isRecording() || !isPaused()) {
|
||||
Log.w(TAG, "Ignore resumeCurrentTrack. Not recording or not paused.");
|
||||
return;
|
||||
}
|
||||
|
||||
resumeTrack(recordingStatus.getTrackId());
|
||||
}
|
||||
|
||||
private void startRecording() {
|
||||
// Update instance variables
|
||||
handler.postDelayed(updateRecordingData, RECORDING_DATA_UPDATE_INTERVAL.toMillis());
|
||||
@@ -222,46 +214,18 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
||||
return;
|
||||
}
|
||||
|
||||
// Need to remember the recordingTrackId before setting it to null
|
||||
boolean wasPause = isPaused();
|
||||
Track.Id trackId = recordingStatus.getTrackId();
|
||||
|
||||
// Set recording status
|
||||
updateRecordingStatus(STATUS_DEFAULT);
|
||||
|
||||
if (!wasPause) {
|
||||
trackRecordingManager.end(trackPointCreator);
|
||||
}
|
||||
|
||||
endRecording(true);
|
||||
trackRecordingManager.end(trackPointCreator);
|
||||
endRecording();
|
||||
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
|
||||
public void pauseCurrentTrack() {
|
||||
if (!isRecording() || isPaused()) {
|
||||
Log.w(TAG, "Ignore pauseCurrentTrack. Not recording or paused.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set recording status
|
||||
updateRecordingStatus(recordingStatus.pause());
|
||||
|
||||
trackRecordingManager.pause(trackPointCreator);
|
||||
|
||||
endRecording(false);
|
||||
|
||||
notificationManager.updateContent(getString(R.string.generic_paused));
|
||||
}
|
||||
|
||||
private void endRecording(boolean trackStopped) {
|
||||
private void endRecording() {
|
||||
stopUpdateRecordingData();
|
||||
if (!trackStopped) {
|
||||
updateRecordingDataWhileRecording();
|
||||
} else {
|
||||
recordingDataObservable.postValue(NOT_RECORDING);
|
||||
}
|
||||
recordingDataObservable.postValue(NOT_RECORDING);
|
||||
|
||||
voiceAnnouncementManager.stop();
|
||||
|
||||
@@ -289,8 +253,8 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
||||
|
||||
@Override
|
||||
public boolean newTrackPoint(TrackPoint trackPoint, Distance thresholdHorizontalAccuracy) {
|
||||
if (!isRecording() || isPaused()) {
|
||||
Log.w(TAG, "Ignore newTrackPoint. Not recording or paused.");
|
||||
if (!isRecording()) {
|
||||
Log.w(TAG, "Ignore newTrackPoint. Not recording.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -323,7 +287,7 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
||||
}
|
||||
|
||||
public Marker.Id insertMarker(String name, String category, String description, String photoUrl) {
|
||||
if (!isRecording() || isPaused()) {
|
||||
if (!isRecording()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -398,9 +362,4 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
||||
public boolean isRecording() {
|
||||
return recordingStatus.isRecording();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public boolean isPaused() {
|
||||
return recordingStatus.isPaused();
|
||||
}
|
||||
}
|
||||
@@ -167,17 +167,6 @@ public class TrackRecordingServiceConnection implements ServiceConnection, Death
|
||||
setTrackRecordingService(null);
|
||||
}
|
||||
|
||||
public void resumeTrack() {
|
||||
if (trackRecordingService != null) {
|
||||
trackRecordingService.resumeCurrentTrack();
|
||||
}
|
||||
}
|
||||
public void pauseTrack() {
|
||||
if (trackRecordingService != null) {
|
||||
trackRecordingService.pauseCurrentTrack();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Marker.Id addMarker(Context context, String name, String category, String description, String photoUrl) {
|
||||
TrackRecordingService trackRecordingService = getServiceIfBound();
|
||||
|
||||
@@ -181,7 +181,7 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
insertMarkerMenuItem.setVisible(track != null && track.getId().equals(recordingStatus.getTrackId()) && !recordingStatus.isPaused());
|
||||
insertMarkerMenuItem.setVisible(track != null && track.getId().equals(recordingStatus.getTrackId()));
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user