Decouple FeedMedia and PlaybackService
This commit is contained in:
parent
762140bccd
commit
c04f36bb9f
|
@ -11,6 +11,7 @@ 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;
|
||||
import de.danoeh.antennapod.core.util.FeedItemUtil;
|
||||
|
||||
public abstract class ItemActionButton {
|
||||
FeedItem item;
|
||||
|
@ -39,7 +40,7 @@ public abstract class ItemActionButton {
|
|||
}
|
||||
|
||||
final boolean isDownloadingMedia = DownloadRequester.getInstance().isDownloadingFile(media);
|
||||
if (media.isCurrentlyPlaying()) {
|
||||
if (FeedItemUtil.isCurrentlyPlaying(media)) {
|
||||
return new PauseActionButton(item);
|
||||
} else if (item.getFeed().isLocalFeed()) {
|
||||
return new PlayLocalActionButton(item);
|
||||
|
|
|
@ -6,6 +6,7 @@ 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.FeedItemUtil;
|
||||
import de.danoeh.antennapod.core.util.IntentUtils;
|
||||
|
||||
import static de.danoeh.antennapod.core.service.playback.PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE;
|
||||
|
@ -35,7 +36,7 @@ public class PauseActionButton extends ItemActionButton {
|
|||
return;
|
||||
}
|
||||
|
||||
if (media.isCurrentlyPlaying()) {
|
||||
if (FeedItemUtil.isCurrentlyPlaying(media)) {
|
||||
IntentUtils.sendLocalBroadcast(context, ACTION_PAUSE_PLAY_CURRENT_EPISODE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ import de.danoeh.antennapod.core.storage.DBReader;
|
|||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
||||
import de.danoeh.antennapod.core.util.Converter;
|
||||
import de.danoeh.antennapod.core.util.DateUtils;
|
||||
import de.danoeh.antennapod.core.util.FeedItemUtil;
|
||||
import de.danoeh.antennapod.ui.common.ThemeUtils;
|
||||
import de.danoeh.antennapod.core.util.playback.PlaybackController;
|
||||
import de.danoeh.antennapod.core.util.playback.Timeline;
|
||||
|
@ -336,7 +337,7 @@ public class ItemFragment extends Fragment {
|
|||
txtvDuration.setContentDescription(
|
||||
Converter.getDurationStringLocalized(getContext(), media.getDuration()));
|
||||
}
|
||||
if (media.isCurrentlyPlaying()) {
|
||||
if (FeedItemUtil.isCurrentlyPlaying(media)) {
|
||||
actionButton1 = new PauseActionButton(item);
|
||||
} else if (item.getFeed().isLocalFeed()) {
|
||||
actionButton1 = new PlayLocalActionButton(item);
|
||||
|
|
|
@ -29,6 +29,7 @@ import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
|||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
||||
import de.danoeh.antennapod.core.util.Converter;
|
||||
import de.danoeh.antennapod.core.util.DateUtils;
|
||||
import de.danoeh.antennapod.core.util.FeedItemUtil;
|
||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||
import de.danoeh.antennapod.ui.common.ThemeUtils;
|
||||
import de.danoeh.antennapod.ui.common.CircularProgressBar;
|
||||
|
@ -133,7 +134,7 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder {
|
|||
isVideo.setVisibility(media.getMediaType() == MediaType.VIDEO ? View.VISIBLE : View.GONE);
|
||||
duration.setVisibility(media.getDuration() > 0 ? View.VISIBLE : View.GONE);
|
||||
|
||||
if (media.isCurrentlyPlaying()) {
|
||||
if (FeedItemUtil.isCurrentlyPlaying(media)) {
|
||||
itemView.setBackgroundColor(ThemeUtils.getColorFromAttr(activity, R.attr.currently_playing_background));
|
||||
} else {
|
||||
itemView.setBackgroundResource(ThemeUtils.getDrawableFromAttr(activity, R.attr.selectableItemBackground));
|
||||
|
@ -213,7 +214,7 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder {
|
|||
}
|
||||
|
||||
public boolean isCurrentlyPlayingItem() {
|
||||
return item.getMedia() != null && item.getMedia().isCurrentlyPlaying();
|
||||
return item.getMedia() != null && FeedItemUtil.isCurrentlyPlaying(item.getMedia());
|
||||
}
|
||||
|
||||
public void notifyPlaybackPositionUpdated(PlaybackPositionEvent event) {
|
||||
|
|
|
@ -15,13 +15,10 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
|
||||
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
||||
|
||||
public class FeedMedia extends FeedFile implements Playable {
|
||||
private static final String TAG = "FeedMedia";
|
||||
|
||||
public static final int FEEDFILETYPE_FEEDMEDIA = 2;
|
||||
public static final int PLAYABLE_TYPE_FEEDMEDIA = 1;
|
||||
public static final String FILENAME_PREFIX_EMBEDDED_COVER = "metadata-retriever:";
|
||||
|
@ -162,15 +159,6 @@ public class FeedMedia extends FeedFile implements Playable {
|
|||
&& PlaybackPreferences.getCurrentlyPlayingFeedMediaId() == id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads playback preferences to determine whether this FeedMedia object is
|
||||
* currently being played and the current player status is playing.
|
||||
*/
|
||||
public boolean isCurrentlyPlaying() {
|
||||
return isPlaying() && PlaybackService.isRunning &&
|
||||
((PlaybackPreferences.getCurrentPlayerStatus() == PlaybackPreferences.PLAYER_STATUS_PLAYING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTypeAsInt() {
|
||||
return FEEDFILETYPE_FEEDMEDIA;
|
||||
|
|
|
@ -4,6 +4,8 @@ import androidx.annotation.NonNull;
|
|||
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -73,4 +75,13 @@ public class FeedItemUtil {
|
|||
int smartMarkAsPlayedSecs = UserPreferences.getSmartMarkAsPlayedSecs();
|
||||
return media.getDuration() > 0 && media.getPosition() >= media.getDuration() - smartMarkAsPlayedSecs * 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads playback preferences to determine whether this FeedMedia object is
|
||||
* currently being played and the current player status is playing.
|
||||
*/
|
||||
public static boolean isCurrentlyPlaying(FeedMedia item) {
|
||||
return item.isPlaying() && PlaybackService.isRunning
|
||||
&& ((PlaybackPreferences.getCurrentPlayerStatus() == PlaybackPreferences.PLAYER_STATUS_PLAYING));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue