diff options
author | Doug Smith <dsmith47@nd.edu> | 2019-10-16 04:31:50 -0400 |
---|---|---|
committer | Doug Smith <dsmith47@nd.edu> | 2019-10-16 04:31:50 -0400 |
commit | 0bc3294ca43fa38011086e8b3008c587bce47042 (patch) | |
tree | fd5c073c48eaa740d1cfd87668f635fcb6fe066b /app/src | |
parent | 2ffdc275b8dd127f15506556d1b7ba9fb9108b47 (diff) | |
download | AntennaPod-0bc3294ca43fa38011086e8b3008c587bce47042.zip |
Implemented feature to show stream button (instead of Download/Play-Pause) in podcast episode views.
* Added user preference to specify that stream buttons are preferred
* Added StreamAction button to trigger streams on podcast options
Diffstat (limited to 'app/src')
3 files changed, 71 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..7337ef664 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java @@ -0,0 +1,63 @@ +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.NetworkUtils; +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"> |