Flatten nested ifs, per @ByteHamster feedback

This commit is contained in:
orionlee 2018-05-02 13:53:56 -07:00
parent ab0f413185
commit 4c7531d277
2 changed files with 16 additions and 22 deletions

View File

@ -605,16 +605,14 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
} }
private static String getWebsiteLinkWithFallback(Playable media) { private static String getWebsiteLinkWithFallback(Playable media) {
String link = null; if (media == null) {
if (media != null) { return null;
link = media.getWebsiteLink(); } else if (media.getWebsiteLink() != null) {
if (link == null) { return media.getWebsiteLink();
if (media instanceof FeedMedia) { } else if (media instanceof FeedMedia) {
link = FeedItemUtil.getLinkWithFallback(((FeedMedia)media).getItem()); return FeedItemUtil.getLinkWithFallback(((FeedMedia)media).getItem());
} // else case not a FeedMedia, return null
} }
} // else no media, return null return null;
return link;
} }
@Override @Override

View File

@ -2,7 +2,6 @@ package de.danoeh.antennapod.core.util;
import java.util.List; import java.util.List;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedItem;
public class FeedItemUtil { public class FeedItemUtil {
@ -81,16 +80,13 @@ public class FeedItemUtil {
* use the feed's link if the named feed item has no link. * use the feed's link if the named feed item has no link.
*/ */
public static String getLinkWithFallback(FeedItem item) { public static String getLinkWithFallback(FeedItem item) {
String link = null; if (item == null) {
if (item != null) { return null;
link = item.getLink(); } else if (item.getLink() != null) {
if (link == null) { return item.getLink();
Feed feed = item.getFeed(); } else if (item.getFeed() != null) {
if (feed != null) { return item.getFeed().getLink();
link = feed.getLink();
} }
} return null;
} // else null item, can only return null
return link;
} }
} }