diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2023-05-05 23:09:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-05 23:09:03 +0200 |
commit | 6d7bfef8a5fe8180f13904739996bb2b8de8a0d4 (patch) | |
tree | 84f246b74fe7254678788e9f206d81d1a30ffa5e /net/download | |
parent | 4c286931cd2dbd9038022f808f9d8a73ccbb6759 (diff) | |
download | AntennaPod-6d7bfef8a5fe8180f13904739996bb2b8de8a0d4.zip |
Download Service Rewrite (#6420)
Diffstat (limited to 'net/download')
2 files changed, 43 insertions, 11 deletions
diff --git a/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadServiceInterface.java b/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadServiceInterface.java index b5d0cd991..5fac79ce8 100644 --- a/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadServiceInterface.java +++ b/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadServiceInterface.java @@ -1,10 +1,20 @@ package de.danoeh.antennapod.net.download.serviceinterface; import android.content.Context; -import android.content.Intent; +import de.danoeh.antennapod.model.download.DownloadStatus; +import de.danoeh.antennapod.model.feed.FeedItem; + +import java.util.HashMap; +import java.util.Map; public abstract class DownloadServiceInterface { + public static final String WORK_TAG = "episodeDownload"; + public static final String WORK_TAG_EPISODE_URL = "episodeUrl:"; + public static final String WORK_DATA_PROGRESS = "progress"; + public static final String WORK_DATA_MEDIA_ID = "media_id"; + public static final String WORK_DATA_WAS_QUEUED = "was_queued"; private static DownloadServiceInterface impl; + private Map<String, DownloadStatus> currentDownloads = new HashMap<>(); public static DownloadServiceInterface get() { return impl; @@ -14,13 +24,35 @@ public abstract class DownloadServiceInterface { DownloadServiceInterface.impl = impl; } - public abstract void download(Context context, boolean cleanupMedia, DownloadRequest... requests); + public void setCurrentDownloads(Map<String, DownloadStatus> currentDownloads) { + this.currentDownloads = currentDownloads; + } - public abstract Intent makeDownloadIntent(Context context, boolean cleanupMedia, DownloadRequest... requests); + /** + * Download immediately after user action. + */ + public abstract void downloadNow(Context context, FeedItem item, boolean ignoreConstraints); - public abstract void refreshAllFeeds(Context context, boolean initiatedByUser); + /** + * Download when device seems fit. + */ + public abstract void download(Context context, FeedItem item); public abstract void cancel(Context context, String url); public abstract void cancelAll(Context context); + + public boolean isDownloadingEpisode(String url) { + return currentDownloads.containsKey(url) + && currentDownloads.get(url).getState() != DownloadStatus.STATE_COMPLETED; + } + + public boolean isEpisodeQueued(String url) { + return currentDownloads.containsKey(url) + && currentDownloads.get(url).getState() == DownloadStatus.STATE_QUEUED; + } + + public int getProgress(String url) { + return isDownloadingEpisode(url) ? currentDownloads.get(url).getProgress() : -1; + } } diff --git a/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadServiceInterfaceStub.java b/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadServiceInterfaceStub.java index 947746485..716d68d14 100644 --- a/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadServiceInterfaceStub.java +++ b/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadServiceInterfaceStub.java @@ -1,23 +1,23 @@ package de.danoeh.antennapod.net.download.serviceinterface; import android.content.Context; -import android.content.Intent; +import de.danoeh.antennapod.model.feed.FeedItem; public class DownloadServiceInterfaceStub extends DownloadServiceInterface { - public void download(Context context, boolean cleanupMedia, DownloadRequest... requests) { + @Override + public void downloadNow(Context context, FeedItem item, boolean ignoreConstraints) { } - public Intent makeDownloadIntent(Context context, boolean cleanupMedia, DownloadRequest... requests) { - return null; - } - - public void refreshAllFeeds(Context context, boolean initiatedByUser) { + @Override + public void download(Context context, FeedItem item) { } + @Override public void cancel(Context context, String url) { } + @Override public void cancelAll(Context context) { } } |