@Override public synchronized void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (cursor != null) { cursorSeenYet = true; if (cursor.getCount() < 1) { triggerRefresh(1, 0); } else { if (!firstStorySeenYet) { // once we have at least a single story, we can instruct the sync service as to how to // safely // activate new stories we recieve firstStorySeenYet = true; cursor.moveToFirst(); long cutoff = cursor.getLong(cursor.getColumnIndex(DatabaseConstants.STORY_TIMESTAMP)); cursor.moveToPosition(-1); if (activity.getStoryOrder() == StoryOrder.NEWEST) { NBSyncService.setActivationMode(NBSyncService.ActivationMode.OLDER, cutoff); } else { NBSyncService.setActivationMode(NBSyncService.ActivationMode.NEWER, cutoff); } } } adapter.swapCursor(cursor); } updateLoadingMessage(); }
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); int truePosition = menuInfo.position - 1; Story story = adapter.getStory(truePosition); Activity activity = getActivity(); switch (item.getItemId()) { case R.id.menu_mark_story_as_read: FeedUtils.markStoryAsRead(story, activity); return true; case R.id.menu_mark_story_as_unread: FeedUtils.markStoryUnread(story, activity); return true; case R.id.menu_mark_older_stories_as_read: FeedUtils.markFeedsRead(getFeedSet(), story.timestamp, null, activity); return true; case R.id.menu_mark_newer_stories_as_read: FeedUtils.markFeedsRead(getFeedSet(), null, story.timestamp, activity); return true; case R.id.menu_send_story: FeedUtils.sendStory(story, activity); return true; case R.id.menu_save_story: FeedUtils.setStorySaved(story, true, activity); return true; case R.id.menu_unsave_story: FeedUtils.setStorySaved(story, false, activity); return true; default: return super.onContextItemSelected(item); } }
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { MenuInflater inflater = getActivity().getMenuInflater(); if (PrefsUtils.getStoryOrder(activity, getFeedSet()) == StoryOrder.NEWEST) { inflater.inflate(R.menu.context_story_newest, menu); } else { inflater.inflate(R.menu.context_story_oldest, menu); } int truePosition = ((AdapterView.AdapterContextMenuInfo) menuInfo).position - 1; Story story = adapter.getStory(truePosition); if (story.read) { menu.removeItem(R.id.menu_mark_story_as_read); } else { menu.removeItem(R.id.menu_mark_story_as_unread); } if (story.starred) { menu.removeItem(R.id.menu_save_story); } else { menu.removeItem(R.id.menu_unsave_story); } }
@Override public void onLoaderReset(Loader<Cursor> loader) { if (adapter != null) adapter.notifyDataSetInvalidated(); }