@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); int selectedPosition = ((AdapterView.AdapterContextMenuInfo) menuInfo).position; Resources res = getResources(); @SuppressWarnings("unused") MenuItem item; mSelectedCard = mDeck.cardFromId(Long.parseLong(mCards.get(selectedPosition).get("id"))); if (mSelectedCard.isMarked()) { item = menu.add( Menu.NONE, CONTEXT_MENU_MARK, Menu.NONE, res.getString(R.string.card_browser_unmark_card)); mIsMarked = true; Log.i(AnkiDroidApp.TAG, "Selected Card is currently marked"); } else { item = menu.add( Menu.NONE, CONTEXT_MENU_MARK, Menu.NONE, res.getString(R.string.card_browser_mark_card)); mIsMarked = false; } if (mSelectedCard.getSuspendedState()) { item = menu.add( Menu.NONE, CONTEXT_MENU_SUSPEND, Menu.NONE, res.getString(R.string.card_browser_unsuspend_card)); mIsSuspended = true; Log.i(AnkiDroidApp.TAG, "Selected Card is currently suspended"); } else { item = menu.add( Menu.NONE, CONTEXT_MENU_SUSPEND, Menu.NONE, res.getString(R.string.card_browser_suspend_card)); mIsSuspended = false; } item = menu.add( Menu.NONE, CONTEXT_MENU_DELETE, Menu.NONE, res.getString(R.string.card_browser_delete_card)); item = menu.add( Menu.NONE, CONTEXT_MENU_DETAILS, Menu.NONE, res.getString(R.string.card_browser_card_details)); menu.setHeaderTitle(mCards.get(selectedPosition).get("question")); }
@Override public void onPostExecute(DeckTask.TaskData result) { mUndoRedoCardId = result.getLong(); String undoType = result.getString(); if (undoType.equals(Deck.UNDO_TYPE_DELETE_CARD)) { int position = getPosition(mDeletedCards, mUndoRedoCardId); if (position != -1) { HashMap<String, String> data = new HashMap<String, String>(); data.put("id", mDeletedCards.get(position).get("id")); data.put("question", mDeletedCards.get(position).get("question")); data.put("answer", mDeletedCards.get(position).get("answer")); data.put("marSus", mDeletedCards.get(position).get("marSus")); mAllCards.add(Integer.parseInt(mDeletedCards.get(position).get("allCardPos")), data); mDeletedCards.remove(position); updateCardsList(); } else { deleteCard(Long.toString(mUndoRedoCardId), getPosition(mCards, mUndoRedoCardId)); } mProgressDialog.dismiss(); } else { mUndoRedoCard = mDeck.cardFromId(mUndoRedoCardId); if (undoType.equals(Deck.UNDO_TYPE_EDIT_CARD)) { mUndoRedoCard.fromDB(mUndoRedoCardId); int pos = getPosition(mAllCards, mUndoRedoCardId); updateCard(mUndoRedoCard, mAllCards, pos); pos = getPosition(mCards, mUndoRedoCardId); if (pos != -1) { updateCard(mUndoRedoCard, mCards, pos); } updateList(); mProgressDialog.dismiss(); } else if (undoType.equals(Deck.UNDO_TYPE_MARK_CARD)) { markCards(mUndoRedoCard.getFactId(), mUndoRedoCard.isMarked()); mProgressDialog.dismiss(); } else if (undoType.equals(Deck.UNDO_TYPE_SUSPEND_CARD)) { suspendCard( mUndoRedoCard, getPosition(mCards, mUndoRedoCardId), mUndoRedoCard.getSuspendedState()); mProgressDialog.dismiss(); } else { mUndoRedoDialogShowing = true; getCards(); } } }