use of com.ichi2.libanki.Collection in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundLoadStatistics.
private TaskData doInBackgroundLoadStatistics(TaskData... params) {
Log.i(AnkiDroidApp.TAG, "doInBackgroundLoadStatistics");
Collection col = params[0].getCollection();
int type = params[0].getInt();
boolean wholeCollection = params[0].getBoolean();
Stats stats = new Stats(col, wholeCollection);
switch(type) {
default:
case Stats.TYPE_FORECAST:
return new TaskData(stats.calculateDue(AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getInt("statsType", Stats.TYPE_MONTH)));
case Stats.TYPE_REVIEW_COUNT:
return new TaskData(stats.calculateDone(AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getInt("statsType", Stats.TYPE_MONTH), true));
case Stats.TYPE_REVIEW_TIME:
return new TaskData(stats.calculateDone(AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getInt("statsType", Stats.TYPE_MONTH), false));
}
}
use of com.ichi2.libanki.Collection in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundEmptyCram.
private TaskData doInBackgroundEmptyCram(TaskData... params) {
Log.i(AnkiDroidApp.TAG, "doInBackgroundEmptyCram");
Collection col = params[0].getCollection();
boolean fragmented = params[0].getBoolean();
long did = params[0].getLong();
col.getSched().emptyDyn(did);
return doInBackgroundUpdateValuesFromDeck(new DeckTask.TaskData(col, new Object[] { true, fragmented }));
}
use of com.ichi2.libanki.Collection in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundLoadDeckCounts.
private TaskData doInBackgroundLoadDeckCounts(TaskData... params) {
Log.i(AnkiDroidApp.TAG, "doInBackgroundLoadDeckCounts");
Collection col = params[0].getCollection();
if (col == null) {
return null;
}
try {
return new TaskData(col.getSched().deckCounts());
} catch (RuntimeException e) {
Log.e(AnkiDroidApp.TAG, "doInBackgroundLoadDeckCounts - error: " + e);
return null;
}
}
use of com.ichi2.libanki.Collection 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.Collection in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundConfRemove.
private TaskData doInBackgroundConfRemove(TaskData... params) {
Log.i(AnkiDroidApp.TAG, "doInBackgroundConfRemove");
Object[] data = params[0].getObjArray();
Collection col = (Collection) data[0];
JSONObject conf = (JSONObject) data[1];
try {
// When a conf is deleted, all decks using it revert to the default conf.
// Cards must be reordered according to the default conf.
int order = conf.getJSONObject("new").getInt("order");
int defaultOrder = col.getDecks().getConf(1).getJSONObject("new").getInt("order");
if (order != defaultOrder) {
conf.getJSONObject("new").put("order", defaultOrder);
col.getSched().resortConf(conf);
}
col.getDecks().remConf(conf.getLong("id"));
return new TaskData(true);
} catch (JSONException e) {
return new TaskData(false);
}
}
Aggregations