Search in sources :

Example 1 with ReminderService

use of com.ichi2.anki.services.ReminderService in project AnkiChinaAndroid by ankichinateam.

the class ReminderService method getDeckOptionDue.

// getDeckOptionDue information, will recur one time to workaround collection close if recur is true
@Nullable
private List<DeckDueTreeNode> getDeckOptionDue(Collection col, long dConfId, boolean recur) {
    // are working
    if (col.getDb() == null || col.getDecks().getConf(dConfId) == null) {
        Timber.d("Deck option %s became unavailable while ReminderService was working. Ignoring", dConfId);
        return null;
    }
    List<DeckDueTreeNode> decks = new ArrayList<>();
    try {
        // This loop over top level deck only. No notification will ever occur for subdecks.
        for (DeckDueTreeNode node : col.getSched().deckDueTree()) {
            JSONObject deck = col.getDecks().get(node.getDid(), false);
            // Dynamic deck has no "conf", so are not added here.
            if (deck != null && deck.optLong("conf") == dConfId) {
                decks.add(node);
            }
        }
        return decks;
    } catch (Exception e) {
        if (recur) {
            Timber.i(e, "getDeckOptionDue exception - likely database re-initialization from auto-sync. Will re-try after sleep.");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Timber.i(ex, "Thread interrupted while waiting to retry. Likely unimportant.");
                Thread.currentThread().interrupt();
            }
            return getDeckOptionDue(col, dConfId, false);
        } else {
            Timber.w(e, "Database unavailable while working. No re-tries left.");
        }
    }
    return null;
}
Also used : DeckDueTreeNode(com.ichi2.libanki.sched.DeckDueTreeNode) JSONObject(com.ichi2.utils.JSONObject) ArrayList(java.util.ArrayList) Nullable(androidx.annotation.Nullable)

Aggregations

Nullable (androidx.annotation.Nullable)1 DeckDueTreeNode (com.ichi2.libanki.sched.DeckDueTreeNode)1 JSONObject (com.ichi2.utils.JSONObject)1 ArrayList (java.util.ArrayList)1