use of com.ichi2.async.TaskData in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundRepairDeck.
private TaskData doInBackgroundRepairDeck(TaskData... params) {
// Log.i(AnkiDroidApp.TAG, "doInBackgroundRepairDeck");
String deckPath = params[0].getString();
Collection col = params[0].getCollection();
if (col != null) {
col.close(false);
}
return new TaskData(BackupManager.repairDeck(deckPath));
}
use of com.ichi2.async.TaskData in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundRebuildCram.
private TaskData doInBackgroundRebuildCram(TaskData... params) {
// Log.i(AnkiDroidApp.TAG, "doInBackgroundRebuildCram");
Collection col = params[0].getCollection();
boolean fragmented = params[0].getBoolean();
long did = params[0].getLong();
col.getSched().rebuildDyn(did);
return doInBackgroundUpdateValuesFromDeck(new DeckTask.TaskData(col, new Object[] { true, fragmented }));
}
use of com.ichi2.async.TaskData in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundRestoreDeck.
private TaskData doInBackgroundRestoreDeck(TaskData... params) {
// Log.i(AnkiDroidApp.TAG, "doInBackgroundRestoreDeck");
Object[] data = params[0].getObjArray();
Collection col = (Collection) data[0];
if (col != null) {
col.close(false);
}
return new TaskData(BackupManager.restoreBackup((String) data[1], (String) data[2]));
}
use of com.ichi2.async.TaskData in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundDismissNote.
private TaskData doInBackgroundDismissNote(TaskData... params) {
Sched sched = params[0].getSched();
Collection col = sched.getCol();
Card card = params[0].getCard();
Note note = card.note();
int type = params[0].getInt();
try {
col.getDb().getDatabase().beginTransaction();
try {
switch(type) {
case 4:
// collect undo information
col.markUndo(Collection.UNDO_BURY_CARD, new Object[] { col.getDirty(), note.cards(), card.getId() });
// then bury
sched.buryCards(new long[] { card.getId() });
sHadCardQueue = true;
break;
case 0:
// collect undo information
col.markUndo(Collection.UNDO_BURY_NOTE, new Object[] { col.getDirty(), note.cards(), card.getId() });
// then bury
sched.buryNote(note.getId());
sHadCardQueue = true;
break;
case 1:
// collect undo information
col.markUndo(Collection.UNDO_SUSPEND_CARD, new Object[] { card });
// suspend card
if (card.getQueue() == -1) {
sched.unsuspendCards(new long[] { card.getId() });
} else {
sched.suspendCards(new long[] { card.getId() });
}
sHadCardQueue = true;
break;
case 2:
// collect undo information
ArrayList<Card> cards = note.cards();
long[] cids = new long[cards.size()];
for (int i = 0; i < cards.size(); i++) {
cids[i] = cards.get(i).getId();
}
col.markUndo(Collection.UNDO_SUSPEND_NOTE, new Object[] { cards, card.getId() });
// suspend note
sched.suspendCards(cids);
sHadCardQueue = true;
break;
case 3:
// collect undo information
ArrayList<Card> allCs = note.cards();
long[] cardIds = new long[allCs.size()];
for (int i = 0; i < allCs.size(); i++) {
cardIds[i] = allCs.get(i).getId();
}
col.markUndo(Collection.UNDO_DELETE_NOTE, new Object[] { note, allCs, card.getId() });
// delete note
col.remNotes(new long[] { note.getId() });
sHadCardQueue = true;
break;
}
publishProgress(new TaskData(getCard(col.getSched()), 0));
col.getDb().getDatabase().setTransactionSuccessful();
} finally {
col.getDb().getDatabase().endTransaction();
}
} catch (RuntimeException e) {
Log.e(AnkiDroidApp.TAG, "doInBackgroundSuspendCard - RuntimeException on suspending card: " + e);
AnkiDroidApp.saveExceptionReportFile(e, "doInBackgroundSuspendCard");
return new TaskData(false);
}
return new TaskData(true);
}
use of com.ichi2.async.TaskData in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundImportAdd.
private TaskData doInBackgroundImportAdd(TaskData... params) {
// Log.i(AnkiDroidApp.TAG, "doInBackgroundImportAdd");
Resources res = AnkiDroidApp.getInstance().getBaseContext().getResources();
Collection col = params[0].getCollection();
String path = params[0].getString();
boolean sharedDeckImport = params[0].getBoolean();
ProgressCallback pc = null;
// don't report progress on shared deck import (or maybe should we?)
if (!sharedDeckImport) {
pc = new ProgressCallback(this, res);
}
int addedCount = -1;
try {
Anki2Importer imp = new Anki2Importer(col, path, pc);
AnkiDb ankiDB = col.getDb();
ankiDB.getDatabase().beginTransaction();
try {
addedCount = imp.run();
ankiDB.getDatabase().setTransactionSuccessful();
} finally {
ankiDB.getDatabase().endTransaction();
if (sharedDeckImport) {
File tmpFile = new File(path);
tmpFile.delete();
}
}
if (addedCount >= 0) {
ankiDB.execute("VACUUM");
ankiDB.execute("ANALYZE");
}
publishProgress(new TaskData(res.getString(R.string.import_update_counts)));
// Update the counts
DeckTask.TaskData result = doInBackgroundLoadDeckCounts(new TaskData(col));
if (result == null) {
return null;
}
return new TaskData(addedCount, result.getObjArray(), true);
} catch (RuntimeException e) {
Log.e(AnkiDroidApp.TAG, "doInBackgroundImportAdd - RuntimeException on importing cards: ", e);
AnkiDroidApp.saveExceptionReportFile(e, "doInBackgroundImportAdd");
return new TaskData(false);
} catch (IOException e) {
Log.e(AnkiDroidApp.TAG, "doInBackgroundImportAdd - IOException on importing cards: ", e);
AnkiDroidApp.saveExceptionReportFile(e, "doInBackgroundImportAdd");
return new TaskData(false);
}
}
Aggregations