Downloads weren't cancelled properly
This commit is contained in:
parent
eab911c2ff
commit
8bca22eff9
|
@ -243,7 +243,7 @@ public class DownloadService extends Service {
|
|||
Log.d(TAG, "Cancelling download with url " + url);
|
||||
Downloader d = getDownloader(url);
|
||||
if (d != null) {
|
||||
d.interrupt();
|
||||
d.cancel();
|
||||
removeDownload(d);
|
||||
} else {
|
||||
Log.e(TAG, "Could not cancel download with url " + url);
|
||||
|
@ -251,7 +251,7 @@ public class DownloadService extends Service {
|
|||
|
||||
} else if (intent.getAction().equals(ACTION_CANCEL_ALL_DOWNLOADS)) {
|
||||
for (Downloader d : downloads) {
|
||||
d.interrupt();
|
||||
d.cancel();
|
||||
DownloadRequester.getInstance().removeDownload(
|
||||
d.getStatus().getFeedFile());
|
||||
d.getStatus().getFeedFile().setFile_url(null);
|
||||
|
|
|
@ -12,6 +12,8 @@ public abstract class Downloader extends Thread {
|
|||
private DownloadService downloadService;
|
||||
|
||||
protected boolean finished;
|
||||
|
||||
protected volatile boolean cancelled;
|
||||
|
||||
protected volatile DownloadStatus status;
|
||||
|
||||
|
@ -19,6 +21,7 @@ public abstract class Downloader extends Thread {
|
|||
super();
|
||||
this.downloadService = downloadService;
|
||||
this.status = status;
|
||||
this.cancelled = false;
|
||||
handler = new Handler();
|
||||
}
|
||||
|
||||
|
@ -55,5 +58,9 @@ public abstract class Downloader extends Thread {
|
|||
public DownloadStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
}
|
|
@ -65,14 +65,13 @@ public class HttpDownloader extends Downloader {
|
|||
publishProgress();
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Starting download");
|
||||
while ((count = in.read(buffer)) != -1
|
||||
&& !isInterrupted()) {
|
||||
while (!cancelled && (count = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, count);
|
||||
status.setSoFar(status.getSoFar() + count);
|
||||
status.setProgressPercent((int) (((double) status
|
||||
.getSoFar() / (double) status.getSize()) * 100));
|
||||
}
|
||||
if (isInterrupted()) {
|
||||
if (cancelled) {
|
||||
onCancelled();
|
||||
} else {
|
||||
onSuccess();
|
||||
|
|
Loading…
Reference in New Issue