mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-12-01 12:31:45 +00:00
Added cachedDescription and cachedContentEncoded
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user