use of com.ichi2.utils.JSONArray in project Anki-Android by ankidroid.
the class Sched method _fillDyn.
private List<Long> _fillDyn(@NonNull Deck deck) {
JSONArray terms = deck.getJSONArray("terms").getJSONArray(0);
String search = terms.getString(0);
int limit = terms.getInt(1);
int order = terms.getInt(2);
SortOrder orderlimit = new SortOrder.AfterSqlOrderBy(_dynOrder(order, limit));
if (!TextUtils.isEmpty(search.trim())) {
search = String.format(Locale.US, "(%s)", search);
}
search = String.format(Locale.US, "%s -is:suspended -is:buried -deck:filtered -is:learn", search);
List<Long> ids = mCol.findCards(search, orderlimit);
if (ids.isEmpty()) {
return ids;
}
// move the cards over
mCol.log(deck.getLong("id"), ids);
_moveToDyn(deck.getLong("id"), ids);
return ids;
}
use of com.ichi2.utils.JSONArray in project Anki-Android by ankidroid.
the class Sched method _newConf.
/**
* Tools ******************************************************************** ***************************
*/
@Override
@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());
JSONArray delays = conf.optJSONArray("delays");
if (delays == null) {
delays = oconf.getJSONObject("new").getJSONArray("delays");
}
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));
// overrides
dict.put("delays", delays);
dict.put("separate", conf.getBoolean("separate"));
dict.put("order", Consts.NEW_CARDS_DUE);
dict.put("perDay", mReportLimit);
return dict;
}
use of com.ichi2.utils.JSONArray in project Anki-Android by ankidroid.
the class ReviewerTest method testMultipleCards.
@Test
public synchronized void testMultipleCards() throws ConfirmModSchemaException {
addNoteWithThreeCards();
Collection col = getCol();
JSONObject nw = col.getDecks().confForDid(1).getJSONObject("new");
MockTime time = getCollectionTime();
nw.put("delays", new JSONArray(new int[] { 1, 10, 60, 120 }));
waitForAsyncTasksToComplete();
Reviewer reviewer = startReviewer();
waitForAsyncTasksToComplete();
assertCounts(reviewer, 3, 0, 0);
// card 1 is shown
answerCardOrdinalAsGood(reviewer, 1);
// card get scheduler in [10, 12.5] minutes
time.addM(3);
// We wait 3 minutes to ensure card 2 is scheduled after card 1
// card 2 is shown
answerCardOrdinalAsGood(reviewer, 2);
// Same as above
time.addM(3);
// card 3 is shown
answerCardOrdinalAsGood(reviewer, 3);
undo(reviewer);
assertCurrentOrdIs(reviewer, 3);
// card 3 is shown
answerCardOrdinalAsGood(reviewer, 3);
// Anki Desktop shows "1"
assertCurrentOrdIsNot(reviewer, 3);
}
use of com.ichi2.utils.JSONArray in project Anki-Android by ankidroid.
the class ReviewerTest method cloneTemplate.
private void cloneTemplate(ModelManager models, Model m) throws ConfirmModSchemaException {
JSONArray tmpls = m.getJSONArray("tmpls");
JSONObject defaultTemplate = tmpls.getJSONObject(0);
JSONObject newTemplate = defaultTemplate.deepClone();
newTemplate.put("ord", tmpls.length());
String card_name = getTargetContext().getString(R.string.card_n_name, tmpls.length() + 1);
newTemplate.put("name", card_name);
models.addTemplate(m, newTemplate);
}
use of com.ichi2.utils.JSONArray in project Anki-Android by ankidroid.
the class ModelTest method test_req.
@Test
public void test_req() {
Collection col = getCol();
ModelManager mm = col.getModels();
Model basic = mm.byName("Basic");
assertTrue(basic.has("req"));
reqSize(basic);
JSONArray r = basic.getJSONArray("req").getJSONArray(0);
assertEquals(0, r.getInt(0));
assertTrue(Arrays.asList(new String[] { REQ_ANY, REQ_ALL }).contains(r.getString(1)));
assertEquals(1, r.getJSONArray(2).length());
assertEquals(0, r.getJSONArray(2).getInt(0));
Model opt = mm.byName("Basic (optional reversed card)");
reqSize(opt);
r = opt.getJSONArray("req").getJSONArray(0);
assertTrue(Arrays.asList(new String[] { REQ_ANY, REQ_ALL }).contains(r.getString(1)));
assertEquals(1, r.getJSONArray(2).length());
assertEquals(0, r.getJSONArray(2).getInt(0));
assertEquals(new JSONArray("[1,\"all\",[1,2]]"), opt.getJSONArray("req").getJSONArray(1));
// testing any
opt.getJSONArray("tmpls").getJSONObject(1).put("qfmt", "{{Back}}{{Add Reverse}}");
mm.save(opt, true);
assertEquals(new JSONArray("[1, \"any\", [1, 2]]"), opt.getJSONArray("req").getJSONArray(1));
// testing null
opt.getJSONArray("tmpls").getJSONObject(1).put("qfmt", "{{^Add Reverse}}{{/Add Reverse}}");
mm.save(opt, true);
assertEquals(new JSONArray("[1, \"none\", []]"), opt.getJSONArray("req").getJSONArray(1));
opt = mm.byName("Basic (type in the answer)");
reqSize(opt);
r = opt.getJSONArray("req").getJSONArray(0);
assertTrue(Arrays.asList(new String[] { REQ_ANY, REQ_ALL }).contains(r.getString(1)));
if (col.getModels() instanceof ModelsV16) {
assertEquals(new JSONArray("[0, 1]"), r.getJSONArray(2));
} else {
// TODO: Port anki@4e33775ed4346ef136ece6ef5efec5ba46057c6b
assertEquals(new JSONArray("[0]"), r.getJSONArray(2));
}
}
Aggregations