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