From 4c7531d277bf4b2a733031b9b1d3a7e9c1ad0241 Mon Sep 17 00:00:00 2001 From: orionlee Date: Wed, 2 May 2018 13:53:56 -0700 Subject: [PATCH] Flatten nested ifs, per @ByteHamster feedback --- .../activity/MediaplayerActivity.java | 18 ++++++++--------- .../antennapod/core/util/FeedItemUtil.java | 20 ++++++++----------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index 229848753..35f9579df 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -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 - } - } // else no media, return null - return link; + if (media == null) { + return null; + } else if (media.getWebsiteLink() != null) { + return media.getWebsiteLink(); + } else if (media instanceof FeedMedia) { + return FeedItemUtil.getLinkWithFallback(((FeedMedia)media).getItem()); + } + return null; } @Override 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; } }