diff --git a/clients/android/NewsBlur/src/com/newsblur/database/ReadingAdapter.java b/clients/android/NewsBlur/src/com/newsblur/database/ReadingAdapter.java index 1dfdcbb47..93cf0cf5c 100644 --- a/clients/android/NewsBlur/src/com/newsblur/database/ReadingAdapter.java +++ b/clients/android/NewsBlur/src/com/newsblur/database/ReadingAdapter.java @@ -21,8 +21,10 @@ import com.newsblur.util.FeedUtils; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -47,6 +49,9 @@ public class ReadingAdapter extends PagerAdapter { // the live list of stories being used by the adapter private List stories = new ArrayList(0); + // classifiers for each feed seen in the story list + private Map classifiers = new HashMap(0); + private final ExecutorService executorService; public ReadingAdapter(FragmentManager fm, String sourceUserId, boolean showFeedMetadata, Reading activity) { @@ -93,15 +98,24 @@ public class ReadingAdapter extends PagerAdapter { } else { if (c.isClosed()) return; newStories = new ArrayList(c.getCount()); + // keep track of which feeds are in this story set so we can also fetch Classifiers + Set feedIdsSeen = new HashSet(); c.moveToPosition(-1); while (c.moveToNext()) { if (c.isClosed()) return; Story s = Story.fromCursor(c); s.bindExternValues(c); newStories.add(s); + feedIdsSeen.add(s.feedId); + } + for (String feedId : feedIdsSeen) { + classifiers.put(feedId, FeedUtils.dbHelper.getClassifierForFeed(feedId)); } } } catch (Exception e) { + // because we use interruptable loaders that auto-close cursors, it is expected + // that cursors will sometimes go bad. this is a useful signal to stop the thaw + // thread and let it start on a fresh cursor. com.newsblur.util.Log.e(this, "error thawing story list: " + e.getMessage(), e); return; } @@ -133,9 +147,6 @@ public class ReadingAdapter extends PagerAdapter { } private ReadingItemFragment createFragment(Story story) { - // TODO: classifiers should be pre-fetched by loaders? - Classifier classifier = FeedUtils.dbHelper.getClassifierForFeed(story.feedId); - return ReadingItemFragment.newInstance(story, story.extern_feedTitle, story.extern_feedColor, @@ -143,7 +154,7 @@ public class ReadingAdapter extends PagerAdapter { story.extern_faviconBorderColor, story.extern_faviconTextColor, story.extern_faviconUrl, - classifier, + classifiers.get(story.feedId), showFeedMetadata, sourceUserId); }