Search in sources :

Example 36 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project Anki-Android by ankidroid.

the class SchedV2Test method test_initial_repeat.

// hard on the first step should be the average of again and good,
// and it should be logged properly
@Test
@Ignore("Port anki@a9c93d933cadbf5d9c7e3e2b4f7a25d2c59da5d3")
public void test_initial_repeat() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    note.setItem("Back", "two");
    col.addNote(note);
    col.reset();
    Card c = getCard();
    col.getSched().answerCard(c, BUTTON_TWO);
    // should be due in ~ 5.5 mins
    long expected = col.getTime().intTime() + (int) (5.5 * 60);
    long due = c.getDue();
    assertThat(expected - 10, is(lessThan(due)));
    assertThat(due, is(lessThanOrEqualTo((long) (expected * 1.25))));
    long ivl = col.getDb().queryLongScalar("select ivl from revlog");
    assertEquals((long) (-5.5 * 60), ivl);
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card) Ignore(org.junit.Ignore) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 37 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project Anki-Android by ankidroid.

the class SchedTest method test_reviewsV1.

@Test
public void test_reviewsV1() throws Exception {
    Collection col = getColV1();
    // add a note
    Note note = col.newNote();
    note.setItem("Front", "one");
    note.setItem("Back", "two");
    col.addNote(note);
    // set the card up as a review card, due 8 days ago
    Card c = note.cards().get(0);
    c.setType(CARD_TYPE_REV);
    c.setQueue(QUEUE_TYPE_REV);
    c.setDue(col.getSched().getToday() - 8);
    c.setFactor(STARTING_FACTOR);
    c.setReps(3);
    c.setLapses(1);
    c.setIvl(100);
    c.startTimer();
    c.flush();
    // save it for later use as well
    Card cardcopy = c.clone();
    // failing it should put it in the learn queue with the default options
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    // different delay to new
    col.reset();
    DeckConfig conf = col.getSched()._cardConf(c);
    conf.getJSONObject("lapse").put("delays", new JSONArray(new double[] { 2, 20 }));
    col.getDecks().save(conf);
    col.getSched().answerCard(c, BUTTON_ONE);
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
    // it should be due tomorrow, with an interval of 1
    assertEquals(col.getSched().getToday() + 1, c.getODue());
    assertEquals(1, c.getIvl());
    // but because it's in the learn queue, its current due time should be in
    // the future
    assertThat(c.getDue(), is(greaterThanOrEqualTo(col.getTime().intTime())));
    assertThat(c.getDue() - col.getTime().intTime(), is(greaterThan(118L)));
    // factor should have been decremented
    assertEquals(2300, c.getFactor());
    // check counters
    assertEquals(2, c.getLapses());
    assertEquals(4, c.getReps());
    // check ests.
    assertEquals(120, col.getSched().nextIvl(c, BUTTON_ONE));
    assertEquals(20 * 60, col.getSched().nextIvl(c, BUTTON_TWO));
    // try again with an ease of 2 instead
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    c = cardcopy.clone();
    c.flush();
    col.getSched().answerCard(c, BUTTON_TWO);
    assertEquals(QUEUE_TYPE_REV, c.getQueue());
    // the new interval should be (100 + 8/4) * 1.2 = 122
    assertTrue(checkRevIvl(col, c, 122));
    assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
    // factor should have been decremented
    assertEquals(2350, c.getFactor());
    // check counters
    assertEquals(1, c.getLapses());
    assertEquals(4, c.getReps());
    // ease 3
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    c = cardcopy.clone();
    c.flush();
    col.getSched().answerCard(c, BUTTON_THREE);
    // the new interval should be (100 + 8/2) * 2.5 = 260
    assertTrue(checkRevIvl(col, c, 260));
    assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
    // factor should have been left alone
    assertEquals(STARTING_FACTOR, c.getFactor());
    // ease 4
    // //////////////////////////////////////////////////////////////////////////////////////////////////
    c = cardcopy.clone();
    c.flush();
    col.getSched().answerCard(c, BUTTON_FOUR);
    // the new interval should be (100 + 8) * 2.5 * 1.3 = 351
    assertTrue(checkRevIvl(col, c, 351));
    assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
    // factor should have been increased
    assertEquals(2650, c.getFactor());
}
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 38 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project Anki-Android by ankidroid.

the class SchedV2Test method test_timingV2.

