diff options
author | Martin Fietz <marf@hadiko-99-4.hadiko.uni-karlsruhe.de> | 2015-05-03 18:58:48 +0200 |
---|---|---|
committer | Martin Fietz <marf@hadiko-99-4.hadiko.uni-karlsruhe.de> | 2015-05-03 18:58:48 +0200 |
commit | fd7cdd3c715565b621cb7ba2f485dd1bad696044 (patch) | |
tree | efa3f0534401ce34d7749288a32837c2c3795472 /app | |
parent | f8bb78d43630eb7762074279c5b1db032071e072 (diff) | |
download | AntennaPod-fd7cdd3c715565b621cb7ba2f485dd1bad696044.zip |
Show confirmation dialog when downloading over mobile data connection is disabled
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java | 69 |
1 files changed, 61 insertions, 8 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java b/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java index d3843934a..20f07f71c 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java @@ -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(); + } } |