summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/androidTest/java/de/test/antennapod/feed/FeedItemTest.java37
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java11
2 files changed, 47 insertions, 1 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/feed/FeedItemTest.java b/app/src/androidTest/java/de/test/antennapod/feed/FeedItemTest.java
new file mode 100644
index 000000000..db463132d
--- /dev/null
+++ b/app/src/androidTest/java/de/test/antennapod/feed/FeedItemTest.java
@@ -0,0 +1,37 @@
+package de.test.antennapod.feed;
+
+import android.test.AndroidTestCase;
+import de.danoeh.antennapod.core.feed.FeedItem;
+
+public class FeedItemTest extends AndroidTestCase {
+ private static final String TEXT_LONG = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
+ private static final String TEXT_SHORT = "Lorem ipsum";
+
+ /**
+ * If one of `description` or `content:encoded` is null, use the other one.
+ */
+ public void testShownotesNullValues() throws Exception {
+ testShownotes(null, TEXT_LONG);
+ testShownotes(TEXT_LONG, null);
+ }
+
+ /**
+ * If `description` is reasonably longer than `content:encoded`, use `description`.
+ */
+ public void testShownotesLength() throws Exception {
+ testShownotes(TEXT_SHORT, TEXT_LONG);
+ testShownotes(TEXT_LONG, TEXT_SHORT);
+ }
+
+ /**
+ * Checks if the shownotes equal TEXT_LONG, using the given `description` and `content:encoded`
+ * @param description Description of the feed item
+ * @param contentEncoded `content:encoded` of the feed item
+ */
+ private void testShownotes(String description, String contentEncoded) throws Exception {
+ FeedItem item = new FeedItem();
+ item.setDescription(description);
+ item.setContentEncoded(contentEncoded);
+ assertEquals(TEXT_LONG, item.loadShownotes().call());
+ }
+}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java
index 7b387b1d3..87298d4c3 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java
@@ -3,6 +3,7 @@ package de.danoeh.antennapod.core.feed;
import android.database.Cursor;
import android.support.annotation.Nullable;
+import android.text.TextUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -372,7 +373,15 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Flattr
if (contentEncoded == null || description == null) {
DBReader.loadExtraInformationOfFeedItem(FeedItem.this);
}
- return (contentEncoded != null) ? contentEncoded : description;
+ if (TextUtils.isEmpty(contentEncoded)) {
+ return description;
+ } else if (TextUtils.isEmpty(description)) {
+ return contentEncoded;
+ } else if (description.length() > 1.25 * contentEncoded.length()) {
+ return description;
+ } else {
+ return contentEncoded;
+ }
};
}