Search in sources :

Example 41 with DeckConfig

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

the class SchedV2Test method test_learn_dayV2.

@Test
public void test_learn_dayV2() throws Exception {
    Collection col = getColV2();
    // add a note
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    col.reset();
    Card c = getCard();
    DeckConfig conf = col.getSched()._cardConf(c);
    conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 1, 10, 1440, 2880 }));
    col.getDecks().save(conf);
    // pass it
    col.getSched().answerCard(c, BUTTON_THREE);
    // two reps to graduate, 1 more today
    assertEquals(3, c.getLeft() % 1000);
    assertEquals(1, c.getLeft() / 1000);
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
    c = getCard();
    assertEquals(SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_THREE));
    // answering it will place it in queue 3
    col.getSched().answerCard(c, BUTTON_THREE);
    assertEquals(col.getSched().getToday() + 1, c.getDue());
    assertEquals(QUEUE_TYPE_DAY_LEARN_RELEARN, c.getQueue());
    assertNull(getCard());
    // for testing, move it back a day
    c.setDue(c.getDue() - 1);
    c.flush();
    col.reset();
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
    c = getCard();
    // nextIvl should work
    assertEquals(SECONDS_PER_DAY * 2, col.getSched().nextIvl(c, BUTTON_THREE));
    // if we fail it, it should be back in the correct queue
    col.getSched().answerCard(c, BUTTON_ONE);
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
    col.undo();
    col.reset();
    c = getCard();
    col.getSched().answerCard(c, BUTTON_THREE);
    // simulate the passing of another two days
    c.setDue(c.getDue() - 2);
    c.flush();
    col.reset();
    // the last pass should graduate it into a review card
    assertEquals(SECONDS_PER_DAY, col.getSched().nextIvl(c, BUTTON_THREE));
    col.getSched().answerCard(c, BUTTON_THREE);
    assertEquals(CARD_TYPE_REV, c.getType());
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
    // if the lapse step is tomorrow, failing it should handle the counts
    // correctly
    c.setDue(0);
    c.flush();
    col.reset();
    assertEquals(new Counts(0, 0, 1), col.getSched().counts());
    conf = col.getSched()._cardConf(c);
    conf.getJSONObject("lapse").put("delays", new JSONArray(new double[] { 1440 }));
    col.getDecks().save(conf);
    c = getCard();
    col.getSched().answerCard(c, BUTTON_ONE);
    assertEquals(QUEUE_TYPE_DAY_LEARN_RELEARN, c.getQueue());
    assertEquals(new Counts(0, 0, 0), col.getSched().counts());
}
Also used : Note(com.ichi2.libanki.Note) JSONArray(com.ichi2.utils.JSONArray) Collection(com.ichi2.libanki.Collection) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 42 with DeckConfig

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

the class SchedV2Test method test_newBoxes_v2.

@Test
public void test_newBoxes_v2() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    col.reset();
    Card c = getCard();
    DeckConfig conf = col.getSched()._cardConf(c);
    conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 1, 2, 3, 4, 5 }));
    col.getDecks().save(conf);
    col.getSched().answerCard(c, BUTTON_TWO);
    // should handle gracefully
    conf.getJSONObject("new").put("delays", new JSONArray(new double[] { 1 }));
    col.getDecks().save(conf);
    col.getSched().answerCard(c, BUTTON_TWO);
}
Also used : Note(com.ichi2.libanki.Note) JSONArray(com.ichi2.utils.JSONArray) Collection(com.ichi2.libanki.Collection) DeckConfig(com.ichi2.libanki.DeckConfig) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 43 with DeckConfig

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

the class FilteredDeckUtil method createFilteredDeck.

public static long createFilteredDeck(Collection col, String name, String search) {
    long filteredDid = 0;
    try {
        filteredDid = col.getDecks().newDyn(name);
    } catch (DeckRenameException filteredAncestor) {
        throw new RuntimeException(filteredAncestor);
    }
    DeckConfig conf = col.getDecks().confForDid(filteredDid);
    conf.getJSONArray("terms").getJSONArray(0).put(0, search);
    col.getDecks().save(conf);
    return filteredDid;
}
Also used : DeckRenameException(com.ichi2.libanki.backend.exception.DeckRenameException) DeckConfig(com.ichi2.libanki.DeckConfig)

Example 44 with DeckConfig

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

the class DeckOptions method buildLists.

// TODO Tracked in https://github.com/ankidroid/Anki-Android/issues/5019
@SuppressWarnings("deprecation")
protected void buildLists() {
    android.preference.ListPreference deckConfPref = (android.preference.ListPreference) findPreference("deckConf");
    List<DeckConfig> confs = mCol.getDecks().allConf();
    Collections.sort(confs, NamedJSONComparator.INSTANCE);
    String[] confValues = new String[confs.size()];
    String[] confLabels = new String[confs.size()];
    for (int i = 0; i < confs.size(); i++) {
        DeckConfig o = confs.get(i);
        confValues[i] = o.getString("id");
        confLabels[i] = o.getString("name");
    }
    deckConfPref.setEntries(confLabels);
    deckConfPref.setEntryValues(confValues);
    deckConfPref.setValue(mPref.getString("deckConf", "0"));
    android.preference.ListPreference newOrderPref = (android.preference.ListPreference) findPreference("newOrder");
    newOrderPref.setEntries(R.array.new_order_labels);
    newOrderPref.setEntryValues(R.array.new_order_values);
    newOrderPref.setValue(mPref.getString("newOrder", "0"));
    android.preference.ListPreference leechActPref = (android.preference.ListPreference) findPreference("lapLeechAct");
    leechActPref.setEntries(R.array.leech_action_labels);
    leechActPref.setEntryValues(R.array.leech_action_values);
    leechActPref.setValue(mPref.getString("lapLeechAct", Integer.toString(Consts.LEECH_SUSPEND)));
}
Also used : DeckConfig(com.ichi2.libanki.DeckConfig)

Example 45 with DeckConfig

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

the class DeckPickerTest method limitAppliedAfterReview.

@Test
public void limitAppliedAfterReview() {
    Collection col = getCol();
    AbstractSched sched = col.getSched();
    DeckConfig dconf = col.getDecks().getConf(1);
    assertNotNull(dconf);
    dconf.getJSONObject("new").put("perDay", 10);
    col.getDecks().save(dconf);
    for (int i = 0; i < 11; i++) {
        addNoteUsingBasicModel("Which card is this ?", Integer.toString(i));
    }
    // This set a card as current card
    sched.getCard();
    ensureCollectionLoadIsSynchronous();
    DeckPicker deckPicker = super.startActivityNormallyOpenCollectionWithIntent(DeckPicker.class, new Intent());
    assertEquals(10, deckPicker.mDueTree.get(0).getNewCount());
}
Also used : AbstractSched(com.ichi2.libanki.sched.AbstractSched) Collection(com.ichi2.libanki.Collection) Intent(android.content.Intent) DeckConfig(com.ichi2.libanki.DeckConfig) Test(org.junit.Test)

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