Search in sources :

Example 6 with Sched

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

the class DeckTask method doInBackgroundMarkCard.

private TaskData doInBackgroundMarkCard(TaskData... params) {
    Card card = params[0].getCard();
    Sched sched = params[0].getSched();
    try {
        AnkiDb ankiDB = sched.getCol().getDb();
        ankiDB.getDatabase().beginTransaction();
        try {
            if (card != null) {
                Note note = card.note();
                sched.getCol().markUndo(Collection.UNDO_MARK_NOTE, new Object[] { note.getId(), note.stringTags(), card.getId() });
                if (note.hasTag("marked")) {
                    note.delTag("marked");
                } else {
                    note.addTag("marked");
                }
                note.flush();
            }
            publishProgress(new TaskData(card));
            ankiDB.getDatabase().setTransactionSuccessful();
        } finally {
            ankiDB.getDatabase().endTransaction();
        }
    } catch (RuntimeException e) {
        Log.e(AnkiDroidApp.TAG, "doInBackgroundMarkCard - RuntimeException on marking card: " + e);
        AnkiDroidApp.saveExceptionReportFile(e, "doInBackgroundMarkCard");
        return new TaskData(false);
    }
    return new TaskData(true);
}
Also used : AnkiDb(com.ichi2.anki.AnkiDb) Sched(com.ichi2.libanki.Sched) Note(com.ichi2.libanki.Note) Card(com.ichi2.libanki.Card)

Aggregations

Sched (com.ichi2.libanki.Sched)6 Card (com.ichi2.libanki.Card)5 Collection (com.ichi2.libanki.Collection)3 Note (com.ichi2.libanki.Note)3 AnkiDb (com.ichi2.anki.AnkiDb)2 JSONObject (org.json.JSONObject)1