Search in sources :

Example 21 with TaskData

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()));
}
Also used : DeckTask(com.ichi2.async.DeckTask) JSONException(org.json.JSONException) NotFoundException(android.content.res.Resources.NotFoundException) SQLException(android.database.SQLException) TaskData(com.ichi2.async.DeckTask.TaskData) TaskData(com.ichi2.async.DeckTask.TaskData)

Example 22 with TaskData

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);
}
Also used : AnkiDb(com.ichi2.anki.AnkiDb) Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection)

Example 23 with TaskData

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);
    }
}
Also used : JSONObject(org.json.JSONObject) Collection(com.ichi2.libanki.Collection) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 24 with TaskData

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));
    }
}
Also used : Stats(com.ichi2.libanki.Stats) Collection(com.ichi2.libanki.Collection)

Example 25 with TaskData

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 }));
}
Also used : Collection(com.ichi2.libanki.Collection) JSONObject(org.json.JSONObject)

Aggregations

Collection (com.ichi2.libanki.Collection)24 JSONObject (org.json.JSONObject)13 JSONException (org.json.JSONException)8 TaskData (com.ichi2.async.DeckTask.TaskData)7 Resources (android.content.res.Resources)6 Sched (com.ichi2.libanki.Sched)6 AnkiDb (com.ichi2.anki.AnkiDb)5 Card (com.ichi2.libanki.Card)5 Note (com.ichi2.libanki.Note)5 File (java.io.File)5 DeckTask (com.ichi2.async.DeckTask)4 Intent (android.content.Intent)3 SharedPreferences (android.content.SharedPreferences)3 NotFoundException (android.content.res.Resources.NotFoundException)3 SQLException (android.database.SQLException)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 ZipFile (java.util.zip.ZipFile)3 DialogInterface (android.content.DialogInterface)2 OnCancelListener (android.content.DialogInterface.OnCancelListener)2