Search in sources :

Example 61 with TaskData

use of com.ichi2.async.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 62 with TaskData

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

the class DeckTask method doInBackgroundUpdateNote.

private TaskData doInBackgroundUpdateNote(TaskData[] params) {
    // Log.i(AnkiDroidApp.TAG, "doInBackgroundUpdateNote");
    // Save the note
    Sched sched = params[0].getSched();
    Collection col = sched.getCol();
    Card editCard = params[0].getCard();
    Note editNote = editCard.note();
    boolean fromReviewer = params[0].getBoolean();
    // mark undo
    col.markUndo(Collection.UNDO_EDIT_NOTE, new Object[] { col.getNote(editNote.getId()), editCard.getId(), fromReviewer });
    try {
        col.getDb().getDatabase().beginTransaction();
        try {
            // TODO: undo integration
            editNote.flush();
            // flush card too, in case, did has been changed
            editCard.flush();
            if (fromReviewer) {
                Card newCard;
                if (col.getDecks().active().contains(editCard.getDid())) {
                    newCard = editCard;
                    newCard.load();
                    // reload qa-cache
                    newCard.getQuestion(true);
                } else {
                    newCard = getCard(sched);
                }
                publishProgress(new TaskData(newCard));
            } else {
                publishProgress(new TaskData(editCard, editNote.stringTags()));
            }
            col.getDb().getDatabase().setTransactionSuccessful();
        } finally {
            col.getDb().getDatabase().endTransaction();
        }
    } catch (RuntimeException e) {
        Log.e(AnkiDroidApp.TAG, "doInBackgroundUpdateNote - RuntimeException on updating fact: " + e);
        AnkiDroidApp.saveExceptionReportFile(e, "doInBackgroundUpdateNote");
        return new TaskData(false);
    }
    return new TaskData(true);
}
Also used : Sched(com.ichi2.libanki.Sched) Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card)

Example 63 with TaskData

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

the class DeckPicker method onStop.

@Override
protected void onStop() {
    Log.i(AnkiDroidApp.TAG, "DeckPicker - onStop");
    super.onStop();
    if (!mDontSaveOnStop) {
        if (isFinishing()) {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_CLOSE_DECK, mCloseCollectionHandler, new TaskData(AnkiDroidApp.getCol()));
        } else {
            StudyOptionsFragment frag = getFragment();
            if (!(frag != null && !frag.dbSaveNecessary())) {
                UIUtils.saveCollectionInBackground();
            }
        }
    }
}
Also used : TaskData(com.ichi2.async.DeckTask.TaskData)

Example 64 with TaskData

use of com.ichi2.async.TaskData 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 65 with TaskData

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

the class DeckTask method doInBackgroundDeleteDeck.

private TaskData doInBackgroundDeleteDeck(TaskData... params) {
    // Log.i(AnkiDroidApp.TAG, "doInBackgroundDeleteDeck");
    Collection col = params[0].getCollection();
    long did = params[0].getLong();
    col.getDecks().rem(did, true);
    col.getMedia().removeUnusedImages();
    return doInBackgroundLoadDeckCounts(new TaskData(col));
}
Also used : Collection(com.ichi2.libanki.Collection)

Aggregations

Collection (com.ichi2.libanki.Collection)67 TaskData (com.ichi2.async.TaskData)46 JSONObject (com.ichi2.utils.JSONObject)35 Card (com.ichi2.libanki.Card)16 JSONException (com.ichi2.utils.JSONException)15 ArrayList (java.util.ArrayList)14 JSONObject (org.json.JSONObject)13 Resources (android.content.res.Resources)12 HashMap (java.util.HashMap)12 SharedPreferences (android.content.SharedPreferences)11 Deck (com.ichi2.libanki.Deck)11 Intent (android.content.Intent)10 View (android.view.View)9 TextView (android.widget.TextView)9 ConfirmationDialog (com.ichi2.anki.dialogs.ConfirmationDialog)9 TaskListener (com.ichi2.async.TaskListener)9 Map (java.util.Map)9 VisibleForTesting (androidx.annotation.VisibleForTesting)8 CollectionTask (com.ichi2.async.CollectionTask)8 IOException (java.io.IOException)8