Search in sources :

Example 46 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project Anki-Android by ankidroid.

the class Anki2Importer method _did.

/*
     * Decks
     * ***********************************************************
     */
/**
 * Given did in src col, return local id.
 */
private long _did(long did) {
    // already converted?
    if (mDecks.containsKey(did)) {
        return mDecks.get(did);
    }
    // get the name in src
    Deck g = mSrc.getDecks().get(did);
    String name = g.getString("name");
    // if there's a prefix, replace the top level deck
    if (!TextUtils.isEmpty(mDeckPrefix)) {
        List<String> parts = Arrays.asList(Decks.path(name));
        String tmpname = TextUtils.join("::", parts.subList(1, parts.size()));
        name = mDeckPrefix;
        if (!TextUtils.isEmpty(tmpname)) {
            name += "::" + tmpname;
        }
    }
    // Manually create any parents so we can pull in descriptions
    String head = "";
    List<String> parents = Arrays.asList(Decks.path(name));
    for (String parent : parents.subList(0, parents.size() - 1)) {
        if (!TextUtils.isEmpty(head)) {
            head += "::";
        }
        head += parent;
        long idInSrc = mSrc.getDecks().id_safe(head);
        _did(idInSrc);
    }
    // create in local
    long newid = mDst.getDecks().id_safe(name);
    // pull conf over
    if (g.has("conf") && g.getLong("conf") != 1) {
        DeckConfig conf = mSrc.getDecks().getConf(g.getLong("conf"));
        mDst.getDecks().save(conf);
        mDst.getDecks().updateConf(conf);
        Deck g2 = mDst.getDecks().get(newid);
        g2.put("conf", g.getLong("conf"));
        mDst.getDecks().save(g2);
    }
    // save desc
    Deck deck = mDst.getDecks().get(newid);
    deck.put("desc", g.getString("desc"));
    mDst.getDecks().save(deck);
    // add to deck map and return
    mDecks.put(did, newid);
    return newid;
}
Also used : Deck(com.ichi2.libanki.Deck) DeckConfig(com.ichi2.libanki.DeckConfig)

Example 47 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project Anki-Android by ankidroid.

the class Syncer method getDecks.

/**
 * Decks ********************************************************************
 */
private JSONArray getDecks() {
    JSONArray result = new JSONArray();
    if (mCol.getServer()) {
        JSONArray decks = new JSONArray();
        for (Deck g : mCol.getDecks().all()) {
            if (g.getInt("usn") >= mMinUsn) {
                decks.put(g);
            }
        }
        JSONArray dconfs = new JSONArray();
        for (DeckConfig g : mCol.getDecks().allConf()) {
            if (g.getInt("usn") >= mMinUsn) {
                dconfs.put(g);
            }
        }
        result.put(decks);
        result.put(dconfs);
    } else {
        JSONArray decks = new JSONArray();
        for (Deck g : mCol.getDecks().all()) {
            if (g.getInt("usn") == -1) {
                g.put("usn", mMaxUsn);
                decks.put(g);
            }
        }
        JSONArray dconfs = new JSONArray();
        for (DeckConfig g : mCol.getDecks().allConf()) {
            if (g.getInt("usn") == -1) {
                g.put("usn", mMaxUsn);
                dconfs.put(g);
            }
        }
        mCol.getDecks().save();
        result.put(decks);
        result.put(dconfs);
    }
    return result;
}
Also used : JSONArray(com.ichi2.utils.JSONArray) Deck(com.ichi2.libanki.Deck) DeckConfig(com.ichi2.libanki.DeckConfig)

Example 48 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project Anki-Android by ankidroid.

the class SchedV2 method _newConf.

