use of com.ichi2.libanki.importer.Anki2Importer 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