Search in sources :

Example 21 with Collection

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

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

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

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

Example 25 with Collection

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

the class DeckTask method doInBackgroundRepairDeck.

private TaskData doInBackgroundRepairDeck(TaskData... params) {
    Log.i(AnkiDroidApp.TAG, "doInBackgroundRepairDeck");
    String deckPath = params[0].getString();
    Collection col = params[0].getCollection();
    if (col != null) {
        col.close(false);
    }
    return new TaskData(BackupManager.repairDeck(deckPath));
}
Also used : Collection(com.ichi2.libanki.Collection)

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