use of com.ichi2.async.TaskData in project AnkiChinaAndroid by ankichinateam.
the class AnkiActivity method importReplace.
@Override
public void importReplace(String importPath) {
try {
AnkiDroidApp.getSharedPrefs(this).edit().remove(Consts.KEY_SYNC_CHINA_SESSION).apply();
CollectionTask.launchCollectionTask(IMPORT_REPLACE, importReplaceListener(), new TaskData(importPath));
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.ichi2.async.TaskData in project AnkiChinaAndroid by ankichinateam.
the class CollectionTask method doInBackgroundAnswerCard.
private TaskData doInBackgroundAnswerCard(TaskData param) {
Collection col = getCol();
AbstractSched sched = col.getSched();
Card oldCard = param.getCard();
@Consts.BUTTON_TYPE int ease = param.getInt();
Card newCard = null;
Timber.i(oldCard != null ? "Answering card" : "Obtaining card");
try {
DB db = col.getDb();
db.getDatabase().beginTransaction();
try {
if (oldCard != null) {
Timber.i("Answering card %d", oldCard.getId());
sched.answerCard(oldCard, ease);
}
newCard = sched.getCard();
if (newCard != null) {
// render cards before locking database
newCard._getQA(true);
}
publishProgress(new TaskData(newCard));
db.getDatabase().setTransactionSuccessful();
} finally {
db.getDatabase().endTransaction();
}
} catch (RuntimeException e) {
Timber.e(e, "doInBackgroundAnswerCard - RuntimeException on answering card");
AnkiDroidApp.sendExceptionReport(e, "doInBackgroundAnswerCard");
return new TaskData(false);
}
return new TaskData(true);
}
use of com.ichi2.async.TaskData in project AnkiChinaAndroid by ankichinateam.
the class CollectionTask method doInBackgroundUpdateNote.
private TaskData doInBackgroundUpdateNote(TaskData param) {
Timber.d("doInBackgroundUpdateNote");
// Save the note
Collection col = getCol();
AbstractSched sched = col.getSched();
Card editCard = param.getCard();
Note editNote = editCard.note();
boolean fromReviewer = param.getBoolean();
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.q(true);
} else {
newCard = sched.getCard();
}
publishProgress(new TaskData(newCard));
} else {
publishProgress(new TaskData(editCard, editNote.stringTags()));
}
col.getDb().getDatabase().setTransactionSuccessful();
} finally {
col.getDb().getDatabase().endTransaction();
}
} catch (RuntimeException e) {
Timber.e(e, "doInBackgroundUpdateNote - RuntimeException on updating note");
AnkiDroidApp.sendExceptionReport(e, "doInBackgroundUpdateNote");
return new TaskData(false);
}
return new TaskData(true);
}
use of com.ichi2.async.TaskData in project AnkiChinaAndroid by ankichinateam.
the class CollectionTask method doInBackgroundCheckDatabase.
private TaskData doInBackgroundCheckDatabase() {
Timber.d("doInBackgroundCheckDatabase");
Collection col = getCol();
// Don't proceed if collection closed
if (col == null) {
Timber.e("doInBackgroundCheckDatabase :: supplied collection was null");
return new TaskData(false);
}
Collection.CheckDatabaseResult result = col.fixIntegrity(new ProgressCallback(this, AnkiDroidApp.getAppResources()));
if (result.getFailed()) {
// we can fail due to a locked database, which requires knowledge of the failure.
return new TaskData(false, new Object[] { result });
} else {
// Close the collection and we restart the app to reload
CollectionHelper.getInstance().closeCollection(true, "Check Database Completed");
return new TaskData(true, new Object[] { result });
}
}
use of com.ichi2.async.TaskData in project AnkiChinaAndroid by ankichinateam.
the class CollectionTask method doInBackgroundEmptyCram.
private TaskData doInBackgroundEmptyCram() {
Timber.d("doInBackgroundEmptyCram");
Collection col = getCol();
col.getSched().emptyDyn(col.getDecks().selected());
return doInBackgroundUpdateValuesFromDeck(new TaskData(new Object[] { true }));
}
Aggregations