diff --git a/core/src/main/java/de/danoeh/antennapod/core/cast/CastUtils.java b/core/src/main/java/de/danoeh/antennapod/core/cast/CastUtils.java index c13d50e05..d69256864 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/cast/CastUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/cast/CastUtils.java @@ -268,6 +268,49 @@ public class CastUtils { return feed != null && TextUtils.equals(metadata.getString(KEY_FEED_URL), feed.getDownload_url()); } + /** + * Compares a {@link MediaInfo} instance with a {@link RemoteMedia} one and evaluates whether they + * represent the same podcast episode. + * + * @param info the {@link MediaInfo} object to be compared. + * @param media the {@link RemoteMedia} object to be compared. + * @return true if there's a match, false otherwise. + * + * @see RemoteMedia#equals(Object) + */ + public static boolean matches(MediaInfo info, RemoteMedia media) { + if (info == null || media == null) { + return false; + } + if (!TextUtils.equals(info.getContentId(), media.getStreamUrl())) { + return false; + } + MediaMetadata metadata = info.getMetadata(); + return metadata != null && + TextUtils.equals(metadata.getString(KEY_EPISODE_IDENTIFIER), media.getEpisodeIdentifier()) && + TextUtils.equals(metadata.getString(KEY_FEED_URL), media.getFeedUrl()); + } + + /** + * Compares a {@link MediaInfo} instance with a {@link Playable} and evaluates whether they + * represent the same podcast episode. + * + * @param info the {@link MediaInfo} object to be compared. + * @param media the {@link Playable} object to be compared. + * @return true if there's a match, false otherwise. + * + * @see RemoteMedia#equals(Object) + */ + public static boolean matches(MediaInfo info, Playable media) { + if (info == null || media == null) { + return false; + } + if (media instanceof RemoteMedia) { + return matches(info, (RemoteMedia) media); + } + return media instanceof FeedMedia && matches(info, (FeedMedia) media); + } + //TODO Queue handling perhaps } diff --git a/core/src/main/java/de/danoeh/antennapod/core/cast/RemoteMedia.java b/core/src/main/java/de/danoeh/antennapod/core/cast/RemoteMedia.java index 67a04c36b..18e0e3287 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/cast/RemoteMedia.java +++ b/core/src/main/java/de/danoeh/antennapod/core/cast/RemoteMedia.java @@ -119,6 +119,14 @@ public class RemoteMedia implements Playable { return builder.build(); } + public String getEpisodeIdentifier() { + return itemIdentifier; + } + + public String getFeedUrl() { + return feedUrl; + } + public FeedMedia lookForFeedMedia() { FeedItem feedItem = DBReader.getFeedItem(feedUrl, itemIdentifier); if (feedItem == null) {