Search in sources :

Example 71 with Time

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

the class Sched method _answerLrnCard.

/**
 * @param ease 1=no, 2=yes, 3=remove
 */
@Override
protected void _answerLrnCard(@NonNull Card card, @Consts.BUTTON_TYPE int ease) {
    JSONObject conf = _lrnConf(card);
    @Consts.REVLOG_TYPE int type;
    if (card.isInDynamicDeck() && !card.getWasNew()) {
        type = Consts.REVLOG_CRAM;
    } else if (card.getType() == Consts.CARD_TYPE_REV) {
        type = Consts.REVLOG_RELRN;
    } else {
        type = Consts.REVLOG_LRN;
    }
    boolean leaving = false;
    // lrnCount was decremented once when card was fetched
    int lastLeft = card.getLeft();
    // immediate graduate?
    if (ease == Consts.BUTTON_THREE) {
        _rescheduleAsRev(card, conf, true);
        leaving = true;
    // graduation time?
    } else if (ease == Consts.BUTTON_TWO && (card.getLeft() % 1000) - 1 <= 0) {
        _rescheduleAsRev(card, conf, false);
        leaving = true;
    } else {
        // one step towards graduation
        if (ease == Consts.BUTTON_TWO) {
            // decrement real left count and recalculate left today
            int left = (card.getLeft() % 1000) - 1;
            card.setLeft(_leftToday(conf.getJSONArray("delays"), left) * 1000 + left);
        // failed
        } else {
            card.setLeft(_startingLeft(card));
            boolean resched = _resched(card);
            if (conf.has("mult") && resched) {
                // review that's lapsed
                card.setIvl(Math.max(Math.max(1, (int) (card.getIvl() * conf.getDouble("mult"))), conf.getInt("minInt")));
            } else {
            // new card; no ivl adjustment
            // pass
            }
            if (resched && card.isInDynamicDeck()) {
                card.setODue(mToday + 1);
            }
        }
        int delay = _delayForGrade(conf, card.getLeft());
        if (card.getDue() < getTime().intTime()) {
            // not collapsed; add some randomness
            delay *= Utils.randomFloatInRange(1f, 1.25f);
        }
        card.setDue(getTime().intTime() + delay);
        // due today?
        if (card.getDue() < mDayCutoff) {
            mLrnCount += card.getLeft() / 1000;
            // if the queue is not empty and there's nothing else to do, make
            // sure we don't put it at the head of the queue and end up showing
            // it twice in a row
            card.setQueue(Consts.QUEUE_TYPE_LRN);
            if (!mLrnQueue.isEmpty() && revCount() == 0 && newCount() == 0) {
                long smallestDue = mLrnQueue.getFirstDue();
                card.setDue(Math.max(card.getDue(), smallestDue + 1));
            }
            _sortIntoLrn(card.getDue(), card.getId());
        } else {
            // the card is due in one or more days, so we need to use the day learn queue
            long ahead = ((card.getDue() - mDayCutoff) / SECONDS_PER_DAY) + 1;
            card.setDue(mToday + ahead);
            card.setQueue(Consts.QUEUE_TYPE_DAY_LEARN_RELEARN);
        }
    }
    _logLrn(card, ease, conf, leaving, type, lastLeft);
}
Also used : JSONObject(com.ichi2.utils.JSONObject)

Example 72 with Time

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

the class SchedV2 method _updateCutoff.

/**
 * Daily cutoff ************************************************************* **********************************
 * This function uses GregorianCalendar so as to be sensitive to leap years, daylight savings, etc.
 */
/* Overriden: other way to count time*/
@RustCleanup("remove timing == null check once JavaBackend is removed")
public void _updateCutoff() {
    int oldToday = mToday == null ? 0 : mToday;
    SchedTimingToday timing = _timingToday();
    if (timing == null) {
        mToday = _daysSinceCreation();
        mDayCutoff = _dayCutoff();
    } else if (_new_timezone_enabled()) {
        mToday = timing.days_elapsed();
        mDayCutoff = timing.next_day_at();
    } else {
        mToday = _daysSinceCreation();
        mDayCutoff = _dayCutoff();
    }
    if (oldToday != mToday) {
        mCol.log(mToday, mDayCutoff);
    }
    // instead
    for (Deck deck : mCol.getDecks().all()) {
        update(deck);
    }
    // unbury if the day has rolled over
    int unburied = mCol.get_config("lastUnburied", 0);
    if (unburied < mToday) {
        SyncStatus.ignoreDatabaseModification(this::unburyCards);
        mCol.set_config("lastUnburied", mToday);
    }
}
Also used : SchedTimingToday(com.ichi2.libanki.backend.model.SchedTimingToday) Deck(com.ichi2.libanki.Deck) RustCleanup(net.ankiweb.rsdroid.RustCleanup)

