Show pause button for currently streamed episode
This commit is contained in:
parent
37528452ca
commit
7adfbcf003
|
@ -41,7 +41,9 @@ public abstract class ItemActionButton {
|
|||
}
|
||||
|
||||
final boolean isDownloadingMedia = DownloadRequester.getInstance().isDownloadingFile(media);
|
||||
if (media.isDownloaded()) {
|
||||
if (media.isCurrentlyPlaying()) {
|
||||
return new PauseActionButton(item);
|
||||
} else if (media.isDownloaded()) {
|
||||
return new PlayActionButton(item);
|
||||
} else if (isDownloadingMedia) {
|
||||
return new CancelDownloadActionButton(item);
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
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.util.IntentUtils;
|
||||
|
||||
import static de.danoeh.antennapod.core.service.playback.PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE;
|
||||
|
||||
class PauseActionButton extends ItemActionButton {
|
||||
|
||||
PauseActionButton(FeedItem item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
@StringRes
|
||||
public int getLabel() {
|
||||
return R.string.pause_label;
|
||||
}
|
||||
|
||||
@Override
|
||||
@AttrRes
|
||||
public int getDrawable() {
|
||||
return R.attr.av_pause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(Context context) {
|
||||
FeedMedia media = item.getMedia();
|
||||
if (media == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (media.isCurrentlyPlaying()) {
|
||||
IntentUtils.sendLocalBroadcast(context, ACTION_PAUSE_PLAY_CURRENT_EPISODE);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,16 +3,11 @@ 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;
|
||||
|
||||
class PlayActionButton extends ItemActionButton {
|
||||
|
||||
PlayActionButton(FeedItem item) {
|
||||
|
@ -28,13 +23,8 @@ class PlayActionButton extends ItemActionButton {
|
|||
@Override
|
||||
@AttrRes
|
||||
public int getDrawable() {
|
||||
FeedMedia media = item.getMedia();
|
||||
if (media != null && media.isCurrentlyPlaying()) {
|
||||
return R.attr.av_pause;
|
||||
} else {
|
||||
return R.attr.av_play;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(Context context) {
|
||||
|
@ -43,17 +33,6 @@ class PlayActionButton extends ItemActionButton {
|
|||
return;
|
||||
}
|
||||
|
||||
if (media.isPlaying()) {
|
||||
togglePlayPause(context, media);
|
||||
} else {
|
||||
DBTasks.playMedia(context, media, false, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -61,4 +40,3 @@ class PlayActionButton extends ItemActionButton {
|
|||
.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue