use of com.ichi2.libanki.sched.Sched in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundUpdateValuesFromDeck.
private TaskData doInBackgroundUpdateValuesFromDeck(TaskData... params) {
// Log.i(AnkiDroidApp.TAG, "doInBackgroundUpdateValuesFromDeck");
try {
Sched sched = params[0].getCollection().getSched();
Object[] obj = params[0].getObjArray();
boolean reset = (Boolean) obj[0];
if (reset) {
sched.reset();
}
int[] counts = sched.counts();
int totalNewCount = sched.totalNewForCurrentDeck();
int totalCount = sched.cardCount();
double progressMature = ((double) sched.matureCount()) / ((double) totalCount);
double progressAll = 1 - (((double) (totalNewCount + counts[1])) / ((double) totalCount));
double[][] serieslist = null;
// only calculate stats if necessary
if ((Boolean) obj[1]) {
serieslist = Stats.getSmallDueStats(sched.getCol());
}
return new TaskData(new Object[] { counts[0], counts[1], counts[2], totalNewCount, totalCount, progressMature, progressAll, sched.eta(counts), serieslist });
} catch (RuntimeException e) {
Log.e(AnkiDroidApp.TAG, "doInBackgroundUpdateValuesFromDeck - an error occurred: " + e);
return null;
}
}
use of com.ichi2.libanki.sched.Sched in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundUpdateNote.
private TaskData doInBackgroundUpdateNote(TaskData[] params) {
// Log.i(AnkiDroidApp.TAG, "doInBackgroundUpdateNote");
// Save the note
Sched sched = params[0].getSched();
Collection col = sched.getCol();
Card editCard = params[0].getCard();
Note editNote = editCard.note();
boolean fromReviewer = params[0].getBoolean();
// mark undo
col.markUndo(Collection.UNDO_EDIT_NOTE, new Object[] { col.getNote(editNote.getId()), editCard.getId(), fromReviewer });
try {
col.getDb().getDatabase().beginTransaction();
try {
// TODO: undo integration
editNote.flush();
// flush card too, in case, did has been changed
editCard.flush();
if (fromReviewer) {
Card newCard;
if (col.getDecks().active().contains(editCard.getDid())) {
newCard = editCard;
newCard.load();
// reload qa-cache
newCard.getQuestion(true);
} else {
newCard = getCard(sched);
}
publishProgress(new TaskData(newCard));
} else {
publishProgress(new TaskData(editCard, editNote.stringTags()));
}
col.getDb().getDatabase().setTransactionSuccessful();
} finally {
col.getDb().getDatabase().endTransaction();
}
} catch (RuntimeException e) {
Log.e(AnkiDroidApp.TAG, "doInBackgroundUpdateNote - RuntimeException on updating fact: " + e);
AnkiDroidApp.saveExceptionReportFile(e, "doInBackgroundUpdateNote");
return new TaskData(false);
}
return new TaskData(true);
}
use of com.ichi2.libanki.sched.Sched in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundAnswerCard.
private TaskData doInBackgroundAnswerCard(TaskData... params) {
Sched sched = params[0].getSched();
Card oldCard = params[0].getCard();
int ease = params[0].getInt();
Card newCard = null;
// TODO: proper leech handling
int oldCardLeech = 0;
// 0: normal; 1: leech; 2: leech & suspended
try {
AnkiDb ankiDB = sched.getCol().getDb();
ankiDB.getDatabase().beginTransaction();
try {
if (oldCard != null) {
sched.answerCard(oldCard, ease);
}
if (newCard == null) {
newCard = getCard(sched);
}
if (newCard != null) {
// render cards before locking database
newCard._getQA(true);
}
publishProgress(new TaskData(newCard, oldCardLeech));
ankiDB.getDatabase().setTransactionSuccessful();
} finally {
ankiDB.getDatabase().endTransaction();
}
} catch (RuntimeException e) {
Log.e(AnkiDroidApp.TAG, "doInBackgroundAnswerCard - RuntimeException on answering card: " + e);
AnkiDroidApp.saveExceptionReportFile(e, "doInBackgroundAnswerCard");
return new TaskData(false);
}
return new TaskData(true);
}
use of com.ichi2.libanki.sched.Sched 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);
}
use of com.ichi2.libanki.sched.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);
}
Aggregations