Downloads are now cancelled on timeout
This commit is contained in:
parent
bc0b8fa1ef
commit
ecc2ddb6e4
|
@ -87,7 +87,7 @@ public class DownloadObserver extends Thread {
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
Log.e(TAG, "Error happened when calling client: " + e.getMessage());
|
Log.e(TAG, "Error happened when calling client: " + e.getMessage());
|
||||||
}
|
}
|
||||||
cancelDownload();
|
requester.cancelDownload(context, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (InterruptedException e) {
|
}catch (InterruptedException e) {
|
||||||
|
@ -102,8 +102,6 @@ public class DownloadObserver extends Thread {
|
||||||
this.client = callable;
|
this.client = callable;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cancelDownload() {}
|
|
||||||
|
|
||||||
public Cursor getDownloadCursor() {
|
public Cursor getDownloadCursor() {
|
||||||
DownloadManager.Query query = buildQuery(id);
|
DownloadManager.Query query = buildQuery(id);
|
||||||
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||||
|
|
|
@ -91,6 +91,29 @@ public class DownloadRequester {
|
||||||
true);
|
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 */
|
/** Get a Feed by its download id */
|
||||||
public Feed getFeed(long id) {
|
public Feed getFeed(long id) {
|
||||||
for(FeedFile f: feeds) {
|
for(FeedFile f: feeds) {
|
||||||
|
|
Loading…
Reference in New Issue