Example 73 with Time

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

the class SchedV2 method update.

protected void update(@NonNull Deck g) {
    for (String t : new String[] { "new", "rev", "lrn", "time" }) {
        String key = t + "Today";
        JSONArray tToday = g.getJSONArray(key);
        if (g.getJSONArray(key).getInt(0) != mToday) {
            tToday.put(0, mToday);
            tToday.put(1, 0);
        }
    }
}
Also used : JSONArray(com.ichi2.utils.JSONArray)

Example 74 with Time

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

the class SchedV2 method _answerLrnCard.

// Overriden
protected void _answerLrnCard(@NonNull Card card, @Consts.BUTTON_TYPE int ease) {
    JSONObject conf = _lrnConf(card);
    @Consts.REVLOG_TYPE int type;
    if (card.getType() == Consts.CARD_TYPE_REV || card.getType() == Consts.CARD_TYPE_RELEARNING) {
        type = Consts.REVLOG_RELRN;
    } else {
        type = Consts.REVLOG_LRN;
    }
    // lrnCount was decremented once when card was fetched
    int lastLeft = card.getLeft();
    boolean leaving = false;
    // immediate graduate?
    if (ease == Consts.BUTTON_FOUR) {
        _rescheduleAsRev(card, conf, true);
        leaving = true;
    // next step?
    } else if (ease == Consts.BUTTON_THREE) {
        // graduation time?
        if ((card.getLeft() % 1000) - 1 <= 0) {
            _rescheduleAsRev(card, conf, false);
            leaving = true;
        } else {
            _moveToNextStep(card, conf);
        }
    } else if (ease == Consts.BUTTON_TWO) {
        _repeatStep(card, conf);
    } else {
        // move back to first step
        _moveToFirstStep(card, conf);
    }
    _logLrn(card, ease, conf, leaving, type, lastLeft);
}
Also used : JSONObject(com.ichi2.utils.JSONObject)

Example 75 with Time

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

the class SchedV2 method _getCard.

/*
      Getting the next card ****************************************************
      *******************************************
     */
/**
 * Return the next due card, or null.
 * Overridden: V1 does not allow dayLearnFirst
 */
@Nullable
protected Card _getCard() {
    // learning card due?
    @Nullable Card c = _getLrnCard(false);
    if (c != null) {
        return c;
    }
    // new first, or time for one?
    if (_timeForNewCard()) {
        c = _getNewCard();
        if (c != null) {
            return c;
        }
    }
    // Day learning first and card due?
    boolean dayLearnFirst = mCol.get_config("dayLearnFirst", false);
    if (dayLearnFirst) {
        c = _getLrnDayCard();
        if (c != null) {
            return c;
        }
    }
    // Card due for review?
    c = _getRevCard();
    if (c != null) {
        return c;
    }
    // day learning card due?
    if (!dayLearnFirst) {
        c = _getLrnDayCard();
        if (c != null) {
            return c;
        }
    }
    // New cards left?
    c = _getNewCard();
    if (c != null) {
        return c;
    }
    // collapse or finish
    return _getLrnCard(true);
}
Also used : Nullable(androidx.annotation.Nullable) Card(com.ichi2.libanki.Card) Nullable(androidx.annotation.Nullable)

Aggregations

Test (org.junit.Test)27 Collection (com.ichi2.libanki.Collection)26 JSONObject (com.ichi2.utils.JSONObject)26 RobolectricTest (com.ichi2.anki.RobolectricTest)19 Card (com.ichi2.libanki.Card)19 Note (com.ichi2.libanki.Note)15 JSONArray (com.ichi2.utils.JSONArray)15 Deck (com.ichi2.libanki.Deck)11 ArrayList (java.util.ArrayList)11 DeckConfig (com.ichi2.libanki.DeckConfig)10 IOException (java.io.IOException)10 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)9 HashMap (java.util.HashMap)9 Cursor (android.database.Cursor)8 Nullable (androidx.annotation.Nullable)8 JSONException (com.ichi2.utils.JSONException)8 SharedPreferences (android.content.SharedPreferences)7 Resources (android.content.res.Resources)7 File (java.io.File)7 View (android.view.View)5