mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Removed ignore_illegal_state string and code the uses it.
Removed the throwing of exceptions on start and stop of tracks and instead added checking to not run them.
This commit is contained in:
@@ -50,5 +50,4 @@ limitations under the License.
|
||||
<!-- Intent actions -->
|
||||
<string name="save_intent_action">android.intent.action.SAVE</string>
|
||||
<string name="open_settings_screen">android.intent.action.settings.OPEN</string>
|
||||
<string name="ignore_illegal_state">android.intent.extra.IGNORE_ILLEGAL_STATE</string>
|
||||
</resources>
|
||||
|
||||
@@ -290,14 +290,8 @@ public class TrackRecordingService extends Service {
|
||||
if (intent.getBooleanExtra(RESUME_TRACK_EXTRA_NAME, false)) {
|
||||
resumeTrack(startId);
|
||||
} else {
|
||||
try {
|
||||
// Process actions for controlling the service.
|
||||
processStartStopIntent(intent);
|
||||
} catch (IllegalStateException e) {
|
||||
/* Eat the exception if our sender says to ignore it, e.g., the Widget. */
|
||||
if (!intent.getBooleanExtra(getString(R.string.ignore_illegal_state), false))
|
||||
throw e;
|
||||
}
|
||||
// Process actions for controlling the service.
|
||||
processStartStopIntent(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,16 +299,24 @@ public class TrackRecordingService extends Service {
|
||||
String action = intent.getAction();
|
||||
|
||||
if (isNewTrackAction(action)) {
|
||||
boolean selectNewTrack = intent.getBooleanExtra(getString(R.string.select_new_track_extra), false);
|
||||
|
||||
startNewTrack();
|
||||
if (selectNewTrack) {
|
||||
prefManager.setSelectedTrack(recordingTrackId);
|
||||
if (!isTrackInProgress()) {
|
||||
boolean selectNewTrack = intent.getBooleanExtra(getString(R.string.select_new_track_extra), false);
|
||||
|
||||
startNewTrack();
|
||||
if (selectNewTrack) {
|
||||
prefManager.setSelectedTrack(recordingTrackId);
|
||||
}
|
||||
}
|
||||
} else if (isEndTrackAction(action)) {
|
||||
endCurrentTrack();
|
||||
if (isTrackInProgress()) {
|
||||
endCurrentTrack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTrackInProgress() {
|
||||
return recordingTrackId != -1 || isRecording;
|
||||
}
|
||||
|
||||
private boolean isNewTrackAction(String action) {
|
||||
return getString(R.string.start_new_track_action).equals(action);
|
||||
@@ -571,9 +573,6 @@ public class TrackRecordingService extends Service {
|
||||
|
||||
public long startNewTrack() {
|
||||
Log.d(TAG, "TrackRecordingService.startNewTrack");
|
||||
if (recordingTrackId != -1 || isRecording) {
|
||||
throw new IllegalStateException("A track is already in progress!");
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
acquireWakeLock();
|
||||
@@ -1009,9 +1008,6 @@ public class TrackRecordingService extends Service {
|
||||
|
||||
private void endCurrentTrack() {
|
||||
Log.d(TAG, "TrackRecordingService.endCurrentTrack");
|
||||
if (recordingTrackId == -1 || !isRecording) {
|
||||
throw new IllegalStateException("No recording track in progress!");
|
||||
}
|
||||
|
||||
announcementExecutor.shutdown();
|
||||
splitExecutor.shutdown();
|
||||
|
||||
@@ -198,11 +198,6 @@ public class TrackWidgetProvider
|
||||
private void setButtonIntent(
|
||||
RemoteViews views, Context context, int action, int icon, int extra) {
|
||||
Intent intent = new Intent(context, TrackRecordingService.class);
|
||||
|
||||
/* Keeps the TrackRecordingService from throwing back an exception in cases where
|
||||
* two of the same intents are sent from the user double taping on the widget. */
|
||||
intent.putExtra(context.getString(R.string.ignore_illegal_state), true);
|
||||
|
||||
intent.setAction(context.getString(action));
|
||||
if (extra != -1) {
|
||||
intent.putExtra(context.getString(extra), true);
|
||||
|
||||
Reference in New Issue
Block a user