use of com.ichi2.async.DeckTask.TaskData in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundConfChange.
private TaskData doInBackgroundConfChange(TaskData... params) {
Log.i(AnkiDroidApp.TAG, "doInBackgroundConfChange");
Object[] data = params[0].getObjArray();
Collection col = (Collection) data[0];
JSONObject deck = (JSONObject) data[1];
JSONObject conf = (JSONObject) data[2];
try {
long newConfId = conf.getLong("id");
// If new config has a different sorting order, reorder the cards
int oldOrder = col.getDecks().getConf(deck.getLong("conf")).getJSONObject("new").getInt("order");
int newOrder = col.getDecks().getConf(newConfId).getJSONObject("new").getInt("order");
if (oldOrder != newOrder) {
switch(newOrder) {
case 0:
col.getSched().randomizeCards(deck.getLong("id"));
break;
case 1:
col.getSched().orderCards(deck.getLong("id"));
break;
}
}
col.getDecks().setConf(deck, newConfId);
return new TaskData(true);
} catch (JSONException e) {
return new TaskData(false);
}
}
use of com.ichi2.async.DeckTask.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);
}
}
use of com.ichi2.async.DeckTask.TaskData in project Anki-Android by Ramblurr.
the class MultimediaCardEditorActivity method save.
private void save() {
NoteService.saveMedia((MultimediaEditableNote) mNote);
NoteService.updateJsonNoteFromMultimediaNote(mNote, mEditorNote);
TaskListener listener = new TaskListener() {
@Override
public void onProgressUpdate(TaskData... values) {
// TODO Auto-generated method stub
}
@Override
public void onPreExecute() {
// TODO Auto-generated method stub
}
@Override
public void onPostExecute(TaskData result) {
// TODO Auto-generated method stub
}
};
if (mAddNote) {
DeckTask.launchDeckTask(DeckTask.TASK_TYPE_ADD_FACT, listener, new DeckTask.TaskData(mEditorNote));
} else {
DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UPDATE_FACT, listener, new DeckTask.TaskData(mCol.getSched(), mCard, false));
}
setResult(Activity.RESULT_OK);
finish();
animateRight();
}
use of com.ichi2.async.DeckTask.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.DeckTask.TaskData in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundReorder.
private TaskData doInBackgroundReorder(TaskData... params) {
Log.i(AnkiDroidApp.TAG, "doInBackgroundReorder");
Object[] data = params[0].getObjArray();
Collection col = (Collection) data[0];
JSONObject conf = (JSONObject) data[1];
col.getSched().resortConf(conf);
return new TaskData(true);
}
Aggregations