Search in sources :

Example 56 with DECK

use of com.ichi2.anki.CardBrowser.Column.DECK in project AnkiChinaAndroid by ankichinateam.

the class SchedV2 method _moveToDyn.

protected void _moveToDyn(long did, @NonNull List<Long> ids, int start) {
    Deck deck = mCol.getDecks().get(did);
    ArrayList<Object[]> data = new ArrayList<>();
    int u = mCol.usn();
    int due = start;
    for (Long id : ids) {
        data.add(new Object[] { did, due, u, id });
        due += 1;
    }
    String queue = "";
    if (!deck.getBoolean("resched")) {
        queue = ", queue = " + Consts.QUEUE_TYPE_REV + "";
    }
    mCol.getDb().executeMany("UPDATE cards SET odid = did, " + "odue = due, did = ?, due = (case when due <= 0 then due else ? end), usn = ? " + queue + " WHERE id = ?", data);
}
Also used : ArrayList(java.util.ArrayList) Deck(com.ichi2.libanki.Deck)

Example 57 with DECK

use of com.ichi2.anki.CardBrowser.Column.DECK in project AnkiChinaAndroid by ankichinateam.

the class SchedV2 method rebuildDyn.

// Note: The original returns an integer result. We return List<Long> with that number to satisfy the
// interface requirements. The result isn't used anywhere so this isn't a problem.
// Overridden, because upstream implements exactly the same method in two different way for unknown reason
@Nullable
public List<Long> rebuildDyn(long did) {
    if (did == 0) {
        did = mCol.getDecks().selected();
    }
    Deck deck = mCol.getDecks().get(did);
    if (deck.getInt("dyn") == 0) {
        Timber.e("error: deck is not a filtered deck");
        return null;
    }
    // move any existing cards back first, then fill
    emptyDyn(did);
    int cnt = _fillDyn(deck);
    if (cnt == 0) {
        return null;
    }
    // and change to our new deck
    mCol.getDecks().select(did);
    return Collections.singletonList((long) cnt);
}
Also used : Deck(com.ichi2.libanki.Deck) Nullable(androidx.annotation.Nullable)

Example 58 with DECK

use of com.ichi2.anki.CardBrowser.Column.DECK in project AnkiChinaAndroid by ankichinateam.

the class SchedV2 method _updateStats.

public void _updateStats(@NonNull Card card, @NonNull String type, long cnt) {
    String key = type + "Today";
    long did = card.getDid();
    List<Deck> list = mCol.getDecks().parents(did);
    list.add(mCol.getDecks().get(did));
    for (Deck g : list) {
        JSONArray a = g.getJSONArray(key);
        // add
        a.put(1, a.getLong(1) + cnt);
        mCol.getDecks().save(g);
    }
}
Also used : JSONArray(com.ichi2.utils.JSONArray) Deck(com.ichi2.libanki.Deck)

Example 59 with DECK

use of com.ichi2.anki.CardBrowser.Column.DECK 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 60 with DECK

use of com.ichi2.anki.CardBrowser.Column.DECK in project AnkiChinaAndroid by ankichinateam.

the class SchedV2 method _fillDyn.

/**
 * Whether the filtered deck is empty
 * Overriden
 */
private int _fillDyn(Deck deck) {
    int start = -100000;
    int total = 0;
    JSONArray terms;
    List<Long> ids;
    terms = deck.getJSONArray("terms");
    for (int i = 0; i < terms.length(); i++) {
        JSONArray term = terms.getJSONArray(i);
        String search = term.getString(0);
        int limit = term.getInt(1);
        int order = term.getInt(2);
        String orderlimit = _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", search);
        ids = mCol.findCards(search, orderlimit);
        if (ids.isEmpty()) {
            return total;
        }
        // move the cards over
        mCol.log(deck.getLong("id"), ids);
        _moveToDyn(deck.getLong("id"), ids, start + total);
        total += ids.size();
    }
    return total;
}
Also used : JSONArray(com.ichi2.utils.JSONArray)

Aggregations

Deck (com.ichi2.libanki.Deck)100 Collection (com.ichi2.libanki.Collection)97 JSONObject (com.ichi2.utils.JSONObject)88 Test (org.junit.Test)80 JSONArray (com.ichi2.utils.JSONArray)55 Card (com.ichi2.libanki.Card)53 Note (com.ichi2.libanki.Note)50 ArrayList (java.util.ArrayList)47 RobolectricTest (com.ichi2.anki.RobolectricTest)44 DeckConfig (com.ichi2.libanki.DeckConfig)37 JSONException (com.ichi2.utils.JSONException)34 NonNull (androidx.annotation.NonNull)30 HashMap (java.util.HashMap)29 Model (com.ichi2.libanki.Model)23 Map (java.util.Map)22 Intent (android.content.Intent)21 Resources (android.content.res.Resources)18 TextView (android.widget.TextView)18 SharedPreferences (android.content.SharedPreferences)17 Cursor (android.database.Cursor)17