diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2019-10-20 18:54:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-20 18:54:14 +0200 |
commit | f1f91478b6057dbaaaa5255d14dfe254bdc10f1d (patch) | |
tree | 32b57ef09e9daeb09f5148eb84490aa1b7670dde /app | |
parent | 38a670139f3c1377bb0ec8611f998e3005274301 (diff) | |
parent | bfa160ace39e11f1b45f54a81a3cda50363651b1 (diff) | |
download | AntennaPod-f1f91478b6057dbaaaa5255d14dfe254bdc10f1d.zip |
Merge pull request #3520 from dsmith47/stream
Show stream button rather than download (in queue, podcast views)
Diffstat (limited to 'app')
3 files changed, 72 insertions, 0 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/ItemActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/ItemActionButton.java index 31e9fccb5..861c6a4be 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/ItemActionButton.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/ItemActionButton.java @@ -10,6 +10,7 @@ import android.widget.ImageButton; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; +import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.DownloadRequester; public abstract class ItemActionButton { @@ -43,6 +44,8 @@ public abstract class ItemActionButton { return new PlayActionButton(item); } else if (isDownloadingMedia) { return new CancelDownloadActionButton(item); + } else if (UserPreferences.streamOverDownload()) { + return new StreamActionButton(item); } else if (MobileDownloadHelper.userAllowedMobileDownloads() || !MobileDownloadHelper.userChoseAddToQueue() || isInQueue) { return new DownloadActionButton(item, isInQueue); } else { 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 new file mode 100644 index 000000000..dc7fd1e7a --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java @@ -0,0 +1,64 @@ +package de.danoeh.antennapod.adapter.actionbutton; + +import android.content.Context; + +import androidx.annotation.AttrRes; +import androidx.annotation.StringRes; + +import de.danoeh.antennapod.R; +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.playback.PlaybackServiceStarter; + +import static de.danoeh.antennapod.core.service.playback.PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE; +import static de.danoeh.antennapod.core.service.playback.PlaybackService.ACTION_RESUME_PLAY_CURRENT_EPISODE; + +public class StreamActionButton extends ItemActionButton { + + StreamActionButton(FeedItem item) { + super(item); + } + + @Override + @StringRes + public int getLabel() { + return R.string.stream_label; + } + + @Override + @AttrRes + public int getDrawable() { + FeedMedia media = item.getMedia(); + if (media != null && media.isCurrentlyPlaying()) { + return R.attr.av_pause; + } + return R.attr.action_stream; + } + + @Override + public void onClick(Context context) { + final FeedMedia media = item.getMedia(); + 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) { + new PlaybackServiceStarter(context, media) + .startWhenPrepared(true) + .shouldStream(true) + .start(); + + String pauseOrResume = media.isCurrentlyPlaying() + ? ACTION_PAUSE_PLAY_CURRENT_EPISODE : ACTION_RESUME_PLAY_CURRENT_EPISODE; + IntentUtils.sendLocalBroadcast(context, pauseOrResume); + } +} diff --git a/app/src/main/res/xml/preferences_playback.xml b/app/src/main/res/xml/preferences_playback.xml index d609d3daa..2334e1b1c 100644 --- a/app/src/main/res/xml/preferences_playback.xml +++ b/app/src/main/res/xml/preferences_playback.xml @@ -76,6 +76,11 @@ android:key="prefPlaybackTimeRespectsSpeed" android:summary="@string/pref_playback_time_respects_speed_sum" android:title="@string/pref_playback_time_respects_speed_title"/> + <SwitchPreference + android:defaultValue="false" + android:key="prefStreamOverDownload" + android:summary="@string/pref_stream_over_download_sum" + android:title="@string/pref_stream_over_download_title"/> </PreferenceCategory> <PreferenceCategory android:title="@string/queue_label"> |