@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); } }