Search in sources :

Example 11 with TaskData

use of com.ichi2.async.DeckTask.TaskData in project Anki-Android by Ramblurr.

the class DeckTask method doInBackgroundSearchCards.

private TaskData doInBackgroundSearchCards(TaskData... params) {
    Log.i(AnkiDroidApp.TAG, "doInBackgroundSearchCards");
    Collection col = (Collection) params[0].getObjArray()[0];
    HashMap<String, String> deckNames = (HashMap<String, String>) params[0].getObjArray()[1];
    String query = (String) params[0].getObjArray()[2];
    String order = (String) params[0].getObjArray()[3];
    TaskData result = new TaskData(col.findCardsForCardBrowser(query, order, deckNames));
    if (DeckTask.taskIsCancelled()) {
        return null;
    } else {
        publishProgress(result);
    }
    return new TaskData(col.cardCount(col.getDecks().allIds()));
}
Also used : HashMap(java.util.HashMap) Collection(com.ichi2.libanki.Collection)

Example 12 with TaskData

use of com.ichi2.async.DeckTask.TaskData in project Anki-Android by Ramblurr.

the class DeckTask method doInBackgroundUpdateValuesFromDeck.

private TaskData doInBackgroundUpdateValuesFromDeck(TaskData... params) {
    Log.i(AnkiDroidApp.TAG, "doInBackgroundUpdateValuesFromDeck");
    try {
        Sched sched = params[0].getCollection().getSched();
        Object[] obj = params[0].getObjArray();
        boolean reset = (Boolean) obj[0];
        if (reset) {
            sched.reset();
        }
        int[] counts = sched.counts();
        int totalNewCount = sched.totalNewForCurrentDeck();
        int totalCount = sched.cardCount();
        double progressMature = ((double) sched.matureCount()) / ((double) totalCount);
        double progressAll = 1 - (((double) (totalNewCount + counts[1])) / ((double) totalCount));
        double[][] serieslist = null;
        // only calculate stats if necessary
        if ((Boolean) obj[1]) {
            serieslist = Stats.getSmallDueStats(sched.getCol());
        }
        return new TaskData(new Object[] { counts[0], counts[1], counts[2], totalNewCount, totalCount, progressMature, progressAll, sched.eta(counts), serieslist });
    } catch (RuntimeException e) {
        Log.e(AnkiDroidApp.TAG, "doInBackgroundUpdateValuesFromDeck - an error occurred: " + e);
        return null;
    }
}
Also used : Sched(com.ichi2.libanki.Sched) JSONObject(org.json.JSONObject)

Example 13 with TaskData

use of com.ichi2.async.DeckTask.TaskData in project Anki-Android by Ramblurr.

the class DeckTask method doInBackgroundRestoreDeck.

private TaskData doInBackgroundRestoreDeck(TaskData... params) {
    Log.i(AnkiDroidApp.TAG, "doInBackgroundRestoreDeck");
    Object[] data = params[0].getObjArray();
    Collection col = (Collection) data[0];
    if (col != null) {
        col.close(false);
    }
    return new TaskData(BackupManager.restoreBackup((String) data[1], (String) data[2]));
}
Also used : Collection(com.ichi2.libanki.Collection) JSONObject(org.json.JSONObject)

Example 14 with TaskData

use of com.ichi2.async.DeckTask.TaskData in project Anki-Android by Ramblurr.

the class DeckTask method doInBackgroundCloseCollection.

private TaskData doInBackgroundCloseCollection(TaskData... params) {
    Log.i(AnkiDroidApp.TAG, "doInBackgroundCloseCollection");
    Collection col = params[0].getCollection();
    if (col != null) {
        try {
            WidgetStatus.waitToFinish();
            String path = col.getPath();
            AnkiDroidApp.closeCollection(true);
            BackupManager.performBackup(path);
        } catch (RuntimeException e) {
            Log.i(AnkiDroidApp.TAG, "doInBackgroundCloseCollection: error occurred - collection not properly closed");
        }
    }
    return null;
}
Also used : Collection(com.ichi2.libanki.Collection)

Example 15 with TaskData

use of com.ichi2.async.DeckTask.TaskData in project Anki-Android by Ramblurr.

the class DeckTask method doInBackgroundSaveCollection.

private TaskData doInBackgroundSaveCollection(TaskData... params) {
    Log.i(AnkiDroidApp.TAG, "doInBackgroundSaveCollection");
    Collection col = params[0].getCollection();
    if (col != null) {
        try {
            col.save();
        } catch (RuntimeException e) {
            Log.e(AnkiDroidApp.TAG, "Error on saving deck in background: " + e);
        }
    }
    return null;
}
Also used : Collection(com.ichi2.libanki.Collection)

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