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;
}
}
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;
}
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;
}
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;
}
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);
}
}
}
Aggregations