summaryrefslogtreecommitdiff
path: root/core/src/main/java/de
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2020-03-28 23:46:50 +0100
committerByteHamster <info@bytehamster.com>2021-03-04 19:47:48 +0100
commitf62a6b808e54e28c791b0448661099ccbcf3e1c1 (patch)
treea1b8cc93cfbf1f39c1ae0de8ea10f1ebb6726a86 /core/src/main/java/de
parent9dbe5f6de58d8113b55c7bedd2f1fab200d80fb8 (diff)
downloadAntennaPod-f62a6b808e54e28c791b0448661099ccbcf3e1c1.zip
Only store content_encoded or description
Diffstat (limited to 'core/src/main/java/de')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java57
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java2
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java5
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java14
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java19
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSContent.java32
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSITunes.java13
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSMedia.java5
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSRSS20.java10
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java8
10 files changed, 70 insertions, 95 deletions
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 b2a89d452..133caaebd 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
@@ -4,7 +4,6 @@ import android.database.Cursor;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import android.text.TextUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -42,10 +41,6 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Serial
* The description of a feeditem.
*/
private String description;
- /**
- * The content of the content-encoded tag of a feeditem.
- */
- private String contentEncoded;
private String link;
private Date pubDate;
@@ -181,9 +176,6 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Serial
if (other.getDescription() != null) {
description = other.getDescription();
}
- if (other.getContentEncoded() != null) {
- contentEncoded = other.contentEncoded;
- }
if (other.link != null) {
link = other.link;
}
@@ -239,10 +231,6 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Serial
return description;
}
- public void setDescription(String description) {
- this.description = description;
- }
-
public String getLink() {
return link;
}
@@ -306,7 +294,7 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Serial
}
public void setPlayed(boolean played) {
- if(played) {
+ if (played) {
state = PLAYED;
} else {
state = UNPLAYED;
@@ -317,12 +305,19 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Serial
return (media != null && media.isInProgress());
}
- public String getContentEncoded() {
- return contentEncoded;
- }
-
- public void setContentEncoded(String contentEncoded) {
- this.contentEncoded = contentEncoded;
+ /**
+ * Updates this item's description property if the given argument is longer than the already stored description
+ * @param newDescription The new item description, content:encoded, itunes:description, etc.
+ */
+ public void setDescriptionIfLonger(String newDescription) {
+ if (newDescription == null) {
+ return;
+ }
+ if (this.description == null) {
+ this.description = newDescription;
+ } else if (this.description.length() < newDescription.length()) {
+ this.description = newDescription;
+ }
}
public String getPaymentLink() {
@@ -360,18 +355,10 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Serial
@Override
public Callable<String> loadShownotes() {
return () -> {
- if (contentEncoded == null || description == null) {
+ if (description == null) {
DBReader.loadDescriptionOfFeedItem(FeedItem.this);
}
- 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;
- }
+ return description;
};
}
@@ -470,17 +457,23 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Serial
/**
* @return true if the item has this tag
*/
- public boolean isTagged(String tag) { return tags.contains(tag); }
+ public boolean isTagged(String tag) {
+ return tags.contains(tag);
+ }
/**
* @param tag adds this tag to the item. NOTE: does NOT persist to the database
*/
- public void addTag(String tag) { tags.add(tag); }
+ public void addTag(String tag) {
+ tags.add(tag);
+ }
/**
* @param tag the to remove
*/
- public void removeTag(String tag) { tags.remove(tag); }
+ public void removeTag(String tag) {
+ tags.remove(tag);
+ }
@NonNull
@Override
diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java b/core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java
index d0e15d591..1418a4e78 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/feed/LocalFeedUpdater.java
@@ -169,7 +169,7 @@ public class LocalFeedUpdater {
try {
loadMetadata(item, file, context);
} catch (Exception e) {
- item.setDescription(e.getMessage());
+ item.setDescriptionIfLonger(e.getMessage());
}
return item;
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java
index 7aa5f8abe..4899716e9 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java
@@ -651,10 +651,7 @@ public final class DBReader {
if (cursor.moveToFirst()) {
int indexDescription = cursor.getColumnIndex(PodDBAdapter.KEY_DESCRIPTION);
String description = cursor.getString(indexDescription);
- int indexContentEncoded = cursor.getColumnIndex(PodDBAdapter.KEY_CONTENT_ENCODED);
- String contentEncoded = cursor.getString(indexContentEncoded);
- item.setDescription(description);
- item.setContentEncoded(contentEncoded);
+ item.setDescriptionIfLonger(description);
}
} finally {
adapter.close();
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java
index 93bc74ea8..c3f03a841 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java
@@ -305,15 +305,21 @@ class DBUpgrader {
+ " ADD COLUMN " + PodDBAdapter.KEY_IMAGE_URL + " TEXT DEFAULT NULL");
}
if (oldVersion < 1090001) {
- db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS +
- " ADD COLUMN " + PodDBAdapter.KEY_FEED_SKIP_INTRO + " INTEGER DEFAULT 0;");
- db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS +
- " ADD COLUMN " + PodDBAdapter.KEY_FEED_SKIP_ENDING + " INTEGER DEFAULT 0;");
+ db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
+ + " ADD COLUMN " + PodDBAdapter.KEY_FEED_SKIP_INTRO + " INTEGER DEFAULT 0;");
+ db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
+ + " ADD COLUMN " + PodDBAdapter.KEY_FEED_SKIP_ENDING + " INTEGER DEFAULT 0;");
}
if (oldVersion < 2020000) {
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
+ " ADD COLUMN " + PodDBAdapter.KEY_EPISODE_NOTIFICATION + " INTEGER DEFAULT 0;");
}
+ if (oldVersion < 2030000) {
+ db.execSQL("UPDATE " + PodDBAdapter.TABLE_NAME_FEED_ITEMS
+ + " SET " + PodDBAdapter.KEY_DESCRIPTION + " = content_encoded, content_encoded = NULL "
+ + "WHERE length(" + PodDBAdapter.KEY_DESCRIPTION + ") < length(content_encoded)");
+ db.execSQL("UPDATE " + PodDBAdapter.TABLE_NAME_FEED_ITEMS + " SET content_encoded = NULL");
+ }
}
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
index 445b1945b..54f5f3fa4 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
@@ -52,7 +52,7 @@ public class PodDBAdapter {
private static final String TAG = "PodDBAdapter";
public static final String DATABASE_NAME = "Antennapod.db";
- public static final int VERSION = 2020000;
+ public static final int VERSION = 2030000;
/**
* Maximum number of arguments for IN-operator.
@@ -84,7 +84,6 @@ public class PodDBAdapter {
public static final String KEY_FEEDFILETYPE = "feedfile_type";
public static final String KEY_COMPLETION_DATE = "completion_date";
public static final String KEY_FEEDITEM = "feeditem";
- public static final String KEY_CONTENT_ENCODED = "content_encoded";
public static final String KEY_PAYMENT_LINK = "payment_link";
public static final String KEY_START = "start";
public static final String KEY_LANGUAGE = "language";
@@ -158,9 +157,9 @@ public class PodDBAdapter {
+ KEY_EPISODE_NOTIFICATION + " INTEGER DEFAULT 0)";
private static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE "
- + TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
- + " TEXT," + KEY_CONTENT_ENCODED + " TEXT," + KEY_PUBDATE
- + " INTEGER," + KEY_READ + " INTEGER," + KEY_LINK + " TEXT,"
+ + TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY
+ + KEY_TITLE + " TEXT," + KEY_PUBDATE + " INTEGER,"
+ + KEY_READ + " INTEGER," + KEY_LINK + " TEXT,"
+ KEY_DESCRIPTION + " TEXT," + KEY_PAYMENT_LINK + " TEXT,"
+ KEY_MEDIA + " INTEGER," + KEY_FEED + " INTEGER,"
+ KEY_HAS_CHAPTERS + " INTEGER," + KEY_ITEM_IDENTIFIER + " TEXT,"
@@ -311,8 +310,7 @@ public class PodDBAdapter {
private static final String SELECT_FEED_ITEMS_AND_MEDIA_WITH_DESCRIPTION =
"SELECT " + KEYS_FEED_ITEM_WITHOUT_DESCRIPTION + ", " + KEYS_FEED_MEDIA + ", "
- + TABLE_NAME_FEED_ITEMS + "." + KEY_DESCRIPTION + ", "
- + TABLE_NAME_FEED_ITEMS + "." + KEY_CONTENT_ENCODED
+ + TABLE_NAME_FEED_ITEMS + "." + KEY_DESCRIPTION
+ " FROM " + TABLE_NAME_FEED_ITEMS
+ JOIN_FEED_ITEM_AND_MEDIA;
private static final String SELECT_FEED_ITEMS_AND_MEDIA =
@@ -627,9 +625,6 @@ public class PodDBAdapter {
if (item.getDescription() != null) {
values.put(KEY_DESCRIPTION, item.getDescription());
}
- if (item.getContentEncoded() != null) {
- values.put(KEY_CONTENT_ENCODED, item.getContentEncoded());
- }
values.put(KEY_PUBDATE, item.getPubDate().getTime());
values.put(KEY_PAYMENT_LINK, item.getPaymentLink());
if (saveFeed && item.getFeed() != null) {
@@ -964,7 +959,7 @@ public class PodDBAdapter {
* Return the description and content_encoded of item
*/
public final Cursor getDescriptionOfItem(final FeedItem item) {
- final String query = "SELECT " + KEY_DESCRIPTION + ", " + KEY_CONTENT_ENCODED
+ final String query = "SELECT " + KEY_DESCRIPTION
+ " FROM " + TABLE_NAME_FEED_ITEMS
+ " WHERE " + KEY_ID + "=" + item.getId();
return db.rawQuery(query, null);
@@ -1317,8 +1312,6 @@ public class PodDBAdapter {
.append("(")
.append(KEY_DESCRIPTION + " LIKE '%").append(queryWords[i])
.append("%' OR ")
- .append(KEY_CONTENT_ENCODED).append(" LIKE '%").append(queryWords[i])
- .append("%' OR ")
.append(KEY_TITLE).append(" LIKE '%").append(queryWords[i])
.append("%') ");
diff --git a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSContent.java b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSContent.java
index 306b79c15..bedf377aa 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSContent.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSContent.java
@@ -5,23 +5,21 @@ import org.xml.sax.Attributes;
import de.danoeh.antennapod.core.syndication.handler.HandlerState;
public class NSContent extends Namespace {
- public static final String NSTAG = "content";
- public static final String NSURI = "http://purl.org/rss/1.0/modules/content/";
-
- private static final String ENCODED = "encoded";
-
- @Override
- public SyndElement handleElementStart(String localName, HandlerState state,
- Attributes attributes) {
- return new SyndElement(localName, this);
- }
+ public static final String NSTAG = "content";
+ public static final String NSURI = "http://purl.org/rss/1.0/modules/content/";
- @Override
- public void handleElementEnd(String localName, HandlerState state) {
- if (ENCODED.equals(localName) && state.getCurrentItem() != null &&
- state.getContentBuf() != null) {
- state.getCurrentItem().setContentEncoded(state.getContentBuf().toString());
- }
- }
+ private static final String ENCODED = "encoded";
+
+ @Override
+ public SyndElement handleElementStart(String localName, HandlerState state, Attributes attributes) {
+ return new SyndElement(localName, this);
+ }
+
+ @Override
+ public void handleElementEnd(String localName, HandlerState state) {
+ if (ENCODED.equals(localName) && state.getCurrentItem() != null && state.getContentBuf() != null) {
+ state.getCurrentItem().setDescriptionIfLonger(state.getContentBuf().toString());
+ }
+ }
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSITunes.java b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSITunes.java
index c57d6a5d1..1dc8d8af3 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSITunes.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSITunes.java
@@ -7,7 +7,6 @@ import androidx.core.text.HtmlCompat;
import org.xml.sax.Attributes;
-import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.syndication.handler.HandlerState;
import de.danoeh.antennapod.core.syndication.parsers.DurationParser;
@@ -90,7 +89,7 @@ public class NSITunes extends Namespace {
}
if (state.getCurrentItem() != null) {
if (TextUtils.isEmpty(state.getCurrentItem().getDescription())) {
- state.getCurrentItem().setDescription(subtitle);
+ state.getCurrentItem().setDescriptionIfLonger(subtitle);
}
} else {
if (state.getFeed() != null && TextUtils.isEmpty(state.getFeed().getDescription())) {
@@ -105,16 +104,10 @@ public class NSITunes extends Namespace {
return;
}
- FeedItem currentItem = state.getCurrentItem();
- String description = getDescription(currentItem);
- if (currentItem != null && description.length() * 1.25 < summary.length()) {
- currentItem.setDescription(summary);
+ if (state.getCurrentItem() != null) {
+ state.getCurrentItem().setDescriptionIfLonger(summary);
} else if (NSRSS20.CHANNEL.equals(secondElementName) && state.getFeed() != null) {
state.getFeed().setDescription(summary);
}
}
-
- private String getDescription(FeedItem item) {
- return (item != null && item.getDescription() != null) ? item.getDescription() : "";
- }
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSMedia.java b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSMedia.java
index 30b01f0bc..b5d5a1b3f 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSMedia.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSMedia.java
@@ -121,9 +121,8 @@ public class NSMedia extends Namespace {
public void handleElementEnd(String localName, HandlerState state) {
if (DESCRIPTION.equals(localName)) {
String content = state.getContentBuf().toString();
- if (state.getCurrentItem() != null && content != null
- && state.getCurrentItem().getDescription() == null) {
- state.getCurrentItem().setDescription(content);
+ if (state.getCurrentItem() != null) {
+ state.getCurrentItem().setDescriptionIfLonger(content);
}
}
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSRSS20.java b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSRSS20.java
index 45c5d4884..b1cd6d1c2 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSRSS20.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSRSS20.java
@@ -13,10 +13,7 @@ import de.danoeh.antennapod.core.syndication.util.SyndTypeUtils;
import de.danoeh.antennapod.core.util.DateUtils;
/**
- * SAX-Parser for reading RSS-Feeds
- *
- * @author daniel
- *
+ * SAX-Parser for reading RSS-Feeds.
*/
public class NSRSS20 extends Namespace {
@@ -83,8 +80,7 @@ public class NSRSS20 extends Namespace {
if (state.getCurrentItem() != null) {
FeedItem currentItem = state.getCurrentItem();
// the title tag is optional in RSS 2.0. The description is used
- // as a
- // title if the item has no title-tag.
+ // as a title if the item has no title-tag.
if (currentItem.getTitle() == null) {
currentItem.setTitle(currentItem.getDescription());
}
@@ -138,7 +134,7 @@ public class NSRSS20 extends Namespace {
if (CHANNEL.equals(second) && state.getFeed() != null) {
state.getFeed().setDescription(content);
} else if (ITEM.equals(second) && state.getCurrentItem() != null) {
- state.getCurrentItem().setDescription(content);
+ state.getCurrentItem().setDescriptionIfLonger(content);
}
} else if (LANGUAGE.equals(localName) && state.getFeed() != null) {
state.getFeed().setLanguage(content.toLowerCase());
diff --git a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java
index 7e4350fd4..42f787d98 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java
@@ -198,10 +198,10 @@ public class NSAtom extends Namespace {
state.getFeed().setDescription(textElement.getProcessedContent());
} else if (CONTENT.equals(top) && ENTRY.equals(second) && textElement != null &&
state.getCurrentItem() != null) {
- state.getCurrentItem().setDescription(textElement.getProcessedContent());
- } else if (SUMMARY.equals(top) && ENTRY.equals(second) && textElement != null &&
- state.getCurrentItem() != null && state.getCurrentItem().getDescription() == null) {
- state.getCurrentItem().setDescription(textElement.getProcessedContent());
+ state.getCurrentItem().setDescriptionIfLonger(textElement.getProcessedContent());
+ } else if (SUMMARY.equals(top) && ENTRY.equals(second) && textElement != null
+ && state.getCurrentItem() != null) {
+ state.getCurrentItem().setDescriptionIfLonger(textElement.getProcessedContent());
} else if (UPDATED.equals(top) && ENTRY.equals(second) && state.getCurrentItem() != null &&
state.getCurrentItem().getPubDate() == null) {
state.getCurrentItem().setPubDate(DateUtils.parse(content));