Downloads are now cancelled on timeout

This commit is contained in:
Daniel Oeh 2012-05-28 01:16:56 +02:00
parent bc0b8fa1ef
commit ecc2ddb6e4
2 changed files with 24 additions and 3 deletions

View File

@ -87,7 +87,7 @@ public class DownloadObserver extends Thread {
}catch (Exception e) {
Log.e(TAG, "Error happened when calling client: " + e.getMessage());
}
cancelDownload();
requester.cancelDownload(context, id);
}
}
}catch (InterruptedException e) {
@ -102,8 +102,6 @@ public class DownloadObserver extends Thread {
this.client = callable;
}
private void cancelDownload() {}
public Cursor getDownloadCursor() {
DownloadManager.Query query = buildQuery(id);
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);

View File

@ -91,6 +91,29 @@ public class DownloadRequester {
true);
}
public void cancelDownload(final Context context, final long id) {
Log.d(TAG, "Cancelling download with id " + id);
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
int removed = manager.remove(id);
if (removed > 0) {
// Delete downloads in lists
Feed feed = getFeed(id);
if (feed != null) {
feeds.remove(feed);
} else {
FeedImage image = getFeedImage(id);
if (image != null) {
images.remove(image);
} else {
FeedMedia m = getFeedMedia(id);
if (media != null) {
media.remove(m);
}
}
}
}
}
/** Get a Feed by its download id */
public Feed getFeed(long id) {
for(FeedFile f: feeds) {