use of com.ichi2.async.DeckTask.TaskData in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundConfReset.
private TaskData doInBackgroundConfReset(TaskData... params) {
Log.i(AnkiDroidApp.TAG, "doInBackgroundConfReset");
Object[] data = params[0].getObjArray();
Collection col = (Collection) data[0];
JSONObject conf = (JSONObject) data[1];
col.getDecks().restoreToDefault(conf);
return new TaskData(true);
}
use of com.ichi2.async.DeckTask.TaskData 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.async.DeckTask.TaskData 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);
}
use of com.ichi2.async.DeckTask.TaskData in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundOpenCollection.
private TaskData doInBackgroundOpenCollection(TaskData... params) {
Log.i(AnkiDroidApp.TAG, "doInBackgroundOpenCollection");
long time = Utils.intNow(1000);
Resources res = AnkiDroidApp.getInstance().getBaseContext().getResources();
String collectionFile = params[0].getString();
SharedPreferences prefs = AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext());
// see, if a collection is still opened
Collection oldCol = AnkiDroidApp.getCol();
Collection col = null;
publishProgress(new TaskData(res.getString(R.string.open_collection)));
if (!(AnkiDroidApp.colIsOpen() && oldCol.getPath().equals(collectionFile))) {
// android's delete db bug
if (BackupManager.safetyBackupNeeded(collectionFile)) {
publishProgress(new TaskData(res.getString(R.string.backup_collection)));
BackupManager.performBackup(collectionFile);
}
publishProgress(new TaskData(res.getString(R.string.open_collection)));
// load collection
try {
col = AnkiDroidApp.openCollection(collectionFile);
} catch (RuntimeException e) {
BackupManager.restoreCollectionIfMissing(collectionFile);
Log.e(AnkiDroidApp.TAG, "doInBackgroundOpenCollection - RuntimeException on opening collection: " + e);
AnkiDroidApp.saveExceptionReportFile(e, "doInBackgroundOpenCollection");
return new TaskData(false);
}
// create tutorial deck if needed
if (prefs.contains("createTutorial") && prefs.getBoolean("createTutorial", false)) {
prefs.edit().remove("createTutorial").commit();
publishProgress(new TaskData(res.getString(R.string.tutorial_load)));
doInBackgroundLoadTutorial(new TaskData(col));
}
} else {
Log.i(AnkiDroidApp.TAG, "doInBackgroundOpenCollection: collection still open - reusing it");
col = oldCol;
}
Object[] counts = null;
DeckTask.TaskData result = doInBackgroundLoadDeckCounts(new TaskData(col));
if (result != null) {
counts = result.getObjArray();
}
if (prefs.getBoolean("splashScreen", false)) {
long millies = Utils.intNow(1000) - time;
if (millies < 1000) {
try {
Thread.sleep(1200 - millies);
} catch (InterruptedException e) {
}
}
}
return new TaskData(col, counts);
}
use of com.ichi2.async.DeckTask.TaskData in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundDeleteDeck.
private TaskData doInBackgroundDeleteDeck(TaskData... params) {
Log.i(AnkiDroidApp.TAG, "doInBackgroundDeleteDeck");
Collection col = params[0].getCollection();
long did = params[0].getLong();
col.getDecks().rem(did, true);
return doInBackgroundLoadDeckCounts(new TaskData(col));
}
Aggregations