Search in sources :

Example 41 with Collection

use of com.ichi2.libanki.Collection 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 42 with Collection

use of com.ichi2.libanki.Collection 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)

Example 43 with Collection

use of com.ichi2.libanki.Collection in project Anki-Android by Ramblurr.

the class DeckTask method doInBackgroundLoadDeckCounts.

private TaskData doInBackgroundLoadDeckCounts(TaskData... params) {
    Log.i(AnkiDroidApp.TAG, "doInBackgroundLoadDeckCounts");
    Collection col = params[0].getCollection();
    if (col == null) {
        return null;
    }
    try {
        return new TaskData(col.getSched().deckCounts());
    } catch (RuntimeException e) {
        Log.e(AnkiDroidApp.TAG, "doInBackgroundLoadDeckCounts - error: " + e);
        return null;
    }
}
Also used : Collection(com.ichi2.libanki.Collection)

Example 44 with Collection

use of com.ichi2.libanki.Collection in project Anki-Android by Ramblurr.

the class DeckTask method doInBackgroundUndo.

private TaskData doInBackgroundUndo(TaskData... params) {
    Sched sched = params[0].getSched();
    Collection col = sched.getCol();
    try {
        col.getDb().getDatabase().beginTransaction();
        Card newCard;
        try {
            long cid = col.undo();
            if (cid != 0) {
                // a review was undone,
                newCard = col.getCard(cid);
                col.reset();
                col.getSched().decrementCounts(newCard);
                sHadCardQueue = true;
            } else {
                // TODO: do not fetch new card if a non review operation has
                // been undone
                col.reset();
                newCard = getCard(sched);
            }
            // TODO: handle leech undoing properly
            publishProgress(new TaskData(newCard, 0));
            col.getDb().getDatabase().setTransactionSuccessful();
        } finally {
            col.getDb().getDatabase().endTransaction();
        }
    } catch (RuntimeException e) {
        Log.e(AnkiDroidApp.TAG, "doInBackgroundUndo - RuntimeException on undoing: " + e);
        AnkiDroidApp.saveExceptionReportFile(e, "doInBackgroundUndo");
        return new TaskData(false);
    }
    return new TaskData(true);
}
Also used : Sched(com.ichi2.libanki.Sched) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card)

Example 45 with Collection

use of com.ichi2.libanki.Collection in project Anki-Android by Ramblurr.

the class DeckTask method doInBackgroundConfRemove.

private TaskData doInBackgroundConfRemove(TaskData... params) {
    Log.i(AnkiDroidApp.TAG, "doInBackgroundConfRemove");
    Object[] data = params[0].getObjArray();
    Collection col = (Collection) data[0];
    JSONObject conf = (JSONObject) data[1];
    try {
        // When a conf is deleted, all decks using it revert to the default conf.
        // Cards must be reordered according to the default conf.
        int order = conf.getJSONObject("new").getInt("order");
        int defaultOrder = col.getDecks().getConf(1).getJSONObject("new").getInt("order");
        if (order != defaultOrder) {
            conf.getJSONObject("new").put("order", defaultOrder);
            col.getSched().resortConf(conf);
        }
        col.getDecks().remConf(conf.getLong("id"));
        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)

Aggregations

Collection (com.ichi2.libanki.Collection)40 JSONObject (org.json.JSONObject)20 File (java.io.File)13 JSONException (org.json.JSONException)12 IOException (java.io.IOException)11 Resources (android.content.res.Resources)10 DialogInterface (android.content.DialogInterface)6 DeckTask (com.ichi2.async.DeckTask)6 TaskData (com.ichi2.async.DeckTask.TaskData)6 StyledDialog (com.ichi2.themes.StyledDialog)6 AnkiDb (com.ichi2.anki.AnkiDb)5 FileInputStream (java.io.FileInputStream)5 ArrayList (java.util.ArrayList)5 Intent (android.content.Intent)4 Note (com.ichi2.libanki.Note)4 FileNotFoundException (java.io.FileNotFoundException)4 FileOutputStream (java.io.FileOutputStream)4 InputStream (java.io.InputStream)4 JSONArray (org.json.JSONArray)4 OnCancelListener (android.content.DialogInterface.OnCancelListener)3