use of com.ichi2.async.DeckTask.TaskData in project Anki-Android by Ramblurr.
the class DeckPicker method handleDbError.
// private void resetDeckLanguages(String deckPath) {
// if (MetaDB.resetDeckLanguages(this, deckPath)) {
// Themes.showThemedToast(this, getResources().getString(R.string.contextmenu_deckpicker_reset_reset_message),
// true);
// }
// }
//
//
// public void openSharedDeckPicker() {
// // deckLoaded = false;
// startActivityForResult(new Intent(this, SharedDeckPicker.class), DOWNLOAD_SHARED_DECK);
// if (UIUtils.getApiLevel() > 4) {
// ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.RIGHT);
// }
// }
public void handleDbError() {
AnkiDatabaseManager.closeDatabase(AnkiDroidApp.getCollectionPath());
DeckTask.launchDeckTask(DeckTask.TASK_TYPE_RESTORE_IF_MISSING, new DeckTask.TaskListener() {
@Override
public void onPreExecute() {
mProgressDialog = StyledProgressDialog.show(DeckPicker.this, "", getResources().getString(R.string.backup_restore_if_missing), true);
}
@Override
public void onPostExecute(TaskData result) {
if (mProgressDialog.isShowing()) {
try {
mProgressDialog.dismiss();
} catch (Exception e) {
Log.e(AnkiDroidApp.TAG, "onPostExecute - Dialog dismiss Exception = " + e.getMessage());
}
}
showDialog(DIALOG_DB_ERROR);
}
@Override
public void onProgressUpdate(TaskData... values) {
}
}, new DeckTask.TaskData(AnkiDroidApp.getCollectionPath()));
}
use of com.ichi2.async.DeckTask.TaskData in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundAddNote.
private TaskData doInBackgroundAddNote(TaskData[] params) {
Log.i(AnkiDroidApp.TAG, "doInBackgroundAddNote");
Note note = params[0].getNote();
Collection col = note.getCol();
try {
AnkiDb ankiDB = col.getDb();
ankiDB.getDatabase().beginTransaction();
try {
publishProgress(new TaskData(col.addNote(note)));
ankiDB.getDatabase().setTransactionSuccessful();
} finally {
ankiDB.getDatabase().endTransaction();
}
} catch (RuntimeException e) {
Log.e(AnkiDroidApp.TAG, "doInBackgroundAddNote - RuntimeException on adding fact: " + e);
AnkiDroidApp.saveExceptionReportFile(e, "doInBackgroundAddNote");
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 doInBackgroundConfSetSubdecks.
private TaskData doInBackgroundConfSetSubdecks(TaskData... params) {
Log.i(AnkiDroidApp.TAG, "doInBackgroundConfSetSubdecks");
Object[] data = params[0].getObjArray();
Collection col = (Collection) data[0];
JSONObject deck = (JSONObject) data[1];
JSONObject conf = (JSONObject) data[2];
try {
TreeMap<String, Long> children = col.getDecks().children(deck.getLong("id"));
for (Map.Entry<String, Long> entry : children.entrySet()) {
JSONObject child = col.getDecks().get(entry.getValue());
if (child.getInt("dyn") == 1) {
continue;
}
TaskData newParams = new TaskData(new Object[] { col, child, conf });
boolean changed = doInBackgroundConfChange(newParams).getBoolean();
if (!changed) {
return new TaskData(false);
}
}
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 doInBackgroundLoadStatistics.
private TaskData doInBackgroundLoadStatistics(TaskData... params) {
Log.i(AnkiDroidApp.TAG, "doInBackgroundLoadStatistics");
Collection col = params[0].getCollection();
int type = params[0].getInt();
boolean wholeCollection = params[0].getBoolean();
Stats stats = new Stats(col, wholeCollection);
switch(type) {
default:
case Stats.TYPE_FORECAST:
return new TaskData(stats.calculateDue(AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getInt("statsType", Stats.TYPE_MONTH)));
case Stats.TYPE_REVIEW_COUNT:
return new TaskData(stats.calculateDone(AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getInt("statsType", Stats.TYPE_MONTH), true));
case Stats.TYPE_REVIEW_TIME:
return new TaskData(stats.calculateDone(AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getInt("statsType", Stats.TYPE_MONTH), false));
}
}
use of com.ichi2.async.DeckTask.TaskData in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundEmptyCram.
private TaskData doInBackgroundEmptyCram(TaskData... params) {
Log.i(AnkiDroidApp.TAG, "doInBackgroundEmptyCram");
Collection col = params[0].getCollection();
boolean fragmented = params[0].getBoolean();
long did = params[0].getLong();
col.getSched().emptyDyn(did);
return doInBackgroundUpdateValuesFromDeck(new DeckTask.TaskData(col, new Object[] { true, fragmented }));
}
Aggregations