From bd1b07150bf8946fcdce4e067954bc9bf8578cfa Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Sat, 27 Oct 2012 22:36:35 +0200 Subject: [PATCH] Renamed methods --- src/de/danoeh/antennapod/feed/Feed.java | 9 +++++++ src/de/danoeh/antennapod/feed/FeedItem.java | 27 ++++++++++++++----- .../danoeh/antennapod/feed/FeedManager.java | 3 +++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/de/danoeh/antennapod/feed/Feed.java b/src/de/danoeh/antennapod/feed/Feed.java index 7915791a5..c3677447b 100644 --- a/src/de/danoeh/antennapod/feed/Feed.java +++ b/src/de/danoeh/antennapod/feed/Feed.java @@ -143,6 +143,15 @@ public class Feed extends FeedFile { return download_url; } } + + /** Calls cacheDescriptions on all items. */ + protected void cacheDescriptionsOfItems() { + if (items != null) { + for (FeedItem item : items) { + item.cacheDescriptions(); + } + } + } @Override public int getTypeAsInt() { diff --git a/src/de/danoeh/antennapod/feed/FeedItem.java b/src/de/danoeh/antennapod/feed/FeedItem.java index 71a327ee7..ebfff80ad 100644 --- a/src/de/danoeh/antennapod/feed/FeedItem.java +++ b/src/de/danoeh/antennapod/feed/FeedItem.java @@ -25,10 +25,10 @@ public class FeedItem extends FeedComponent { * only be set by the parser. */ private String contentEncoded; - + private SoftReference cachedDescription; private SoftReference cachedContentEncoded; - + private String link; private Date pubDate; private FeedMedia media; @@ -41,6 +41,21 @@ public class FeedItem extends FeedComponent { this.read = true; } + /** + * Moves the 'description' and 'contentEncoded' field of feeditem to their + * SoftReference fields. + */ + protected void cacheDescriptions() { + if (description != null) { + cachedDescription = new SoftReference(description); + } + if (contentEncoded != null) { + cachedContentEncoded = new SoftReference(contentEncoded); + } + description = null; + contentEncoded = null; + } + /** Get the chapter that fits the position. */ public Chapter getCurrentChapter(int position) { Chapter current = null; @@ -135,8 +150,8 @@ public class FeedItem extends FeedComponent { public String getContentEncoded() { if (contentEncoded == null && cachedContentEncoded != null) { - return cachedContentEncoded.get(); - + return cachedContentEncoded.get(); + } return contentEncoded; } @@ -168,11 +183,11 @@ public class FeedItem extends FeedComponent { public void setItemIdentifier(String itemIdentifier) { this.itemIdentifier = itemIdentifier; } - + public void setCachedDescription(String d) { cachedDescription = new SoftReference(d); } - + public void setCachedContentEncoded(String c) { cachedContentEncoded = new SoftReference(c); } diff --git a/src/de/danoeh/antennapod/feed/FeedManager.java b/src/de/danoeh/antennapod/feed/FeedManager.java index a8681fa2c..7d06f6724 100644 --- a/src/de/danoeh/antennapod/feed/FeedManager.java +++ b/src/de/danoeh/antennapod/feed/FeedManager.java @@ -774,6 +774,7 @@ public class FeedManager { PodDBAdapter adapter = new PodDBAdapter(context); adapter.open(); adapter.setCompleteFeed(feed); + feed.cacheDescriptionsOfItems(); adapter.close(); } }); @@ -867,6 +868,7 @@ public class FeedManager { public void setFeed(Feed feed, PodDBAdapter adapter) { if (adapter != null) { adapter.setFeed(feed); + feed.cacheDescriptionsOfItems(); } else { Log.w(TAG, "Adapter in setFeed was null"); } @@ -914,6 +916,7 @@ public class FeedManager { PodDBAdapter adapter = new PodDBAdapter(context); adapter.open(); adapter.setFeed(feed); + feed.cacheDescriptionsOfItems(); adapter.close(); } });