Show confirmation dialog when downloading over mobile data connection is disabled
This commit is contained in:
parent
f8bb78d436
commit
fd7cdd3c71
|
@ -1,6 +1,8 @@
|
|||
package de.danoeh.antennapod.adapter;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -10,22 +12,31 @@ import de.danoeh.antennapod.R;
|
|||
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||
import de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction;
|
||||
import de.danoeh.antennapod.core.preferences.GpodnetPreferences;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Default implementation of an ActionButtonCallback
|
||||
*/
|
||||
public class DefaultActionButtonCallback implements ActionButtonCallback {
|
||||
|
||||
private static final String TAG = "DefaultActionButtonCallback";
|
||||
|
||||
private final Context context;
|
||||
|
||||
private final int TEN_MINUTES_IN_MILLIS = 60 * 1000 * 10;
|
||||
|
||||
// remember timestamp when user allowed downloading via mobile connection
|
||||
private static long allowMobileDownloadsTimestamp;
|
||||
private static long onlyAddToQueueTimeStamp;
|
||||
|
||||
public DefaultActionButtonCallback(Context context) {
|
||||
Validate.notNull(context);
|
||||
this.context = context;
|
||||
|
@ -34,17 +45,26 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
|
|||
@Override
|
||||
public void onActionButtonPressed(final FeedItem item) {
|
||||
|
||||
|
||||
if (item.hasMedia()) {
|
||||
final FeedMedia media = item.getMedia();
|
||||
boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media);
|
||||
if (!isDownloading && !media.isDownloaded()) {
|
||||
try {
|
||||
DBTasks.downloadFeedItems(context, item);
|
||||
Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
|
||||
} catch (DownloadRequestException e) {
|
||||
e.printStackTrace();
|
||||
DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
|
||||
if (UserPreferences.isAllowMobileUpdate() || NetworkUtils.connectedToWifi(context) ||
|
||||
(System.currentTimeMillis()-allowMobileDownloadsTimestamp) < TEN_MINUTES_IN_MILLIS) {
|
||||
try {
|
||||
DBTasks.downloadFeedItems(context, item);
|
||||
Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
|
||||
} catch (DownloadRequestException e) {
|
||||
e.printStackTrace();
|
||||
DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
|
||||
}
|
||||
} else {
|
||||
if(System.currentTimeMillis() - onlyAddToQueueTimeStamp < TEN_MINUTES_IN_MILLIS) {
|
||||
DBWriter.addQueueItem(context, item.getId());
|
||||
Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
confirmMobileDownload(context, item);
|
||||
}
|
||||
}
|
||||
} else if (isDownloading) {
|
||||
DownloadRequester.getInstance().cancelDownload(context, media);
|
||||
|
@ -79,4 +99,37 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void confirmMobileDownload(final Context context, final FeedItem item) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder
|
||||
.setTitle(R.string.confirm_mobile_download_dialog_title)
|
||||
.setMessage(context.getText(R.string.confirm_mobile_download_dialog_message))
|
||||
.setPositiveButton(R.string.confirm_mobile_download_dialog_enable_temporarily,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
allowMobileDownloadsTimestamp = System.currentTimeMillis();
|
||||
try {
|
||||
DBTasks.downloadFeedItems(context, item);
|
||||
Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
|
||||
} catch (DownloadRequestException e) {
|
||||
e.printStackTrace();
|
||||
DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNeutralButton(R.string.confirm_mobile_download_dialog_only_add_to_queue,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
onlyAddToQueueTimeStamp = System.currentTimeMillis();
|
||||
DBWriter.addQueueItem(context, item.getId());
|
||||
Toast.makeText(context, R.string.added_to_queue_label, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel_label, null)
|
||||
.create()
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@
|
|||
<string name="mark_unread_label">Mark as unplayed</string>
|
||||
<string name="marked_as_read_label">Marked as played</string>
|
||||
<string name="add_to_queue_label">Add to Queue</string>
|
||||
<string name="added_to_queue_label">Added to Queue</string>
|
||||
<string name="remove_from_queue_label">Remove from Queue</string>
|
||||
<string name="visit_website_label">Visit Website</string>
|
||||
<string name="support_label">Flattr this</string>
|
||||
|
@ -145,6 +146,10 @@
|
|||
<string name="download_request_error_dialog_message_prefix">An error occurred when trying to download the file:\u0020</string>
|
||||
<string name="authentication_notification_title">Authentication required</string>
|
||||
<string name="authentication_notification_msg">The resource you requested requires a username and a password</string>
|
||||
<string name="confirm_mobile_download_dialog_title">Confirm Mobile Download</string>
|
||||
<string name="confirm_mobile_download_dialog_message">Downloading over mobile data connection disable in settings.\n\nEnable temporarily or just add to queue?\n\n<small>Your choice will be remember for 10 minutes.</small></string>
|
||||
<string name="confirm_mobile_download_dialog_only_add_to_queue">Only add to Queue</string>
|
||||
<string name="confirm_mobile_download_dialog_enable_temporarily">Enable temporarily</string>
|
||||
|
||||
<!-- Mediaplayer messages -->
|
||||
<string name="player_error_msg">Error!</string>
|
||||
|
|
Loading…
Reference in New Issue