Ejemplo n.º 1
0
  private TaskData doInBackgroundSuspendCard(TaskData... params) {
    long start, stop;
    Deck deck = params[0].getDeck();
    Card oldCard = params[0].getCard();
    Card newCard;

    AnkiDb.database.beginTransaction();
    try {
      if (oldCard != null) {
        start = System.currentTimeMillis();
        deck.suspendCard(oldCard.id);
        stop = System.currentTimeMillis();
        Log.v(TAG, "doInBackgroundSuspendCard - Suspended card in " + (stop - start) + " ms.");
      }

      start = System.currentTimeMillis();
      newCard = deck.getCard();
      stop = System.currentTimeMillis();
      Log.v(TAG, "doInBackgroundSuspendCard - Loaded new card in " + (stop - start) + " ms.");
      publishProgress(new TaskData(newCard));
      AnkiDb.database.setTransactionSuccessful();
    } finally {
      AnkiDb.database.endTransaction();
    }

    return null;
  }
Ejemplo n.º 2
0
  private TaskData doInBackgroundAnswerCard(TaskData... params) {
    long start, stop;
    Deck deck = params[0].getDeck();
    Card oldCard = params[0].getCard();
    int ease = params[0].getInt();
    Card newCard;

    if (oldCard != null) {
      start = System.currentTimeMillis();
      oldCard.temporarilySetLowestPriority();
      deck.decreaseCounts(oldCard);
      stop = System.currentTimeMillis();
      Log.v(TAG, "doInBackground - Set old card 0 priority in " + (stop - start) + " ms.");
    }

    start = System.currentTimeMillis();
    newCard = deck.getCard();
    stop = System.currentTimeMillis();
    Log.v(TAG, "doInBackground - Loaded new card in " + (stop - start) + " ms.");
    publishProgress(new TaskData(newCard));

    if (ease != 0 && oldCard != null) {
      start = System.currentTimeMillis();
      deck.answerCard(oldCard, ease);
      stop = System.currentTimeMillis();
      Log.v(TAG, "doInBackground - Answered old card in " + (stop - start) + " ms.");
    }

    return null;
  }
Ejemplo n.º 3
0
  private TaskData doInBackgroundAnswerCard(TaskData... params) {
    long start, start2;
    Deck deck = params[0].getDeck();
    Card oldCard = params[0].getCard();
    int ease = params[0].getInt();
    Card newCard;

    start2 = System.currentTimeMillis();

    AnkiDb.database.beginTransaction();
    try {
      if (oldCard != null) {
        start = System.currentTimeMillis();
        deck.answerCard(oldCard, ease);
        Log.v(
            TAG,
            "doInBackgroundAnswerCard - Answered card in "
                + (System.currentTimeMillis() - start)
                + " ms.");
      }

      start = System.currentTimeMillis();
      newCard = deck.getCard();
      Log.v(
          TAG,
          "doInBackgroundAnswerCard - Loaded new card in "
              + (System.currentTimeMillis() - start)
              + " ms.");
      publishProgress(new TaskData(newCard));

      AnkiDb.database.setTransactionSuccessful();
    } finally {
      AnkiDb.database.endTransaction();
    }

    Log.w(
        TAG,
        "doInBackgroundAnswerCard - DB operations in "
            + (System.currentTimeMillis() - start2)
            + " ms.");

    return null;
  }
Ejemplo n.º 4
0
  private TaskData doInBackgroundSuspendCard(TaskData... params) {
    long start, stop;
    Deck deck = params[0].getDeck();
    Card oldCard = params[0].getCard();
    Card newCard;

    if (oldCard != null) {
      start = System.currentTimeMillis();
      deck.suspendCard(oldCard.id);
      stop = System.currentTimeMillis();
      Log.v(TAG, "doInBackgroundSuspendCard - Suspended card in " + (stop - start) + " ms.");
    }

    start = System.currentTimeMillis();
    newCard = deck.getCard();
    stop = System.currentTimeMillis();
    Log.v(TAG, "doInBackgroundSuspendCard - Loaded new card in " + (stop - start) + " ms.");
    publishProgress(new TaskData(newCard));

    return null;
  }
Ejemplo n.º 5
0
  private TaskData doInBackgroundLoadDeck(TaskData... params) {
    String deckFilename = params[0].getString();
    Log.i(TAG, "doInBackgroundLoadDeck - deckFilename = " + deckFilename);

    Log.i(TAG, "loadDeck - SD card mounted and existent file -> Loading deck...");
    try {
      // Open the right deck.
      Deck deck = Deck.openDeck(deckFilename);
      // Start by getting the first card and displaying it.
      Card card = deck.getCard();
      Log.i(TAG, "Deck loaded!");

      return new TaskData(AnkiDroid.DECK_LOADED, deck, card);
    } catch (SQLException e) {
      Log.i(TAG, "The database " + deckFilename + " could not be opened = " + e.getMessage());
      return new TaskData(AnkiDroid.DECK_NOT_LOADED);
    } catch (CursorIndexOutOfBoundsException e) {
      Log.i(TAG, "The deck has no cards = " + e.getMessage());
      ;
      return new TaskData(AnkiDroid.DECK_EMPTY);
    }
  }
    private Payload doInBackgroundLoadDeck(Payload... params) {
      Payload data = params[0];
      SharedDeckDownload download = (SharedDeckDownload) data.data[0];
      String deckFilename = mDestination + "/tmp/" + download.getTitle() + ".anki.updating";
      Log.i(AnkiDroidApp.TAG, "doInBackgroundLoadDeck - deckFilename = " + deckFilename);

      Log.i(AnkiDroidApp.TAG, "loadDeck - SD card mounted and existent file -> Loading deck...");
      try {
        // Open the right deck.
        Deck deck = Deck.openDeck(deckFilename);
        // Start by getting the first card and displaying it.
        Card card = deck.getCard();
        Log.i(AnkiDroidApp.TAG, "Deck loaded!");

        // Set the result
        data.returnType = DeckTask.DECK_LOADED;
        HashMap<String, Object> results = new HashMap<String, Object>();
        results.put("deck", deck);
        results.put("card", card);
        results.put("position", download.getNumUpdatedCards());
        data.result = results;
        return data;
      } catch (SQLException e) {
        Log.i(
            AnkiDroidApp.TAG,
            "The database " + deckFilename + " could not be opened = " + e.getMessage());
        data.success = false;
        data.returnType = DeckTask.DECK_NOT_LOADED;
        data.exception = e;
        return data;
      } catch (CursorIndexOutOfBoundsException e) {
        // XXX: Where is this exception thrown?
        Log.i(AnkiDroidApp.TAG, "The deck has no cards = " + e.getMessage());
        data.success = false;
        data.returnType = DeckTask.DECK_EMPTY;
        data.exception = e;
        return data;
      }
    }