@Test
public void test_timingV2() throws Exception {
    Collection col = getColV2();
    // add a few review cards, due today
    for (int i = 0; i < 5; i++) {
        Note note = col.newNote();
        note.setItem("Front", "num" + i);
        col.addNote(note);
        Card c = note.cards().get(0);
        c.setType(CARD_TYPE_REV);
        c.setQueue(QUEUE_TYPE_REV);
        c.setDue(0);
        c.flush();
    }
    // fail the first one
    col.reset();
    Card c = getCard();
    col.getSched().answerCard(c, BUTTON_ONE);
    // the next card should be another review
    Card c2 = getCard();
    assertEquals(QUEUE_TYPE_REV, c2.getQueue());
    // if the failed card becomes due, it should show first
    c.setDue(col.getTime().intTime() - 1);
    c.flush();
    col.reset();
    c = getCard();
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 39 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project Anki-Android by ankidroid.

the class AnkiActivity method showSimpleMessageDialog.

/**
 * Show a simple message dialog, dismissing the message without taking any further action when OK button is pressed.
 * If a DialogFragment cannot be shown due to the Activity being stopped then the message is shown in the
 * notification bar instead.
 *
 * @param message
 * @param reload flag which forces app to be restarted when true
 */
public void showSimpleMessageDialog(String message, boolean reload) {
    AsyncDialogFragment newFragment = SimpleMessageDialog.newInstance(message, reload);
    showAsyncDialogFragment(newFragment);
}
Also used : AsyncDialogFragment(com.ichi2.anki.dialogs.AsyncDialogFragment)

Example 40 with DUE

use of com.ichi2.anki.CardBrowser.Column.DUE in project Anki-Android by ankidroid.

the class Reviewer method setFullScreen.

// #9332: UI Visibility -> Insets
@SuppressWarnings("deprecation")
private void setFullScreen(final AbstractFlashcardViewer a) {
    // Set appropriate flags to enable Sticky Immersive mode.
    a.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | // | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // temporarily disabled due to #5245
    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_IMMERSIVE);
    // Show / hide the Action bar together with the status bar
    SharedPreferences prefs = AnkiDroidApp.getSharedPrefs(a);
    FullScreenMode fullscreenMode = FullScreenMode.fromPreference(prefs);
    a.getWindow().setStatusBarColor(Themes.getColorFromAttr(a, R.attr.colorPrimaryDark));
    View decorView = a.getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(flags -> {
        final View toolbar = a.findViewById(R.id.toolbar);
        final View answerButtons = a.findViewById(R.id.answer_options_layout);
        final View topbar = a.findViewById(R.id.top_bar);
        if (toolbar == null || topbar == null || answerButtons == null) {
            return;
        }
        // Note that system bars will only be "visible" if none of the
        // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
        boolean visible = (flags & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
        Timber.d("System UI visibility change. Visible: %b", visible);
        if (visible) {
            showViewWithAnimation(toolbar);
            if (fullscreenMode.equals(FullScreenMode.FULLSCREEN_ALL_GONE)) {
                showViewWithAnimation(topbar);
                showViewWithAnimation(answerButtons);
            }
        } else {
            hideViewWithAnimation(toolbar);
            if (fullscreenMode.equals(FullScreenMode.FULLSCREEN_ALL_GONE)) {
                hideViewWithAnimation(topbar);
                hideViewWithAnimation(answerButtons);
            }
        }
    });
}
Also used : SharedPreferences(android.content.SharedPreferences) FullScreenMode(com.ichi2.anki.reviewer.FullScreenMode) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) AudioView(com.ichi2.anki.multimediacard.AudioView)

Aggregations

Test (org.junit.Test)58 Collection (com.ichi2.libanki.Collection)57 Card (com.ichi2.libanki.Card)55 Note (com.ichi2.libanki.Note)52 RobolectricTest (com.ichi2.anki.RobolectricTest)51 JSONObject (com.ichi2.utils.JSONObject)25 DeckConfig (com.ichi2.libanki.DeckConfig)20 JSONArray (com.ichi2.utils.JSONArray)16 ArrayList (java.util.ArrayList)16 Cursor (android.database.Cursor)14 Deck (com.ichi2.libanki.Deck)10 ContentResolver (android.content.ContentResolver)6 ContentValues (android.content.ContentValues)6 Uri (android.net.Uri)6 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 SuppressLint (android.annotation.SuppressLint)5 FileNotFoundException (java.io.FileNotFoundException)5 Activity (android.app.Activity)4 WebView (android.webkit.WebView)4