diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2020-03-01 01:22:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-01 01:22:29 +0100 |
commit | fef4fb9a6b24abdd34dce630f2197f478cae7b3d (patch) | |
tree | 2e36dcae5d08182883f9161e27d68d0ea67c2312 /app/src/main/java/de/danoeh/antennapod | |
parent | 809ca28ab7fb80cd5f3506492c57189f5c1bd153 (diff) | |
download | AntennaPod-fef4fb9a6b24abdd34dce630f2197f478cae7b3d.zip |
Add allow streaming dialog (#3897)
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java | 27 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/dialog/StreamingConfirmationDialog.java | 43 |
2 files changed, 49 insertions, 21 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java index 3a43d3217..38b84c453 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java @@ -10,7 +10,9 @@ import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.util.IntentUtils; +import de.danoeh.antennapod.core.util.NetworkUtils; import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter; +import de.danoeh.antennapod.dialog.StreamingConfirmationDialog; import static de.danoeh.antennapod.core.service.playback.PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE; @@ -29,10 +31,6 @@ public class StreamActionButton extends ItemActionButton { @Override @AttrRes public int getDrawable() { - FeedMedia media = item.getMedia(); - if (media != null && media.isCurrentlyPlaying()) { - return R.attr.av_pause; - } return R.attr.action_stream; } @@ -42,23 +40,10 @@ public class StreamActionButton extends ItemActionButton { if (media == null) { return; } - - if (media.isPlaying()) { - togglePlayPause(context, media); - } else { - DBTasks.playMedia(context, media, false, true, true); - } - } - - private void togglePlayPause(Context context, FeedMedia media) { - if (media.isCurrentlyPlaying()) { - IntentUtils.sendLocalBroadcast(context, ACTION_PAUSE_PLAY_CURRENT_EPISODE); - } else { - new PlaybackServiceStarter(context, media) - .callEvenIfRunning(true) - .startWhenPrepared(true) - .shouldStream(true) - .start(); + if (!NetworkUtils.isStreamingAllowed()) { + new StreamingConfirmationDialog(context, media).show(); + return; } + DBTasks.playMedia(context, media, false, true, true); } } diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/StreamingConfirmationDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/StreamingConfirmationDialog.java new file mode 100644 index 000000000..5b77fd319 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/dialog/StreamingConfirmationDialog.java @@ -0,0 +1,43 @@ +package de.danoeh.antennapod.dialog; + +import android.content.Context; +import android.view.View; +import android.widget.CheckBox; +import androidx.appcompat.app.AlertDialog; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.core.feed.FeedMedia; +import de.danoeh.antennapod.core.preferences.UserPreferences; +import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter; + +public class StreamingConfirmationDialog { + private final Context context; + private final FeedMedia media; + + public StreamingConfirmationDialog(Context context, FeedMedia media) { + this.context = context; + this.media = media; + } + + public void show() { + View view = View.inflate(context, R.layout.checkbox_do_not_show_again, null); + CheckBox checkDoNotShowAgain = view.findViewById(R.id.checkbox_do_not_show_again); + + new AlertDialog.Builder(context) + .setTitle(R.string.stream_label) + .setMessage(R.string.confirm_mobile_streaming_notification_message) + .setView(view) + .setPositiveButton(R.string.stream_label, (dialog, which) -> { + if (checkDoNotShowAgain.isChecked()) { + UserPreferences.setAllowMobileStreaming(true); + } + new PlaybackServiceStarter(context, media) + .callEvenIfRunning(true) + .startWhenPrepared(true) + .shouldStream(true) + .shouldStreamThisTime(true) + .start(); + }) + .setNegativeButton(R.string.cancel_label, null) + .show(); + } +} |