diff --git a/src/de/danoeh/antennapod/service/download/DownloadService.java b/src/de/danoeh/antennapod/service/download/DownloadService.java index 6da651838..d0e9e03ff 100644 --- a/src/de/danoeh/antennapod/service/download/DownloadService.java +++ b/src/de/danoeh/antennapod/service/download/DownloadService.java @@ -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()); diff --git a/src/de/danoeh/antennapod/service/download/Downloader.java b/src/de/danoeh/antennapod/service/download/Downloader.java index d4e7009bf..9eb336e5c 100644 --- a/src/de/danoeh/antennapod/service/download/Downloader.java +++ b/src/de/danoeh/antennapod/service/download/Downloader.java @@ -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); } }); diff --git a/src/de/danoeh/antennapod/service/download/DownloaderCallback.java b/src/de/danoeh/antennapod/service/download/DownloaderCallback.java new file mode 100644 index 000000000..08420e83a --- /dev/null +++ b/src/de/danoeh/antennapod/service/download/DownloaderCallback.java @@ -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); +} diff --git a/src/de/danoeh/antennapod/service/download/HttpDownloader.java b/src/de/danoeh/antennapod/service/download/HttpDownloader.java index 7e419ae3c..e927c8296 100644 --- a/src/de/danoeh/antennapod/service/download/HttpDownloader.java +++ b/src/de/danoeh/antennapod/service/download/HttpDownloader.java @@ -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); } /**