diff --git a/MyTracks/AndroidManifest.xml b/MyTracks/AndroidManifest.xml
index 5014d127d..df3986336 100755
--- a/MyTracks/AndroidManifest.xml
+++ b/MyTracks/AndroidManifest.xml
@@ -153,6 +153,7 @@ limitations under the License.
+
diff --git a/MyTracks/res/values/strings.xml b/MyTracks/res/values/strings.xml
index ba5ea27ac..9eebdfc91 100644
--- a/MyTracks/res/values/strings.xml
+++ b/MyTracks/res/values/strings.xml
@@ -2202,6 +2202,10 @@ limitations under the License.
The selected tracks and their markers will be permanently deleted from the device. If Google
Drive sync is enabled, this will also delete the tracks on Google Drive.
+
+ Deleting…
+
{
+
+ private DeleteActivity deleteActivity;
+ private final long[] trackIds;
+ private final Context context;
+
+ // true if the AsyncTask has completed
+ private boolean completed;
+
+ /**
+ * Creates an AsyncTask.
+ *
+ * @param deleteActivity the activity currently associated with this task
+ * @param trackIds the track ids to delete. To delete all, set to size 1 with
+ * trackIds[0] == -1L
+ */
+ public DeleteAsyncTask(DeleteActivity deleteActivity, long[] trackIds) {
+ this.deleteActivity = deleteActivity;
+ this.trackIds = trackIds;
+ context = deleteActivity.getApplicationContext();
+ completed = false;
+ }
+
+ /**
+ * Sets the current activity associated with this AyncTask.
+ *
+ * @param deleteActivity the current activity, can be null
+ */
+ public void setActivity(DeleteActivity deleteActivity) {
+ this.deleteActivity = deleteActivity;
+ if (completed && deleteActivity != null) {
+ deleteActivity.onAsyncTaskCompleted();
+ }
+ }
+
+ @Override
+ protected void onPreExecute() {
+ if (deleteActivity != null) {
+ deleteActivity.showProgressDialog();
+ }
+ }
+
+ @Override
+ protected Boolean doInBackground(Void... params) {
+ MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
+
+ if (trackIds.length == 1 && trackIds[0] == -1L) {
+ PreferencesUtils.setBoolean(
+ context, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
+ SyncUtils.disableSync(context);
+ SyncUtils.clearSyncState(context);
+ myTracksProviderUtils.deleteAllTracks();
+ return true;
+ } else {
+ for (long id : trackIds) {
+ if (!isCancelled()) {
+ myTracksProviderUtils.deleteTrack(id);
+ }
+ }
+ return true;
+ }
+ }
+
+ @Override
+ protected void onPostExecute(Boolean result) {
+ completed = true;
+ if (deleteActivity != null) {
+ deleteActivity.onAsyncTaskCompleted();
+ }
+ }
+}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/SearchListActivity.java b/MyTracks/src/com/google/android/apps/mytracks/SearchListActivity.java
index 47e9a1c6c..9492026fc 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/SearchListActivity.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/SearchListActivity.java
@@ -24,10 +24,9 @@ import com.google.android.apps.mytracks.content.SearchEngineProvider;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
+import com.google.android.apps.mytracks.fragments.ConfirmDeleteDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteMarkerDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteMarkerDialogFragment.DeleteMarkerCaller;
-import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment;
-import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment.DeleteTrackCaller;
import com.google.android.apps.mytracks.services.MyTracksLocationManager;
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
import com.google.android.apps.mytracks.stats.TripStatistics;
@@ -75,8 +74,7 @@ import java.util.SortedSet;
*
* @author Rodrigo Damazio
*/
-public class SearchListActivity extends AbstractSendToGoogleActivity
- implements DeleteTrackCaller, DeleteMarkerCaller {
+public class SearchListActivity extends AbstractSendToGoogleActivity implements DeleteMarkerCaller {
private static final String TAG = SearchListActivity.class.getSimpleName();
@@ -372,8 +370,8 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
DeleteMarkerDialogFragment.newInstance(new long[] { markerId }).show(
getSupportFragmentManager(), DeleteMarkerDialogFragment.DELETE_MARKER_DIALOG_TAG);
} else {
- DeleteTrackDialogFragment.newInstance(false, new long[] { trackId })
- .show(getSupportFragmentManager(), DeleteTrackDialogFragment.DELETE_TRACK_DIALOG_TAG);
+ ConfirmDeleteDialogFragment.newInstance(new long[] { trackId })
+ .show(getSupportFragmentManager(), ConfirmDeleteDialogFragment.CONFIRM_DELETE_DIALOG_TAG);
}
return true;
default:
@@ -527,21 +525,6 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
resultMap.put(MARKER_ID_FIELD, null);
}
- @Override
- public TrackRecordingServiceConnection getTrackRecordingServiceConnection() {
- return trackRecordingServiceConnection;
- }
-
- @Override
- public void onDeleteTrackDone() {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- handleIntent(getIntent());
- }
- });
- }
-
@Override
public void onDeleteMarkerDone() {
runOnUiThread(new Runnable() {
@@ -551,4 +534,19 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
}
});
}
+
+ @Override
+ protected TrackRecordingServiceConnection getTrackRecordingServiceConnection() {
+ return trackRecordingServiceConnection;
+ }
+
+ @Override
+ protected void onDeleted() {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ handleIntent(getIntent());
+ }
+ });
+ }
}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java
index 50d89fd1d..ee623d82b 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java
@@ -22,8 +22,7 @@ import com.google.android.apps.mytracks.content.TrackDataHub;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
import com.google.android.apps.mytracks.fragments.ChartFragment;
-import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment;
-import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment.DeleteTrackCaller;
+import com.google.android.apps.mytracks.fragments.ConfirmDeleteDialogFragment;
import com.google.android.apps.mytracks.fragments.ExportDialogFragment;
import com.google.android.apps.mytracks.fragments.ExportDialogFragment.ExportCaller;
import com.google.android.apps.mytracks.fragments.ExportDialogFragment.ExportType;
@@ -67,8 +66,7 @@ import java.util.Locale;
* @author Leif Hendrik Wilden
* @author Rodrigo Damazio
*/
-public class TrackDetailActivity extends AbstractSendToGoogleActivity
- implements ExportCaller, DeleteTrackCaller {
+public class TrackDetailActivity extends AbstractSendToGoogleActivity implements ExportCaller {
public static final String EXTRA_TRACK_ID = "track_id";
public static final String EXTRA_MARKER_ID = "marker_id";
@@ -368,8 +366,8 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
startActivity(intent);
return true;
case R.id.track_detail_delete:
- DeleteTrackDialogFragment.newInstance(false, new long[] { trackId })
- .show(getSupportFragmentManager(), DeleteTrackDialogFragment.DELETE_TRACK_DIALOG_TAG);
+ ConfirmDeleteDialogFragment.newInstance(new long[] { trackId })
+ .show(getSupportFragmentManager(), ConfirmDeleteDialogFragment.CONFIRM_DELETE_DIALOG_TAG);
return true;
case R.id.track_detail_sensor_state:
intent = IntentUtils.newIntent(this, SensorStateActivity.class);
@@ -434,12 +432,12 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
}
@Override
- public TrackRecordingServiceConnection getTrackRecordingServiceConnection() {
+ protected TrackRecordingServiceConnection getTrackRecordingServiceConnection() {
return trackRecordingServiceConnection;
}
@Override
- public void onDeleteTrackDone() {
+ protected void onDeleted() {
runOnUiThread(new Runnable() {
@Override
public void run() {
diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java
index 9aa89f371..4e46d5484 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java
@@ -19,8 +19,7 @@ package com.google.android.apps.mytracks;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.TracksColumns;
-import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment;
-import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment.DeleteTrackCaller;
+import com.google.android.apps.mytracks.fragments.ConfirmDeleteDialogFragment;
import com.google.android.apps.mytracks.fragments.EnableSyncDialogFragment;
import com.google.android.apps.mytracks.fragments.EnableSyncDialogFragment.EnableSyncCaller;
import com.google.android.apps.mytracks.fragments.EulaDialogFragment;
@@ -93,7 +92,7 @@ import java.util.Locale;
* @author Leif Hendrik Wilden
*/
public class TrackListActivity extends AbstractSendToGoogleActivity
- implements EulaCaller, EnableSyncCaller, DeleteTrackCaller, FileTypeCaller {
+ implements EulaCaller, EnableSyncCaller, FileTypeCaller {
private static final String TAG = TrackListActivity.class.getSimpleName();
private static final int GOOGLE_PLAY_SERVICES_REQUEST_CODE = 0;
@@ -561,8 +560,8 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
.show(getSupportFragmentManager(), FileTypeDialogFragment.FILE_TYPE_DIALOG_TAG);
return true;
case R.id.track_list_delete_all:
- DeleteTrackDialogFragment.newInstance(true, new long[] {})
- .show(getSupportFragmentManager(), DeleteTrackDialogFragment.DELETE_TRACK_DIALOG_TAG);
+ ConfirmDeleteDialogFragment.newInstance(new long[] {-1L})
+ .show(getSupportFragmentManager(), ConfirmDeleteDialogFragment.CONFIRM_DELETE_DIALOG_TAG);
return true;
case R.id.track_list_settings:
intent = IntentUtils.newIntent(this, SettingsActivity.class);
@@ -617,12 +616,12 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
};
@Override
- public TrackRecordingServiceConnection getTrackRecordingServiceConnection() {
+ protected TrackRecordingServiceConnection getTrackRecordingServiceConnection() {
return trackRecordingServiceConnection;
}
@Override
- public void onDeleteTrackDone() {
+ protected void onDeleted() {
// Do nothing
}
@@ -634,7 +633,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
AnalyticsUtils.sendPageViews(
this, "/action/save_all_" + trackFileFormat.name().toLowerCase(Locale.US));
intent = IntentUtils.newIntent(this, SaveActivity.class)
- .putExtra(SaveActivity.EXTRA_SAVE_ALL, true)
+ .putExtra(SaveActivity.EXTRA_TRACK_IDS, new long[] {-1L})
.putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat);
startActivity(intent);
break;
@@ -788,9 +787,11 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
startActivity(intent);
return true;
case R.id.list_context_menu_delete:
- boolean deleteAll = trackIds.length > 1 && trackIds.length == listView.getCount();
- DeleteTrackDialogFragment.newInstance(deleteAll, trackIds)
- .show(getSupportFragmentManager(), DeleteTrackDialogFragment.DELETE_TRACK_DIALOG_TAG);
+ if (trackIds.length > 1 && trackIds.length == listView.getCount()) {
+ trackIds = new long[] {-1L};
+ }
+ ConfirmDeleteDialogFragment.newInstance(trackIds)
+ .show(getSupportFragmentManager(), ConfirmDeleteDialogFragment.CONFIRM_DELETE_DIALOG_TAG);
return true;
case R.id.list_context_menu_select_all:
int size = listView.getCount();
diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/ConfirmDeleteDialogFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/ConfirmDeleteDialogFragment.java
new file mode 100644
index 000000000..05a8a9e51
--- /dev/null
+++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/ConfirmDeleteDialogFragment.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.google.android.apps.mytracks.fragments;
+
+import com.google.android.apps.mytracks.util.DialogUtils;
+import com.google.android.maps.mytracks.R;
+
+import android.app.Activity;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
+
+/**
+ * A DialogFragment to confirm delete.
+ *
+ * @author Jimmy Shih
+ */
+public class ConfirmDeleteDialogFragment extends DialogFragment {
+
+ /**
+ * Interface for caller of this dialog fragment.
+ *
+ * @author Jimmy Shih
+ */
+ public interface ConfirmDeleteCaller {
+
+ /**
+ * Called when confirm delete is done.
+ *
+ * @param trackIds list of track ids to delete. To delete all, set to size 1
+ * with trackIds[0] == -1L
+ */
+ public void onConfirmDeleteDone(long[] trackIds);
+ }
+
+ public static final String CONFIRM_DELETE_DIALOG_TAG = "confirmDeleteDialog";
+ private static final String KEY_TRACK_IDS = "trackIds";
+
+ /**
+ * Create a new instance.
+ *
+ * @param trackIds list of track ids to delete. To delete all, set to size 1
+ * with trackIds[0] == -1L
+ */
+ public static ConfirmDeleteDialogFragment newInstance(long[] trackIds) {
+ Bundle bundle = new Bundle();
+ bundle.putLongArray(KEY_TRACK_IDS, trackIds);
+
+ ConfirmDeleteDialogFragment deleteTrackDialogFragment = new ConfirmDeleteDialogFragment();
+ deleteTrackDialogFragment.setArguments(bundle);
+ return deleteTrackDialogFragment;
+ }
+
+ private ConfirmDeleteCaller caller;
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ try {
+ caller = (ConfirmDeleteCaller) activity;
+ } catch (ClassCastException e) {
+ throw new ClassCastException(
+ activity.toString() + " must implement " + ConfirmDeleteCaller.class.getSimpleName());
+ }
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ final long[] trackIds = getArguments().getLongArray(KEY_TRACK_IDS);
+ int messageId;
+ if (trackIds.length == 1 && trackIds[0] == -1L) {
+ messageId = R.string.track_delete_all_confirm_message;
+ } else {
+ messageId = trackIds.length > 1 ? R.string.track_delete_multiple_confirm_message
+ : R.string.track_delete_one_confirm_message;
+ }
+ return DialogUtils.createConfirmationDialog(
+ getActivity(), messageId, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ caller.onConfirmDeleteDone(trackIds);
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/DeleteTrackDialogFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/DeleteTrackDialogFragment.java
deleted file mode 100644
index ea28a29ce..000000000
--- a/MyTracks/src/com/google/android/apps/mytracks/fragments/DeleteTrackDialogFragment.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright 2012 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.google.android.apps.mytracks.fragments;
-
-import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
-import com.google.android.apps.mytracks.io.sync.SyncUtils;
-import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
-import com.google.android.apps.mytracks.util.DialogUtils;
-import com.google.android.apps.mytracks.util.PreferencesUtils;
-import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils;
-import com.google.android.maps.mytracks.R;
-
-import android.app.Activity;
-import android.app.Dialog;
-import android.content.DialogInterface;
-import android.os.Bundle;
-import android.support.v4.app.DialogFragment;
-import android.support.v4.app.FragmentActivity;
-
-/**
- * A DialogFragment to track.
- *
- * @author Jimmy Shih
- */
-public class DeleteTrackDialogFragment extends DialogFragment {
-
- /**
- * Interface for caller of this dialog fragment.
- *
- * @author Jimmy Shih
- */
- public interface DeleteTrackCaller {
-
- /**
- * Gets the track recording service connection.
- */
- public TrackRecordingServiceConnection getTrackRecordingServiceConnection();
-
- /**
- * Called when delete track is done.
- */
- public void onDeleteTrackDone();
- }
-
- public static final String DELETE_TRACK_DIALOG_TAG = "deleteTrackDialog";
- private static final String KEY_DELETE_ALL = "deleteAll";
- private static final String KEY_TRACK_IDS = "trackIds";
-
- /**
- * Create a new instance.
- *
- * @param deleteAll true to delete all tracks
- * @param trackIds list of track ids to delete when deleteAll if false
- */
- public static DeleteTrackDialogFragment newInstance(boolean deleteAll, long[] trackIds) {
- Bundle bundle = new Bundle();
- bundle.putBoolean(KEY_DELETE_ALL, deleteAll);
- bundle.putLongArray(KEY_TRACK_IDS, trackIds);
-
- DeleteTrackDialogFragment deleteTrackDialogFragment = new DeleteTrackDialogFragment();
- deleteTrackDialogFragment.setArguments(bundle);
- return deleteTrackDialogFragment;
- }
-
- private DeleteTrackCaller caller;
-
- @Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
- try {
- caller = (DeleteTrackCaller) activity;
- } catch (ClassCastException e) {
- throw new ClassCastException(
- activity.toString() + " must implement " + DeleteTrackCaller.class.getSimpleName());
- }
- }
-
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- boolean deleteAll = getArguments().getBoolean(KEY_DELETE_ALL);
- final FragmentActivity fragmentActivity = getActivity();
- if (deleteAll) {
- return DialogUtils.createConfirmationDialog(fragmentActivity,
- R.string.track_delete_all_confirm_message, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- PreferencesUtils.setBoolean(fragmentActivity, R.string.drive_sync_key,
- PreferencesUtils.DRIVE_SYNC_DEFAULT);
- SyncUtils.disableSync(fragmentActivity);
- SyncUtils.clearSyncState(fragmentActivity);
- MyTracksProviderUtils.Factory.get(fragmentActivity).deleteAllTracks();
- caller.onDeleteTrackDone();
- }
- }).start();
- }
- });
- } else {
- final long[] trackIds = getArguments().getLongArray(KEY_TRACK_IDS);
- int messageId = trackIds.length > 1 ? R.string.track_delete_multiple_confirm_message
- : R.string.track_delete_one_confirm_message;
- return DialogUtils.createConfirmationDialog(
- fragmentActivity, messageId, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- for (long trackId : trackIds) {
- if (trackId == PreferencesUtils.getLong(
- fragmentActivity, R.string.recording_track_id_key)) {
- TrackRecordingServiceConnectionUtils.stopRecording(
- fragmentActivity, caller.getTrackRecordingServiceConnection(), false);
- }
- }
- new Thread(new Runnable() {
- @Override
- public void run() {
- for (long id : trackIds) {
- MyTracksProviderUtils.Factory.get(fragmentActivity).deleteTrack(id);
- }
- caller.onDeleteTrackDone();
- }
- }).start();
- }
- });
- }
- }
-}
\ No newline at end of file
diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveActivity.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveActivity.java
index 0bf75a626..1816a32aa 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveActivity.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveActivity.java
@@ -42,7 +42,6 @@ import java.io.File;
public class SaveActivity extends Activity {
public static final String EXTRA_TRACK_FILE_FORMAT = "track_file_format";
- public static final String EXTRA_SAVE_ALL = "save_all";
public static final String EXTRA_TRACK_IDS = "track_ids";
public static final String EXTRA_PLAY_TRACK = "play_track";
@@ -72,7 +71,6 @@ public class SaveActivity extends Activity {
Intent intent = getIntent();
trackFileFormat = intent.getParcelableExtra(EXTRA_TRACK_FILE_FORMAT);
- boolean saveAll = intent.getBooleanExtra(EXTRA_SAVE_ALL, false);
trackIds = intent.getLongArrayExtra(EXTRA_TRACK_IDS);
playTrack = intent.getBooleanExtra(EXTRA_PLAY_TRACK, false);
@@ -101,7 +99,7 @@ public class SaveActivity extends Activity {
saveAsyncTask = (SaveAsyncTask) retained;
saveAsyncTask.setActivity(this);
} else {
- saveAsyncTask = new SaveAsyncTask(this, trackFileFormat, saveAll, trackIds, directory);
+ saveAsyncTask = new SaveAsyncTask(this, trackFileFormat, trackIds, directory);
saveAsyncTask.execute();
}
}
@@ -164,7 +162,7 @@ public class SaveActivity extends Activity {
finish();
}
}).setTitle(titleId);
- if (!playTrack && trackIds != null && trackIds.length == 1 && successCount == totalCount
+ if (!playTrack && trackIds.length == 1 && trackIds[0] != -1L && successCount == totalCount
&& savedPath != null) {
builder.setNegativeButton(
R.string.share_track_share_file, new DialogInterface.OnClickListener() {
diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveAsyncTask.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveAsyncTask.java
index 167999474..89236f6bd 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveAsyncTask.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveAsyncTask.java
@@ -46,7 +46,6 @@ public class SaveAsyncTask extends AsyncTask {
private SaveActivity saveActivity;
private final TrackFileFormat trackFileFormat;
- private final boolean saveAll;
private final long[] trackIds;
private final File directory;
private final Context context;
@@ -72,15 +71,14 @@ public class SaveAsyncTask extends AsyncTask {
*
* @param saveActivity the activity currently associated with this task
* @param trackFileFormat the track file format
- * @param saveAll true to save all the tracks
- * @param trackIds the track ids to save. null if saveAll if true
+ * @param trackIds the track ids to save. To save all, set to size 1 with
+ * trackIds[0] == -1L
* @param directory the directory to save to
*/
- public SaveAsyncTask(SaveActivity saveActivity, TrackFileFormat trackFileFormat, boolean saveAll,
- long[] trackIds, File directory) {
+ public SaveAsyncTask(
+ SaveActivity saveActivity, TrackFileFormat trackFileFormat, long[] trackIds, File directory) {
this.saveActivity = saveActivity;
this.trackFileFormat = trackFileFormat;
- this.saveAll = saveAll;
this.trackIds = trackIds;
this.directory = directory;
context = saveActivity.getApplicationContext();
@@ -122,13 +120,10 @@ public class SaveAsyncTask extends AsyncTask {
if (!isRecording || isPaused) {
wakeLock = SystemUtils.acquireWakeLock(saveActivity, wakeLock);
}
- if (saveAll) {
+ if (trackIds.length == 1 && trackIds[0] == -1L) {
return saveAllTracks();
} else {
totalCount = 1;
- if (trackIds == null) {
- return false;
- }
Track[] tracks = new Track[trackIds.length];
for (int i = 0; i < trackIds.length; i++) {
tracks[i] = myTracksProviderUtils.getTrack(trackIds[i]);
@@ -199,7 +194,7 @@ public class SaveAsyncTask extends AsyncTask {
* If only saving one track, update the progress dialog once every
* 500 points
*/
- if (trackIds != null && trackIds.length == 1 && number % 500 == 0) {
+ if (trackIds.length == 1 && trackIds[0] != -1L && number % 500 == 0) {
publishProgress(number, max);
}
}