Removed PlaybackPreferences dependency from FeedMedia

This commit is contained in:
ByteHamster 2021-04-22 22:19:02 +02:00
parent c04f36bb9f
commit 09d402a945
7 changed files with 16 additions and 34 deletions

View File

@ -49,7 +49,7 @@ public class FeedItemMenuHandler {
return false;
}
final boolean hasMedia = selectedItem.getMedia() != null;
final boolean isPlaying = hasMedia && selectedItem.getState() == FeedItem.State.PLAYING;
final boolean isPlaying = hasMedia && FeedItemUtil.isPlaying(selectedItem.getMedia());
final boolean isInQueue = selectedItem.isTagged(FeedItem.TAG_QUEUE);
final boolean fileDownloaded = hasMedia && selectedItem.getMedia().fileExists();
final boolean isFavorite = selectedItem.isTagged(FeedItem.TAG_FAVORITE);

View File

@ -153,7 +153,7 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder {
duration.setText(Converter.getDurationStringLong(media.getDuration()));
duration.setContentDescription(activity.getString(R.string.chapter_duration,
Converter.getDurationStringLocalized(activity, media.getDuration())));
if (item.getState() == FeedItem.State.PLAYING || item.getState() == FeedItem.State.IN_PROGRESS) {
if (FeedItemUtil.isPlaying(item.getMedia()) || item.isInProgress()) {
int progress = (int) (100.0 * media.getPosition() / media.getDuration());
int remainingTime = Math.max(media.getDuration() - media.getPosition(), 0);
progressBar.setProgress(progress);

View File

@ -265,7 +265,7 @@ public class FeedItem extends FeedComponent implements Serializable {
}
}
private boolean isInProgress() {
public boolean isInProgress() {
return (media != null && media.isInProgress());
}
@ -312,10 +312,6 @@ public class FeedItem extends FeedComponent implements Serializable {
return media != null;
}
private boolean isPlaying() {
return media != null && media.isPlaying();
}
public String getImageLocation() {
if (imageUrl != null) {
return imageUrl;
@ -332,18 +328,6 @@ public class FeedItem extends FeedComponent implements Serializable {
UNREAD, IN_PROGRESS, READ, PLAYING
}
public State getState() {
if (hasMedia()) {
if (isPlaying()) {
return State.PLAYING;
}
if (isInProgress()) {
return State.IN_PROGRESS;
}
}
return (isPlayed() ? State.READ : State.UNREAD);
}
public long getFeedId() {
return feedId;
}
@ -394,7 +378,7 @@ public class FeedItem extends FeedComponent implements Serializable {
}
public boolean isAutoDownloadable() {
if (media == null || media.isPlaying() || media.isDownloaded() || autoDownload == 0) {
if (media == null || media.isDownloaded() || autoDownload == 0) {
return false;
}
if (autoDownload == 1) {

View File

@ -14,7 +14,6 @@ import android.support.v4.media.MediaDescriptionCompat;
import java.util.Date;
import java.util.List;
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.playback.Playable;
@ -150,15 +149,6 @@ public class FeedMedia extends FeedFile implements Playable {
return false;
}
/**
* Reads playback preferences to determine whether this FeedMedia object is
* currently being played.
*/
public boolean isPlaying() {
return PlaybackPreferences.getCurrentlyPlayingMediaType() == FeedMedia.PLAYABLE_TYPE_FEEDMEDIA
&& PlaybackPreferences.getCurrentlyPlayingFeedMediaId() == id;
}
@Override
public int getTypeAsInt() {
return FEEDFILETYPE_FEEDMEDIA;

View File

@ -11,6 +11,7 @@ import de.danoeh.antennapod.core.feed.FeedFilter;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedPreferences;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.NetworkUtils;
import de.danoeh.antennapod.core.util.PowerUtils;
@ -64,7 +65,8 @@ public class AutomaticDownloadAlgorithm {
Iterator<FeedItem> it = candidates.iterator();
while (it.hasNext()) {
FeedItem item = it.next();
if (!item.isAutoDownloadable() || item.getFeed().isLocalFeed()) {
if (!item.isAutoDownloadable() || FeedItemUtil.isPlaying(item.getMedia())
|| item.getFeed().isLocalFeed()) {
it.remove();
}
}

View File

@ -80,8 +80,14 @@ public class FeedItemUtil {
* 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
public static boolean isCurrentlyPlaying(FeedMedia media) {
return isPlaying(media) && PlaybackService.isRunning
&& ((PlaybackPreferences.getCurrentPlayerStatus() == PlaybackPreferences.PLAYER_STATUS_PLAYING));
}
public static boolean isPlaying(FeedMedia media) {
return PlaybackPreferences.getCurrentlyPlayingMediaType() == FeedMedia.PLAYABLE_TYPE_FEEDMEDIA
&& media != null
&& PlaybackPreferences.getCurrentlyPlayingFeedMediaId() == media.getId();
}
}

View File

@ -172,7 +172,7 @@ public class DbTasksTest {
final Feed feedFromDB = DBReader.getFeed(newFeed.getId());
final FeedItem feedItemFromDB = feedFromDB.getItems().get(0);
assertTrue("state: " + feedItemFromDB.getState(), feedItemFromDB.isNew());
assertTrue(feedItemFromDB.isNew());
}
@Test