Handle the case that sync is active while deleting all tracks

This commit is contained in:
Jimmy Shih
2013-07-12 14:26:09 -07:00
parent a6e9412a69
commit 64018fb02c
3 changed files with 40 additions and 6 deletions
@@ -76,6 +76,16 @@ public class DeleteAsyncTask extends AsyncTask<Void, Integer, Boolean> {
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
if (trackIds.length == 1 && trackIds[0] == -1L) {
try {
while (SyncUtils.isSyncActive(context)) {
if (isCancelled()) {
return false;
}
Thread.sleep(1000);
}
} catch (InterruptedException e) {
return false;
}
PreferencesUtils.setBoolean(
context, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
SyncUtils.disableSync(context);
@@ -84,9 +94,10 @@ public class DeleteAsyncTask extends AsyncTask<Void, Integer, Boolean> {
return true;
} else {
for (long id : trackIds) {
if (!isCancelled()) {
myTracksProviderUtils.deleteTrack(id);
if (isCancelled()) {
return false;
}
myTracksProviderUtils.deleteTrack(id);
}
return true;
}