summaryrefslogtreecommitdiff
path: root/src/de
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-10-27 22:15:22 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-10-27 22:15:22 +0200
commit6fc11c7baef3b7f5b2704d22a5c60764f863923c (patch)
tree611a8f6acf640c80a4546b805ee298644aa88cd9 /src/de
parent6a4abe1e854d17ea502349cb9d7e8b1f8fc737fc (diff)
downloadAntennaPod-6fc11c7baef3b7f5b2704d22a5c60764f863923c.zip
Added cachedDescription and cachedContentEncoded
Diffstat (limited to 'src/de')
-rw-r--r--src/de/danoeh/antennapod/feed/FeedItem.java40
-rw-r--r--src/de/danoeh/antennapod/feed/FeedManager.java4
-rw-r--r--src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java36
3 files changed, 58 insertions, 22 deletions
diff --git a/src/de/danoeh/antennapod/feed/FeedItem.java b/src/de/danoeh/antennapod/feed/FeedItem.java
index a8bb0dbb4..2ac7fec63 100644
--- a/src/de/danoeh/antennapod/feed/FeedItem.java
+++ b/src/de/danoeh/antennapod/feed/FeedItem.java
@@ -1,5 +1,6 @@
package de.danoeh.antennapod.feed;
+import java.lang.ref.SoftReference;
import java.util.Date;
import java.util.List;
@@ -11,11 +12,23 @@ import java.util.List;
*/
public class FeedItem extends FeedComponent {
- /** The id/guid that can be found in the rss/atom feed. Might not be set.*/
+ /** The id/guid that can be found in the rss/atom feed. Might not be set. */
private String itemIdentifier;
private String title;
+ /**
+ * The description of a feeditem. This field should only be set by the
+ * parser.
+ */
private String description;
+ /**
+ * The content of the content-encoded tag of a feeditem. This field should
+ * only be set by the parser.
+ */
private String contentEncoded;
+
+ private SoftReference<String> cachedDescription;
+ private SoftReference<String> cachedContentEncoded;
+
private String link;
private Date pubDate;
private FeedMedia media;
@@ -60,11 +73,12 @@ public class FeedItem extends FeedComponent {
public Chapter getCurrentChapter() {
return getCurrentChapter(media.getPosition());
}
-
- /** Returns the value that uniquely identifies this FeedItem.
- * If the itemIdentifier attribute is not null, it will be returned.
- * Else it will try to return the title. If the title is not given, it will
- * use the link of the entry.
+
+ /**
+ * Returns the value that uniquely identifies this FeedItem. If the
+ * itemIdentifier attribute is not null, it will be returned. Else it will
+ * try to return the title. If the title is not given, it will use the link
+ * of the entry.
* */
public String getIdentifyingValue() {
if (itemIdentifier != null) {
@@ -85,6 +99,9 @@ public class FeedItem extends FeedComponent {
}
public String getDescription() {
+ if (description == null && cachedDescription != null) {
+ return cachedDescription.get();
+ }
return description;
}
@@ -129,6 +146,10 @@ public class FeedItem extends FeedComponent {
}
public String getContentEncoded() {
+ if (contentEncoded == null && cachedContentEncoded != null) {
+ return cachedContentEncoded.get();
+
+ }
return contentEncoded;
}
@@ -160,5 +181,12 @@ public class FeedItem extends FeedComponent {
this.itemIdentifier = itemIdentifier;
}
+ public void setCachedDescription(String d) {
+ cachedDescription = new SoftReference<String>(d);
+ }
+
+ public void setCachedContentEncoded(String c) {
+ cachedContentEncoded = new SoftReference<String>(c);
+ }
}
diff --git a/src/de/danoeh/antennapod/feed/FeedManager.java b/src/de/danoeh/antennapod/feed/FeedManager.java
index 86ab31475..a8681fa2c 100644
--- a/src/de/danoeh/antennapod/feed/FeedManager.java
+++ b/src/de/danoeh/antennapod/feed/FeedManager.java
@@ -1331,9 +1331,9 @@ public class FeedManager {
adapter.open();
Cursor extraCursor = adapter.getExtraInformationOfItem(item);
if (extraCursor.moveToFirst()) {
- item.setDescription(extraCursor
+ item.setCachedDescription(extraCursor
.getString(PodDBAdapter.IDX_FI_EXTRA_DESCRIPTION));
- item.setContentEncoded(extraCursor
+ item.setCachedContentEncoded(extraCursor
.getString(PodDBAdapter.IDX_FI_EXTRA_CONTENT_ENCODED));
}
adapter.close();
diff --git a/src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java b/src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java
index 2322a4e3c..9dc48d465 100644
--- a/src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java
+++ b/src/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java
@@ -104,25 +104,23 @@ public class ItemDescriptionFragment extends SherlockFragment {
}
}
- @SuppressLint("NewApi")
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (item != null) {
- FeedManager.getInstance().loadExtraInformationOfItem(getActivity(),
- item, new FeedManager.TaskCallback() {
-
- @Override
- public void onCompletion() {
- webViewLoader = createLoader();
- if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
- webViewLoader
- .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
- } else {
- webViewLoader.execute();
+ if (item.getDescription() == null && item.getDescription() == null) {
+ Log.i(TAG, "Loading data");
+ FeedManager.getInstance().loadExtraInformationOfItem(
+ getActivity(), item, new FeedManager.TaskCallback() {
+ @Override
+ public void onCompletion() {
+ startLoader();
}
- }
- });
+ });
+ } else {
+ Log.i(TAG, "Using cached data");
+ startLoader();
+ }
} else {
Log.e(TAG, "Error in onViewCreated: Item was null");
}
@@ -133,6 +131,16 @@ public class ItemDescriptionFragment extends SherlockFragment {
super.onResume();
}
+ @SuppressLint("NewApi")
+ private void startLoader() {
+ webViewLoader = createLoader();
+ if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
+ webViewLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ } else {
+ webViewLoader.execute();
+ }
+ }
+
private AsyncTask<Void, Void, Void> createLoader() {
return new AsyncTask<Void, Void, Void>() {
@Override