// Overridden: different delays for filtered cards.
@NonNull
protected JSONObject _newConf(@NonNull Card card) {
    DeckConfig conf = _cardConf(card);
    if (!card.isInDynamicDeck()) {
        return conf.getJSONObject("new");
    }
    // dynamic deck; override some attributes, use original deck for others
    DeckConfig oconf = mCol.getDecks().confForDid(card.getODid());
    JSONObject dict = new JSONObject();
    // original deck
    dict.put("ints", oconf.getJSONObject("new").getJSONArray("ints"));
    dict.put("initialFactor", oconf.getJSONObject("new").getInt("initialFactor"));
    dict.put("bury", oconf.getJSONObject("new").optBoolean("bury", true));
    dict.put("delays", oconf.getJSONObject("new").getJSONArray("delays"));
    // overrides
    dict.put("separate", conf.getBoolean("separate"));
    dict.put("order", Consts.NEW_CARDS_DUE);
    dict.put("perDay", mReportLimit);
    return dict;
}
Also used : JSONObject(com.ichi2.utils.JSONObject) DeckConfig(com.ichi2.libanki.DeckConfig) NonNull(androidx.annotation.NonNull)

Example 49 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project Anki-Android by ankidroid.

the class SchedV2 method _deckNewLimitSingle.

/**
 * Maximal number of new card still to see today in deck g. It's computed as:
 * the number of new card to see by day according to the deck optinos
 * minus the number of new cards seen today in deck d or a descendant
 * plus the number of extra new cards to see today in deck d, a parent or a descendant.
 *
 * Limits of its ancestors are not applied.
 * @param considerCurrentCard whether the current card should be taken from the limit (if it belongs to this deck)
 */
public int _deckNewLimitSingle(@NonNull Deck g, boolean considerCurrentCard) {
    if (g.isDyn()) {
        return mDynReportLimit;
    }
    long did = g.getLong("id");
    @NonNull DeckConfig c = mCol.getDecks().confForDid(did);
    int lim = Math.max(0, c.getJSONObject("new").getInt("perDay") - g.getJSONArray("newToday").getInt(1));
    // So currentCard does not have to be taken into consideration in this method
    if (considerCurrentCard && currentCardIsInQueueWithDeck(Consts.QUEUE_TYPE_NEW, did)) {
        lim--;
    }
    return lim;
}
Also used : NonNull(androidx.annotation.NonNull) DeckConfig(com.ichi2.libanki.DeckConfig)

Example 50 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project Anki-Android by ankidroid.

the class SchedV2 method _lapseConf.

// Overridden: different delays for filtered cards.
@NonNull
protected JSONObject _lapseConf(@NonNull Card card) {
    DeckConfig conf = _cardConf(card);
    if (!card.isInDynamicDeck()) {
        return conf.getJSONObject("lapse");
    }
    // dynamic deck; override some attributes, use original deck for others
    DeckConfig oconf = mCol.getDecks().confForDid(card.getODid());
    JSONObject dict = new JSONObject();
    // original deck
    dict.put("minInt", oconf.getJSONObject("lapse").getInt("minInt"));
    dict.put("leechFails", oconf.getJSONObject("lapse").getInt("leechFails"));
    dict.put("leechAction", oconf.getJSONObject("lapse").getInt("leechAction"));
    dict.put("mult", oconf.getJSONObject("lapse").getDouble("mult"));
    dict.put("delays", oconf.getJSONObject("lapse").getJSONArray("delays"));
    // overrides
    dict.put("resched", conf.getBoolean("resched"));
    return dict;
}
Also used : JSONObject(com.ichi2.utils.JSONObject) DeckConfig(com.ichi2.libanki.DeckConfig) NonNull(androidx.annotation.NonNull)

Aggregations

DeckConfig (com.ichi2.libanki.DeckConfig)85 Collection (com.ichi2.libanki.Collection)57 Card (com.ichi2.libanki.Card)50 Test (org.junit.Test)49 RobolectricTest (com.ichi2.anki.RobolectricTest)48 Note (com.ichi2.libanki.Note)47 JSONArray (com.ichi2.utils.JSONArray)42 JSONObject (com.ichi2.utils.JSONObject)27 Deck (com.ichi2.libanki.Deck)14 NonNull (androidx.annotation.NonNull)12 Cursor (android.database.Cursor)5 JSONException (com.ichi2.utils.JSONException)5 ArrayList (java.util.ArrayList)5 Model (com.ichi2.libanki.Model)4 HashMap (java.util.HashMap)4 SuppressLint (android.annotation.SuppressLint)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 ContentValues (android.content.ContentValues)2 Intent (android.content.Intent)2