summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Tam <149837+tonytamsf@users.noreply.github.com>2024-10-04 13:35:43 -0700
committerGitHub <noreply@github.com>2024-10-04 22:35:43 +0200
commit361c754eb92e020303f31ca4c75fa881e0f68131 (patch)
tree0c1788fbdecfadaf9aec1233c70658a717e3ae9d
parent141cbe946c7ee1b21a55391bec5a1f008d90c221 (diff)
downloadAntennaPod-361c754eb92e020303f31ca4c75fa881e0f68131.zip
Remember choice again in mobile download anyway prompt (#7436)
-rw-r--r--app/src/main/java/de/danoeh/antennapod/actionbutton/DownloadActionButton.java29
-rw-r--r--ui/i18n/src/main/res/values/strings.xml1
2 files changed, 26 insertions, 4 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/actionbutton/DownloadActionButton.java b/app/src/main/java/de/danoeh/antennapod/actionbutton/DownloadActionButton.java
index 15f07d207..4a3545f21 100644
--- a/app/src/main/java/de/danoeh/antennapod/actionbutton/DownloadActionButton.java
+++ b/app/src/main/java/de/danoeh/antennapod/actionbutton/DownloadActionButton.java
@@ -2,6 +2,7 @@ package de.danoeh.antennapod.actionbutton;
import android.content.Context;
import android.view.View;
+import android.widget.Toast;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
@@ -16,6 +17,12 @@ import de.danoeh.antennapod.storage.preferences.UsageStatistics;
import de.danoeh.antennapod.net.common.NetworkUtils;
public class DownloadActionButton extends ItemActionButton {
+ private static final int TIMEOUT_NETWORK_WARN_SECONDS = 300;
+ private static final int BYPASS_TYPE_NOW = 1;
+ private static final int BYPASS_TYPE_LATER = 2;
+
+ private static int bypassCellularNetworkType = 0;
+ private static long bypassCellularNetworkWarningTimer = 0;
public DownloadActionButton(FeedItem item) {
super(item);
@@ -47,15 +54,29 @@ public class DownloadActionButton extends ItemActionButton {
UsageStatistics.logAction(UsageStatistics.ACTION_DOWNLOAD);
- if (NetworkUtils.isEpisodeDownloadAllowed()) {
- DownloadServiceInterface.get().downloadNow(context, item, false);
+ long timeSinceBypass = System.currentTimeMillis() / 1000 - bypassCellularNetworkWarningTimer;
+ boolean shouldBypass = timeSinceBypass < TIMEOUT_NETWORK_WARN_SECONDS;
+ if (shouldBypass && bypassCellularNetworkType == BYPASS_TYPE_NOW) {
+ Toast.makeText(context, context.getString(
+ R.string.mobile_download_notice, TIMEOUT_NETWORK_WARN_SECONDS / 60), Toast.LENGTH_LONG).show();
+ }
+ if (NetworkUtils.isEpisodeDownloadAllowed() || shouldBypass) {
+ DownloadServiceInterface.get().downloadNow(context, item, bypassCellularNetworkType == BYPASS_TYPE_NOW);
} else {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context)
.setTitle(R.string.confirm_mobile_download_dialog_title)
.setPositiveButton(R.string.confirm_mobile_download_dialog_download_later,
- (d, w) -> DownloadServiceInterface.get().downloadNow(context, item, false))
+ (d, w) -> {
+ bypassCellularNetworkType = BYPASS_TYPE_LATER;
+ bypassCellularNetworkWarningTimer = System.currentTimeMillis() / 1000;
+ DownloadServiceInterface.get().downloadNow(context, item, false);
+ })
.setNeutralButton(R.string.confirm_mobile_download_dialog_allow_this_time,
- (d, w) -> DownloadServiceInterface.get().downloadNow(context, item, true))
+ (d, w) -> {
+ bypassCellularNetworkType = BYPASS_TYPE_NOW;
+ bypassCellularNetworkWarningTimer = System.currentTimeMillis() / 1000;
+ DownloadServiceInterface.get().downloadNow(context, item, true);
+ })
.setNegativeButton(R.string.cancel_label, null);
if (NetworkUtils.isNetworkRestricted() && NetworkUtils.isVpnOverWifi()) {
builder.setMessage(R.string.confirm_mobile_download_dialog_message_vpn);
diff --git a/ui/i18n/src/main/res/values/strings.xml b/ui/i18n/src/main/res/values/strings.xml
index 1aa93c312..924421df8 100644
--- a/ui/i18n/src/main/res/values/strings.xml
+++ b/ui/i18n/src/main/res/values/strings.xml
@@ -325,6 +325,7 @@
<string name="confirm_mobile_download_dialog_message_vpn">Your VPN app pretends to be a mobile network (metered connection). Downloading over mobile data connection is disabled in the settings. If you want this problem to be fixed, contact the creators of your VPN app.</string>
<string name="confirm_mobile_download_dialog_download_later">Download later</string>
<string name="confirm_mobile_download_dialog_allow_this_time">Download anyway</string>
+ <string name="mobile_download_notice">Downloading over mobile data connection for the next %d minutes</string>
<string name="confirm_mobile_streaming_notification_title">Confirm mobile streaming</string>
<string name="confirm_mobile_streaming_notification_message">Streaming over mobile data connection is disabled in the settings. Tap to stream anyway.</string>
<string name="confirm_mobile_streaming_button_always">Always</string>