Exemple #1
0
  private Card cardFromId(long id) {
    if (id == 0) return null;
    Card card = new Card();
    boolean result = card.fromDB(id);

    if (!result) return null;
    card.genFuzz();
    card.startTimer();
    return card;
  }
 @Override
 public void onProgressUpdate(DeckTask.TaskData... values) {
   mSelectedCard.fromDB(mSelectedCard.getId());
   int pos = getPosition(mAllCards, mSelectedCard.getId());
   updateCard(mSelectedCard, mAllCards, pos);
   pos = getPosition(mCards, mSelectedCard.getId());
   if (pos != -1) {
     updateCard(mSelectedCard, mCards, pos);
   }
   updateList();
 }
 @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();
     }
   }
 }
Exemple #4
0
  // TODO: The real methods to update cards on Anki should be implemented instead of this
  public void updateAllCards() {
    Cursor cursor = AnkiDb.database.rawQuery("SELECT id, factId " + "FROM cards", null);

    while (cursor.moveToNext()) {
      // Get card
      Card card = new Card();
      card.fromDB(cursor.getLong(0));
      Log.i(TAG, "Card id = " + card.id);

      // Get the related fact
      Fact fact = card.getFact();
      // Log.i(TAG, "Fact id = " + fact.id);

      // Generate the question and answer for this card and update it
      HashMap<String, String> newQA = CardModel.formatQA(fact, card.getCardModel());
      card.question = newQA.get("question");
      Log.i(TAG, "Question = " + card.question);
      card.answer = newQA.get("answer");
      Log.i(TAG, "Answer = " + card.answer);
      card.modified = System.currentTimeMillis() / 1000.0;

      card.toDB();
    }
  }