Search in sources :

Example 11 with Card

use of com.ichi2.libanki.Card in project Anki-Android by Ramblurr.

the class CardBrowser method updateCardInList.

private void updateCardInList(Card card, String updatedCardTags) {
    Note note = card.note();
    int pos;
    for (Card c : note.cards()) {
        pos = getPosition(mCards, c.getId());
        if (pos < 0 || pos >= mCards.size()) {
            continue;
        }
        if (updatedCardTags != null) {
            mCards.get(pos).put("tags", updatedCardTags);
        }
        String sfld = note.getSFld();
        mCards.get(pos).put("sfld", sfld);
        if (mWholeCollection) {
            String deckName;
            try {
                deckName = mCol.getDecks().get(card.getDid()).getString("name");
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
            mCards.get(pos).put("deck", deckName);
        }
        String flags = Integer.toString((c.getQueue() == -1 ? 1 : 0) + (note.hasTag("marked") ? 2 : 0));
        mCards.get(pos).put("flags", flags);
    }
    updateList();
}
Also used : Note(com.ichi2.libanki.Note) JSONException(org.json.JSONException) Card(com.ichi2.libanki.Card)

Example 12 with Card

use of com.ichi2.libanki.Card in project Anki-Android by Ramblurr.

the class CardBrowser method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // FIXME:
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == DeckPicker.RESULT_DB_ERROR) {
        closeCardBrowser(DeckPicker.RESULT_DB_ERROR);
    }
    // switching back to the multimedia card editor.
    if (requestCode == EDIT_CARD && resultCode == MultimediaCardEditorActivity.RESULT_DELETED) {
        deleteNote(sCardBrowserCard);
        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDeleteNoteHandler, new DeckTask.TaskData(mCol.getSched(), sCardBrowserCard, 3));
    } else if (requestCode == EDIT_CARD && resultCode != RESULT_CANCELED) {
        Log.i(AnkiDroidApp.TAG, "CardBrowser: Saving card...");
        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UPDATE_FACT, mUpdateCardHandler, new DeckTask.TaskData(mCol.getSched(), sCardBrowserCard, false));
    } else if (requestCode == ADD_NOTE && resultCode == RESULT_OK) {
        mSearchTerms = mSearchEditText.getText().toString().toLowerCase();
        searchCards();
    }
}
Also used : TaskData(com.ichi2.async.DeckTask.TaskData) DeckTask(com.ichi2.async.DeckTask) TaskData(com.ichi2.async.DeckTask.TaskData)

Example 13 with Card

use of com.ichi2.libanki.Card in project Anki-Android by Ramblurr.

the class CardBrowser method deleteNote.

private void deleteNote(Card card) {
    ArrayList<Card> cards = card.note().cards();
    int pos;
    for (Card c : cards) {
        pos = getPosition(mCards, c.getId());
        if (pos >= 0 && pos < mCards.size()) {
            mCards.remove(pos);
        }
    }
    // Delete itself if not deleted
    pos = getPosition(mCards, card.getId());
    if (pos >= 0 && pos < mCards.size()) {
        mCards.remove(pos);
    }
    updateList();
}
Also used : Card(com.ichi2.libanki.Card)

Example 14 with Card

use of com.ichi2.libanki.Card in project Anki-Android by Ramblurr.

the class NoteService method saveMedia.

/**
     * Saves the multimedia associated with this card to proper path inside anki folder. For each field associated with
     * the note it checks for the following condition a. The field content should have changed b. The field content does
     * not already point to a media inside anki media path If both condition satisfies then it copies the file inside
     * the media path and deletes the file referenced by the note
     * 
     * @param note
     */
public static void saveMedia(final MultimediaEditableNote noteNew) {
    // if (noteNew.getModelId() == noteOld.getModelId())
    // {
    // int fieldCount = noteNew.getNumberOfFields();
    // for (int i = 0; i < fieldCount; i++)
    // {
    // IField newField = noteNew.getField(i);
    // IField oldField = noteOld.getField(i);
    // if
    // (newField.getFormattedValue().equals(oldField.getFormattedValue()))
    // {
    // continue;
    // }
    // importMediaToDirectory(newField);
    // }
    // }
    // else
    // {
    int fieldCount = noteNew.getNumberOfFields();
    for (int i = 0; i < fieldCount; i++) {
        IField newField = noteNew.getField(i);
        importMediaToDirectory(newField);
    }
// }
}
Also used : IField(com.ichi2.anki.multimediacard.fields.IField)

Example 15 with Card

use of com.ichi2.libanki.Card in project Anki-Android by Ramblurr.

the class DeckTask method doInBackgroundUndo.

private TaskData doInBackgroundUndo(TaskData... params) {
    Sched sched = params[0].getSched();
    Collection col = sched.getCol();
    try {
        col.getDb().getDatabase().beginTransaction();
        Card newCard;
        try {
            long cid = col.undo();
            if (cid != 0) {
                // a review was undone,
                newCard = col.getCard(cid);
                col.reset();
                col.getSched().decrementCounts(newCard);
                sHadCardQueue = true;
            } else {
                // TODO: do not fetch new card if a non review operation has
                // been undone
                col.reset();
                newCard = getCard(sched);
            }
            // TODO: handle leech undoing properly
            publishProgress(new TaskData(newCard, 0));
            col.getDb().getDatabase().setTransactionSuccessful();
        } finally {
            col.getDb().getDatabase().endTransaction();
        }
    } catch (RuntimeException e) {
        Log.e(AnkiDroidApp.TAG, "doInBackgroundUndo - RuntimeException on undoing: " + e);
        AnkiDroidApp.saveExceptionReportFile(e, "doInBackgroundUndo");
        return new TaskData(false);
    }
    return new TaskData(true);
}
Also used : Sched(com.ichi2.libanki.Sched) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card)

Aggregations

Card (com.ichi2.libanki.Card)7 Sched (com.ichi2.libanki.Sched)5 JSONException (org.json.JSONException)5 Collection (com.ichi2.libanki.Collection)4 Note (com.ichi2.libanki.Note)4 Resources (android.content.res.Resources)3 SpannableString (android.text.SpannableString)3 SpannedString (android.text.SpannedString)3 AnkiDb (com.ichi2.anki.AnkiDb)3 DeckTask (com.ichi2.async.DeckTask)3 Matcher (java.util.regex.Matcher)3 JSONObject (org.json.JSONObject)3 DialogInterface (android.content.DialogInterface)2 SharedPreferences (android.content.SharedPreferences)2 SQLException (android.database.SQLException)2 StyleSpan (android.text.style.StyleSpan)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 Pair (com.ichi2.anki.Pair)2 TaskData (com.ichi2.async.DeckTask.TaskData)2 StyledDialog (com.ichi2.themes.StyledDialog)2