Remember choice again in mobile download anyway prompt (#7436)

This commit is contained in:
Tony Tam 2024-10-04 13:35:43 -07:00 committed by GitHub
parent 141cbe946c
commit 361c754eb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 4 deletions

View File

@ -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);

View File

@ -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>