mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2024-12-26 16:52:46 +01:00
Add allow streaming dialog (#3897)
This commit is contained in:
parent
809ca28ab7
commit
fef4fb9a6b
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ public class PlaybackServiceStarter {
|
||||
private final Playable media;
|
||||
private boolean startWhenPrepared = false;
|
||||
private boolean shouldStream = false;
|
||||
private boolean shouldStreamThisTime = false;
|
||||
private boolean callEvenIfRunning = false;
|
||||
private boolean prepareImmediately = true;
|
||||
|
||||
@ -58,12 +59,18 @@ public class PlaybackServiceStarter {
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlaybackServiceStarter shouldStreamThisTime(boolean shouldStreamThisTime) {
|
||||
this.shouldStreamThisTime = shouldStreamThisTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Intent getIntent() {
|
||||
Intent launchIntent = new Intent(context, PlaybackService.class);
|
||||
launchIntent.putExtra(PlaybackService.EXTRA_PLAYABLE, media);
|
||||
launchIntent.putExtra(PlaybackService.EXTRA_START_WHEN_PREPARED, startWhenPrepared);
|
||||
launchIntent.putExtra(PlaybackService.EXTRA_SHOULD_STREAM, shouldStream);
|
||||
launchIntent.putExtra(PlaybackService.EXTRA_PREPARE_IMMEDIATELY, prepareImmediately);
|
||||
launchIntent.putExtra(PlaybackService.EXTRA_ALLOW_STREAM_THIS_TIME, shouldStreamThisTime);
|
||||
|
||||
return launchIntent;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user