示例#1
0
  /**
   * the actual implementation of query. This just does a straight attempt to query for up to {@link
   * #requiredCount} flashcards from the table starting at the given id and level. This function
   * will not attempt to wrap to the beginning of the table if insufficient results were found.
   *
   * <p>The results of this query will be added to the passed in {@link QueryResult} object.
   */
  private void queryNoWrap(QueryResult qr, int level, int minId, int requiredCount) {
    Cursor c = _curDB.rawQuery(SQL_QUERY2, new String[] {"" + minId});
    if (c.moveToFirst()) {
      do {
        // extract fc from cursor and prepend to result chain.
        Flashcard fc = cursorToFlashcard(c);
        qr.head = Flashcard.Chain.append(qr.head, fc);

        if (fc.getID() > qr.maxId) qr.maxId = fc.getID();
        ++qr.count;
      } while (c.moveToNext() && qr.count < requiredCount);
    }
    c.close();
  }
示例#2
0
  /** update the level and count for the given flashcard in the database. */
  private void updateFlashcard(Flashcard fc) {
    openDB();

    _curDB.beginTransaction();
    try {
      // Delete old entry if any.
      SQLiteStatement dStmt = getCompiledStatement(SQL_DELETE_FCS);
      dStmt.bindString(1, fc.getLang1Str());
      dStmt.execute();

      // insert new state entry.
      SQLiteStatement iStmt = getCompiledStatement(SQL_INSERT_FCS);
      iStmt.bindString(1, fc.getLang1Str());
      iStmt.bindLong(2, fc.getLevel());
      iStmt.bindLong(3, fc.getRightGuessCount());
      iStmt.execute();
      _curDB.setTransactionSuccessful();
    } catch (SQLException e) {
      MsgDispatcher.sendMessageToUI(
          MsgType.MSG_SHOW_ERROR_MSG, 0, 0, "unable to update id=" + fc.getID());
    } finally {
      _curDB.endTransaction();
    }

    // this flashcard is no longer used by anyone so release it.
    fc.release();
  }
示例#3
0
  /**
   * update the display to show the current flashcard. Either the entire flashcard is shown or just
   * the first half depending on the value of the {@link #_showEntireCard} variable.
   */
  private void updateDisplay() {
    Flashcard fc = FlashcardApp.getInstance().getCurrentFlashcard();
    if (fc == null) {
      return;
    }

    String lang1Text = fc.getLang1Str();
    String lang2Text = "";
    if (FlashcardApp.getInstance().isShowEntireCard()) {
      lang2Text = fc.getLang2Str();
    }

    _topText.setText(StringFormatter.formatEnglishString(lang1Text));
    _bottomText.setText(StringFormatter.formatSpanishString(lang2Text));
    _statusText.setText(
        "id: "
            + fc.getID()
            + "   level: "
            + fc.getLevel()
            + "   count: "
            + fc.getRightGuessCount());
  }