From 4bba6b30a1b5e82b93edc27742ec35362b08d1c7 Mon Sep 17 00:00:00 2001 From: orionlee Date: Mon, 30 Apr 2018 14:59:45 -0700 Subject: Issue #2579: Provide share Link in episode playback screen even when the episode has no link - Use podcast link as the fallback. Also bug fix share link with position: to include epsiode and podcast title. --- .../de/danoeh/antennapod/core/util/ShareUtils.java | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'core/src') diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java index 898f7bedb..149cdcbc6 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java @@ -50,11 +50,30 @@ public class ShareUtils { return item.getFeed().getTitle() + ": " + item.getTitle(); } + /** + * Get the link for the feed item for the purpose of Share. It fallbacks to + * use the feed's link if the named feed item has no link. + */ + private static String getItemShareLink(FeedItem item) { + String link = item.getLink(); + if (link == null) { + Feed feed = item.getFeed(); + if (feed != null) { + link = feed.getLink(); + } + } + return link; + } + + public static boolean hasLinkToShare(FeedItem item) { + return ( item != null && getItemShareLink(item) != null ); + } + public static void shareFeedItemLink(Context context, FeedItem item, boolean withPosition) { - String text = getItemShareText(item) + " " + item.getLink(); + String text = getItemShareText(item) + " " + getItemShareLink(item); if(withPosition) { int pos = item.getMedia().getPosition(); - text = item.getLink() + " [" + Converter.getDurationStringLong(pos) + "]"; + text += " [" + Converter.getDurationStringLong(pos) + "]"; } shareLink(context, text); } -- cgit v1.2.3 From 345fcc17d0416f8db61a2506aa88c25b53718ebb Mon Sep 17 00:00:00 2001 From: orionlee Date: Mon, 30 Apr 2018 15:44:19 -0700 Subject: FeedItem Visit Website tweak: use feed website as a fallback, analogous to how share FeedItem link work. Applicable to both feed playback screen and feed information screen. --- .../de/danoeh/antennapod/core/util/FeedItemUtil.java | 15 +++++++++++++++ .../de/danoeh/antennapod/core/util/ShareUtils.java | 19 ++----------------- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'core/src') diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java b/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java index 892e5ff38..129c1923e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java @@ -2,6 +2,7 @@ package de.danoeh.antennapod.core.util; import java.util.List; +import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedItem; public class FeedItemUtil { @@ -75,4 +76,18 @@ public class FeedItemUtil { return false; } + /** + * Get the link for the feed item for the purpose of Share. It fallbacks to + * use the feed's link if the named feed item has no link. + */ + public static String getLinkWithFallback(FeedItem item) { + String link = item.getLink(); + if (link == null) { + Feed feed = item.getFeed(); + if (feed != null) { + link = feed.getLink(); + } + } + return link; + } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java index 149cdcbc6..0fbca2437 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java @@ -50,27 +50,12 @@ public class ShareUtils { return item.getFeed().getTitle() + ": " + item.getTitle(); } - /** - * Get the link for the feed item for the purpose of Share. It fallbacks to - * use the feed's link if the named feed item has no link. - */ - private static String getItemShareLink(FeedItem item) { - String link = item.getLink(); - if (link == null) { - Feed feed = item.getFeed(); - if (feed != null) { - link = feed.getLink(); - } - } - return link; - } - public static boolean hasLinkToShare(FeedItem item) { - return ( item != null && getItemShareLink(item) != null ); + return ( item != null && FeedItemUtil.getLinkWithFallback(item) != null ); } public static void shareFeedItemLink(Context context, FeedItem item, boolean withPosition) { - String text = getItemShareText(item) + " " + getItemShareLink(item); + String text = getItemShareText(item) + " " + FeedItemUtil.getLinkWithFallback(item); if(withPosition) { int pos = item.getMedia().getPosition(); text += " [" + Converter.getDurationStringLong(pos) + "]"; -- cgit v1.2.3 From ab0f4131850695537c22258633aecb4aca0aece5 Mon Sep 17 00:00:00 2001 From: orionlee Date: Mon, 30 Apr 2018 15:49:18 -0700 Subject: Make FeedItemUtil.getLinkWithFallback(item) tolerates null item. --- .../java/de/danoeh/antennapod/core/util/FeedItemUtil.java | 15 +++++++++------ .../java/de/danoeh/antennapod/core/util/ShareUtils.java | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'core/src') diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java b/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java index 129c1923e..516c57d55 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java @@ -81,13 +81,16 @@ public class FeedItemUtil { * use the feed's link if the named feed item has no link. */ public static String getLinkWithFallback(FeedItem item) { - String link = item.getLink(); - if (link == null) { - Feed feed = item.getFeed(); - if (feed != null) { - link = feed.getLink(); + String link = null; + if (item != null) { + link = item.getLink(); + if (link == null) { + Feed feed = item.getFeed(); + if (feed != null) { + link = feed.getLink(); + } } - } + } // else null item, can only return null return link; } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java index 0fbca2437..5ae00460e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java @@ -51,7 +51,7 @@ public class ShareUtils { } public static boolean hasLinkToShare(FeedItem item) { - return ( item != null && FeedItemUtil.getLinkWithFallback(item) != null ); + return FeedItemUtil.getLinkWithFallback(item) != null; } public static void shareFeedItemLink(Context context, FeedItem item, boolean withPosition) { -- cgit v1.2.3 From 4c7531d277bf4b2a733031b9b1d3a7e9c1ad0241 Mon Sep 17 00:00:00 2001 From: orionlee Date: Wed, 2 May 2018 13:53:56 -0700 Subject: Flatten nested ifs, per @ByteHamster feedback --- .../de/danoeh/antennapod/core/util/FeedItemUtil.java | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'core/src') diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java b/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java index 516c57d55..76a6549ae 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java @@ -2,7 +2,6 @@ package de.danoeh.antennapod.core.util; import java.util.List; -import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedItem; public class FeedItemUtil { @@ -81,16 +80,13 @@ public class FeedItemUtil { * use the feed's link if the named feed item has no link. */ public static String getLinkWithFallback(FeedItem item) { - String link = null; - if (item != null) { - link = item.getLink(); - if (link == null) { - Feed feed = item.getFeed(); - if (feed != null) { - link = feed.getLink(); - } - } - } // else null item, can only return null - return link; + if (item == null) { + return null; + } else if (item.getLink() != null) { + return item.getLink(); + } else if (item.getFeed() != null) { + return item.getFeed().getLink(); + } + return null; } } -- cgit v1.2.3