Clean up leaky cursors.

This commit is contained in:
ojiikun 2014-01-22 23:24:17 +00:00
parent 3a26a533f5
commit d9b26d5530
3 changed files with 10 additions and 0 deletions

View file

@ -61,6 +61,7 @@ public class AllSharedStoriesItemListFragment extends ItemListFragment implement
groupFrom = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_SHORTDATE, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS, DatabaseConstants.FEED_TITLE };
groupTo = new int[] { R.id.row_item_title, R.id.row_item_author, R.id.row_item_title, R.id.row_item_date, R.id.row_item_sidebar, R.id.row_item_feedtitle };
// TODO: defer creation of the adapter until the loader's first callback so we don't leak this first cursor
Cursor cursor = contentResolver.query(FeedProvider.ALL_SHARED_STORIES_URI, null, DatabaseConstants.getStorySelectionFromState(currentState), null, DatabaseConstants.getStorySortOrder(storyOrder));
adapter = new MultipleFeedItemsAdapter(getActivity(), R.layout.row_socialitem, cursor, groupFrom, groupTo, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
adapter.setViewBinder(new SocialItemViewBinder(getActivity()));

View file

@ -68,6 +68,7 @@ public class FeedItemListFragment extends StoryItemListFragment implements Loade
itemList.setEmptyView(v.findViewById(R.id.empty_view));
ContentResolver contentResolver = getActivity().getContentResolver();
// TODO: defer creation of the adapter until the loader's first callback so we don't leak this first stories cursor
Uri storiesUri = FeedProvider.FEED_STORIES_URI.buildUpon().appendPath(feedId).build();
Cursor storiesCursor = contentResolver.query(storiesUri, null, DatabaseConstants.getStorySelectionFromState(currentState), null, DatabaseConstants.getStorySortOrder(storyOrder));
Uri feedUri = FeedProvider.FEEDS_URI.buildUpon().appendPath(feedId).build();
@ -85,6 +86,7 @@ public class FeedItemListFragment extends StoryItemListFragment implements Loade
feedCursor.moveToFirst();
Feed feed = Feed.fromCursor(feedCursor);
feedCursor.close();
String[] groupFrom = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_READ, DatabaseConstants.STORY_SHORTDATE, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS };
int[] groupTo = new int[] { R.id.row_item_title, R.id.row_item_author, R.id.row_item_title, R.id.row_item_date, R.id.row_item_sidebar };

View file

@ -110,6 +110,7 @@ public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
Cursor userCursor = resolver.query(FeedProvider.USERS_URI, null, DatabaseConstants.USER_USERID + " IN (?)", new String[] { id }, null);
UserProfile user = UserProfile.fromCursor(userCursor);
userCursor.close();
imageLoader.displayImage(user.photoUrl, favouriteImage, 10f);
favouriteImage.setTag(id);
@ -135,6 +136,7 @@ public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
if (story != null) {
Cursor userCursor = resolver.query(FeedProvider.USERS_URI, null, DatabaseConstants.USER_USERID + " IN (?)", new String[] { comment.userId }, null);
UserProfile user = UserProfile.fromCursor(userCursor);
userCursor.close();
DialogFragment newFragment = ReplyDialogFragment.newInstance(story, comment.userId, user.username);
newFragment.show(manager, "dialog");
@ -171,15 +173,18 @@ public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
TextView replyUsername = (TextView) replyView.findViewById(R.id.reply_username);
replyUsername.setText(R.string.unknown_user);
}
replyCursor.close();
TextView replySharedDate = (TextView) replyView.findViewById(R.id.reply_shareddate);
replySharedDate.setText(reply.shortDate + " ago");
((LinearLayout) commentView.findViewById(R.id.comment_replies_container)).addView(replyView);
}
replies.close();
Cursor userCursor = resolver.query(FeedProvider.USERS_URI, null, DatabaseConstants.USER_USERID + " IN (?)", new String[] { comment.userId }, null);
UserProfile commentUser = UserProfile.fromCursor(userCursor);
userCursor.close();
TextView commentUsername = (TextView) commentView.findViewById(R.id.comment_username);
commentUsername.setText(commentUser.username);
@ -209,6 +214,7 @@ public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
imageLoader.displayImage(sourceUser.photoUrl, sourceUserImage, 10f);
imageLoader.displayImage(userPhoto, usershareImage, 10f);
}
sourceUserCursor.close();
} else {
imageLoader.displayImage(userPhoto, commentImage, 10f);
}
@ -260,6 +266,7 @@ public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
ImageView image = ViewUtils.createSharebarImage(context, imageLoader, user.photoUrl, user.userId);
sharedGrid.addView(image);
}
userCursor.close();
}
}