diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2024-04-05 19:20:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-05 19:20:27 +0200 |
commit | 92ab575b150ab49ca85e0ac994558142e49c9e68 (patch) | |
tree | 422dcd76895a4ba06ed02723ff61351435c0fe49 /model/src | |
parent | 2143ab135182434911d4554a8ef08115eaa0d2d0 (diff) | |
download | AntennaPod-92ab575b150ab49ca85e0ac994558142e49c9e68.zip |
Delete core module (#7060)
Diffstat (limited to 'model/src')
3 files changed, 87 insertions, 0 deletions
diff --git a/model/src/main/java/de/danoeh/antennapod/model/feed/Chapter.java b/model/src/main/java/de/danoeh/antennapod/model/feed/Chapter.java index 3f4116f9c..3683a2a44 100644 --- a/model/src/main/java/de/danoeh/antennapod/model/feed/Chapter.java +++ b/model/src/main/java/de/danoeh/antennapod/model/feed/Chapter.java @@ -1,5 +1,7 @@ package de.danoeh.antennapod.model.feed; +import java.util.List; + public class Chapter { private long id; /** Defines starting point in milliseconds. */ @@ -74,4 +76,16 @@ public class Chapter { public void setId(long id) { this.id = id; } + + public static int getAfterPosition(List<Chapter> chapters, int playbackPosition) { + if (chapters == null || chapters.isEmpty()) { + return -1; + } + for (int i = 0; i < chapters.size(); i++) { + if (chapters.get(i).getStart() > playbackPosition) { + return i - 1; + } + } + return chapters.size() - 1; + } } diff --git a/model/src/main/java/de/danoeh/antennapod/model/feed/FeedItem.java b/model/src/main/java/de/danoeh/antennapod/model/feed/FeedItem.java index 9cc71eb1d..df4cc8f9c 100644 --- a/model/src/main/java/de/danoeh/antennapod/model/feed/FeedItem.java +++ b/model/src/main/java/de/danoeh/antennapod/model/feed/FeedItem.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.model.feed; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -205,6 +206,19 @@ public class FeedItem implements Serializable { return link; } + /** + * Get the link for the feed item for the purpose of Share. + * It falls backs to the feed's link if the item has no link. + */ + public String getLinkWithFallback() { + if (StringUtils.isNotBlank(link)) { + return link; + } else if (StringUtils.isNotBlank(getFeed().getLink())) { + return getFeed().getLink(); + } + return null; + } + public void setLink(String link) { this.link = link; } diff --git a/model/src/test/java/de/danoeh/antennapod/model/feed/FeedItemFallbackLinkTest.java b/model/src/test/java/de/danoeh/antennapod/model/feed/FeedItemFallbackLinkTest.java new file mode 100644 index 000000000..c0ea222e4 --- /dev/null +++ b/model/src/test/java/de/danoeh/antennapod/model/feed/FeedItemFallbackLinkTest.java @@ -0,0 +1,59 @@ +package de.danoeh.antennapod.model.feed; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +import static org.junit.Assert.assertEquals; + +@RunWith(Parameterized.class) +public class FeedItemFallbackLinkTest { + private static final String FEED_LINK = "http://example.com"; + private static final String ITEM_LINK = "http://example.com/feedItem1"; + + private final String msg; + private final String feedLink; + private final String itemLink; + private final String expected; + + @Parameters + public static Collection<Object[]> data() { + return Arrays.asList(new Object[][]{ + {"average", FEED_LINK, ITEM_LINK, ITEM_LINK}, + {"null item link - fallback to feed", FEED_LINK, null, FEED_LINK}, + {"empty item link - same as null", FEED_LINK, "", FEED_LINK}, + {"blank item link - same as null", FEED_LINK, " ", FEED_LINK}, + {"fallback, but feed link is null too", null, null, null}, + {"fallback - but empty feed link - same as null", "", null, null}, + {"fallback - but blank feed link - same as null", " ", null, null} + }); + } + + public FeedItemFallbackLinkTest(String msg, String feedLink, String itemLink, String expected) { + this.msg = msg; + this.feedLink = feedLink; + this.itemLink = itemLink; + this.expected = expected; + } + + @Test + public void testLinkWithFallback() { + String actual = createFeedItem(feedLink, itemLink).getLinkWithFallback(); + assertEquals(msg, expected, actual); + } + + private static FeedItem createFeedItem(String feedLink, String itemLink) { + Feed feed = new Feed("http://example.com/feed", null); + feed.setLink(feedLink); + FeedItem feedItem = new FeedItem(); + feedItem.setLink(itemLink); + feedItem.setFeed(feed); + feed.setItems(Collections.singletonList(feedItem)); + return feedItem; + } +} |