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) {
String link = null;
if (media != null) {
link = media.getWebsiteLink();
if (link == null) {
if (media instanceof FeedMedia) {
link = FeedItemUtil.getLinkWithFallback(((FeedMedia)media).getItem());
} // else case not a FeedMedia, return null
if (media == null) {
return null;
} else if (media.getWebsiteLink() != null) {
return media.getWebsiteLink();
} else if (media instanceof FeedMedia) {
return FeedItemUtil.getLinkWithFallback(((FeedMedia)media).getItem());
}
} // else no media, return null
return link;
return null;
}
@Override

View File

@ -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();
if (item == null) {
return null;
} else if (item.getLink() != null) {
return item.getLink();
} else if (item.getFeed() != null) {
return item.getFeed().getLink();
}
}
} // else null item, can only return null
return link;
return null;
}
}