Made sure that cancelled/failed downloads are handled correctly
This commit is contained in:
parent
026efe29c3
commit
bcbc162412
|
@ -249,10 +249,6 @@ public class DownloadService extends Service {
|
|||
}
|
||||
|
||||
} else if (intent.getAction().equals(ACTION_CANCEL_ALL_DOWNLOADS)) {
|
||||
handler.post(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (Downloader d : downloads) {
|
||||
d.interrupt();
|
||||
DownloadRequester.getInstance().removeDownload(
|
||||
|
@ -262,10 +258,7 @@ public class DownloadService extends Service {
|
|||
Log.d(TAG, "Cancelled all downloads");
|
||||
}
|
||||
downloads.clear();
|
||||
sendBroadcast(new Intent(
|
||||
ACTION_DOWNLOADS_CONTENT_CHANGED));
|
||||
}
|
||||
});
|
||||
sendBroadcast(new Intent(ACTION_DOWNLOADS_CONTENT_CHANGED));
|
||||
|
||||
}
|
||||
queryDownloads();
|
||||
|
@ -327,7 +320,7 @@ public class DownloadService extends Service {
|
|||
|
||||
@SuppressLint("NewApi")
|
||||
public void onDownloadCompleted(final Downloader downloader) {
|
||||
AsyncTask<Void, Void, Void> handler = new AsyncTask<Void, Void, Void>() {
|
||||
final AsyncTask<Void, Void, Void> handlerTask = new AsyncTask<Void, Void, Void>() {
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
@ -359,13 +352,16 @@ public class DownloadService extends Service {
|
|||
}
|
||||
}
|
||||
removeDownload(downloader);
|
||||
if (!successful) {
|
||||
queryDownloads();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
handler.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
handlerTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
handler.execute();
|
||||
handlerTask.execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -374,18 +370,11 @@ public class DownloadService extends Service {
|
|||
* DownloadService list.
|
||||
*/
|
||||
private void removeDownload(final Downloader d) {
|
||||
handler.post(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
downloads.remove(d);
|
||||
DownloadRequester.getInstance().removeDownload(
|
||||
d.getStatus().getFeedFile());
|
||||
sendBroadcast(new Intent(ACTION_DOWNLOADS_CONTENT_CHANGED));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new DownloadStatus object to the list of completed downloads and
|
||||
|
|
|
@ -109,6 +109,7 @@ public class DownloadRequester {
|
|||
Log.d(TAG, "Cancelling download with url " + downloadUrl);
|
||||
Intent cancelIntent = new Intent(DownloadService.ACTION_CANCEL_DOWNLOAD);
|
||||
cancelIntent.putExtra(DownloadService.EXTRA_DOWNLOAD_URL, downloadUrl);
|
||||
context.sendBroadcast(cancelIntent);
|
||||
}
|
||||
|
||||
/** Cancels all running downloads */
|
||||
|
|
Loading…
Reference in New Issue