summaryrefslogtreecommitdiff
path: root/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2022-01-06 14:36:11 +0100
committerGitHub <noreply@github.com>2022-01-06 14:36:11 +0100
commit849bf4ad854973d39698613c3a356c09c87e687c (patch)
treefbd07d17fe5f26b8c91f9ce4ff8020046070431f /app/src/main/java/de/danoeh/antennapod/adapter/actionbutton
parent8252eb2183c6a478fdfd9317586c8800a24054ca (diff)
downloadAntennaPod-849bf4ad854973d39698613c3a356c09c87e687c.zip
Rewrite download request creation (#5530)
Android has a limit on the size of Intent parameters. When enqueuing a huge number of items, it just ignored the argument and did not call onNewIntent. We now load the list over in DownloadService.
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/adapter/actionbutton')
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/CancelDownloadActionButton.java4
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java30
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/ItemActionButton.java4
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java12
4 files changed, 14 insertions, 36 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/CancelDownloadActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/CancelDownloadActionButton.java
index a2b0e98c3..636c974d9 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/CancelDownloadActionButton.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/CancelDownloadActionButton.java
@@ -5,11 +5,11 @@ import androidx.annotation.DrawableRes;
import androidx.annotation.StringRes;
import de.danoeh.antennapod.R;
+import de.danoeh.antennapod.core.service.download.DownloadService;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.model.feed.FeedMedia;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DBWriter;
-import de.danoeh.antennapod.core.storage.DownloadRequester;
public class CancelDownloadActionButton extends ItemActionButton {
@@ -32,7 +32,7 @@ public class CancelDownloadActionButton extends ItemActionButton {
@Override
public void onClick(Context context) {
FeedMedia media = item.getMedia();
- DownloadRequester.getInstance().cancelDownload(context, media);
+ DownloadService.cancel(context, media.getDownload_url());
if (UserPreferences.isEnableAutodownload()) {
item.disableAutoDownload();
DBWriter.setFeedItem(item);
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java
index 7b922154e..553512882 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java
@@ -9,21 +9,18 @@ import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import de.danoeh.antennapod.R;
-import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
+import de.danoeh.antennapod.core.service.download.DownloadRequestCreator;
+import de.danoeh.antennapod.core.service.download.DownloadService;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.model.feed.FeedMedia;
import de.danoeh.antennapod.core.preferences.UsageStatistics;
import de.danoeh.antennapod.core.storage.DBWriter;
-import de.danoeh.antennapod.core.storage.DownloadRequestException;
-import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.core.util.NetworkUtils;
public class DownloadActionButton extends ItemActionButton {
- private boolean isInQueue;
public DownloadActionButton(FeedItem item) {
super(item);
- this.isInQueue = item.isTagged(FeedItem.TAG_QUEUE);;
}
@Override
@@ -53,30 +50,17 @@ public class DownloadActionButton extends ItemActionButton {
UsageStatistics.logAction(UsageStatistics.ACTION_DOWNLOAD);
if (NetworkUtils.isEpisodeDownloadAllowed() || MobileDownloadHelper.userAllowedMobileDownloads()) {
- downloadEpisode(context);
- } else if (MobileDownloadHelper.userChoseAddToQueue() && !isInQueue) {
- addEpisodeToQueue(context);
+ DownloadService.download(context, false, DownloadRequestCreator.create(item.getMedia()).build());
+ } else if (MobileDownloadHelper.userChoseAddToQueue() && !item.isTagged(FeedItem.TAG_QUEUE)) {
+ DBWriter.addQueueItem(context, item);
+ Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show();
} else {
MobileDownloadHelper.confirmMobileDownload(context, item);
}
}
private boolean shouldNotDownload(@NonNull FeedMedia media) {
- boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media);
+ boolean isDownloading = DownloadService.isDownloadingFile(media.getDownload_url());
return isDownloading || media.isDownloaded();
}
-
- private void addEpisodeToQueue(Context context) {
- DBWriter.addQueueItem(context, item);
- Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show();
- }
-
- private void downloadEpisode(Context context) {
- try {
- DownloadRequester.getInstance().downloadMedia(context, true, item);
- } catch (DownloadRequestException e) {
- e.printStackTrace();
- DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
- }
- }
}
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/ItemActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/ItemActionButton.java
index ad4f35786..5581ca0c6 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/ItemActionButton.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/ItemActionButton.java
@@ -7,10 +7,10 @@ import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import android.view.View;
+import de.danoeh.antennapod.core.service.download.DownloadService;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.model.feed.FeedMedia;
import de.danoeh.antennapod.core.preferences.UserPreferences;
-import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.core.util.FeedItemUtil;
public abstract class ItemActionButton {
@@ -39,7 +39,7 @@ public abstract class ItemActionButton {
return new MarkAsPlayedActionButton(item);
}
- final boolean isDownloadingMedia = DownloadRequester.getInstance().isDownloadingFile(media);
+ final boolean isDownloadingMedia = DownloadService.isDownloadingFile(media.getDownload_url());
if (FeedItemUtil.isCurrentlyPlaying(media)) {
return new PauseActionButton(item);
} else if (item.getFeed().isLocalFeed()) {
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java
index 66ce973e2..6d8af23c0 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java
@@ -4,12 +4,11 @@ import android.content.Context;
import androidx.appcompat.app.AlertDialog;
import de.danoeh.antennapod.R;
-import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
+import de.danoeh.antennapod.core.service.download.DownloadRequestCreator;
+import de.danoeh.antennapod.core.service.download.DownloadService;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter;
-import de.danoeh.antennapod.core.storage.DownloadRequestException;
-import de.danoeh.antennapod.core.storage.DownloadRequester;
class MobileDownloadHelper {
private static long addToQueueTimestamp;
@@ -45,11 +44,6 @@ class MobileDownloadHelper {
private static void downloadFeedItems(Context context, FeedItem item) {
allowMobileDownloadTimestamp = System.currentTimeMillis();
- try {
- DownloadRequester.getInstance().downloadMedia(context, true, item);
- } catch (DownloadRequestException e) {
- e.printStackTrace();
- DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
- }
+ DownloadService.download(context, true, DownloadRequestCreator.create(item.getMedia()).build());
}
} \ No newline at end of file