Use DownloaderCallback instead of DownloadService reference
This commit is contained in:
parent
d531e03f33
commit
272dacab18
|
@ -308,7 +308,13 @@ public class DownloadService extends Service {
|
|||
|
||||
private Downloader getDownloader(DownloadStatus status) {
|
||||
if (URLUtil.isHttpUrl(status.getFeedFile().getDownload_url())) {
|
||||
return new HttpDownloader(this, status);
|
||||
return new HttpDownloader(new DownloaderCallback() {
|
||||
|
||||
@Override
|
||||
public void onDownloadCompleted(Downloader downloader) {
|
||||
DownloadService.this.onDownloadCompleted(downloader);
|
||||
}
|
||||
}, status);
|
||||
}
|
||||
Log.e(TAG, "Could not find appropriate downloader for "
|
||||
+ status.getFeedFile().getDownload_url());
|
||||
|
|
|
@ -8,7 +8,7 @@ import de.danoeh.antennapod.asynctask.DownloadStatus;
|
|||
public abstract class Downloader extends Thread {
|
||||
private static final String TAG = "Downloader";
|
||||
private Handler handler;
|
||||
private DownloadService downloadService;
|
||||
private DownloaderCallback downloaderCallback;
|
||||
|
||||
protected boolean finished;
|
||||
|
||||
|
@ -16,9 +16,9 @@ public abstract class Downloader extends Thread {
|
|||
|
||||
protected volatile DownloadStatus status;
|
||||
|
||||
public Downloader(DownloadService downloadService, DownloadStatus status) {
|
||||
public Downloader(DownloaderCallback downloaderCallback, DownloadStatus status) {
|
||||
super();
|
||||
this.downloadService = downloadService;
|
||||
this.downloaderCallback = downloaderCallback;
|
||||
this.status = status;
|
||||
this.status.setStatusMsg(R.string.download_pending);
|
||||
this.cancelled = false;
|
||||
|
@ -36,7 +36,7 @@ public abstract class Downloader extends Thread {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
downloadService.onDownloadCompleted(Downloader.this);
|
||||
downloaderCallback.onDownloadCompleted(Downloader.this);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package de.danoeh.antennapod.service.download;
|
||||
|
||||
/**
|
||||
* Callback used by the Downloader-classes to notify the requester that the
|
||||
* download has completed.
|
||||
*/
|
||||
public interface DownloaderCallback {
|
||||
|
||||
public void onDownloadCompleted(Downloader downloader);
|
||||
}
|
|
@ -32,8 +32,8 @@ public class HttpDownloader extends Downloader {
|
|||
private static final int BUFFER_SIZE = 8 * 1024;
|
||||
private static final int CONNECTION_TIMEOUT = 5000;
|
||||
|
||||
public HttpDownloader(DownloadService downloadService, DownloadStatus status) {
|
||||
super(downloadService, status);
|
||||
public HttpDownloader(DownloaderCallback downloaderCallback, DownloadStatus status) {
|
||||
super(downloaderCallback, status);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue