Search in sources :

Example 11 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.

the class Decks method flush.

public void flush() {
    ContentValues values = new ContentValues();
    if (mChanged) {
        JSONObject decksarray = new JSONObject();
        for (Map.Entry<Long, Deck> d : mDecks.entrySet()) {
            decksarray.put(Long.toString(d.getKey()), d.getValue());
        }
        values.put("decks", Utils.jsonToString(decksarray));
        JSONObject confarray = new JSONObject();
        for (Map.Entry<Long, DeckConfig> d : mDconf.entrySet()) {
            confarray.put(Long.toString(d.getKey()), d.getValue());
        }
        values.put("dconf", Utils.jsonToString(confarray));
        mCol.getDb().update("col", values);
        mChanged = false;
    }
}
Also used : ContentValues(android.content.ContentValues) JSONObject(com.ichi2.utils.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 12 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.

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, current card is not treated differently.
 */
public int _deckNewLimitSingle(@NonNull Deck g) {
    if (g.getInt("dyn") != 0) {
        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 (currentCardIsInQueueWithDeck(Consts.QUEUE_TYPE_NEW, did)) {
        lim--;
    }
    return lim;
}
Also used : NonNull(androidx.annotation.NonNull) DeckConfig(com.ichi2.libanki.DeckConfig)

Example 13 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.

the class SchedV2 method _lapseConf.

// Overridden: different delays for filtered cards.
@NonNull
protected JSONObject _lapseConf(@NonNull Card card) {
    DeckConfig conf = _cardConf(card);
    // normal deck
    if (card.getODid() == 0) {
        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)

Example 14 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.

the class SchedV2 method _newConf.

// Overridden: different delays for filtered cards.
@NonNull
protected JSONObject _newConf(@NonNull Card card) {
    DeckConfig conf = _cardConf(card);
    // normal deck
    if (card.getODid() == 0) {
        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 15 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.

the class Syncer method mergeDecks.

private void mergeDecks(JSONArray rchg) {
    JSONArray decks = rchg.getJSONArray(0);
    for (int i = 0; i < decks.length(); i++) {
        Deck r = new Deck(decks.getJSONObject(i));
        Deck l = mCol.getDecks().get(r.getLong("id"), false);
        // if missing locally or server is newer, update
        if (l == null || r.getLong("mod") > l.getLong("mod")) {
            mCol.getDecks().update(r);
        }
    }
    JSONArray confs = rchg.getJSONArray(1);
    for (int i = 0; i < confs.length(); i++) {
        DeckConfig r = new DeckConfig(confs.getJSONObject(i));
        DeckConfig l = mCol.getDecks().getConf(r.getLong("id"));
        // if missing locally or server is newer, update
        if (l == null || r.getLong("mod") > l.getLong("mod")) {
            mCol.getDecks().updateConf(r);
        }
    }
}
Also used : JSONArray(com.ichi2.utils.JSONArray) Deck(com.ichi2.libanki.Deck) DeckConfig(com.ichi2.libanki.DeckConfig)

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