Search in sources :

Example 61 with Sched

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

the class CollectionTask method nonTaskUndo.

@VisibleForTesting
public static Card nonTaskUndo(Collection col) {
    AbstractSched sched = col.getSched();
    Card card = col.undo();
    if (card == null) {
        /* multi-card action undone, no action to take here */
        Timber.d("Multi-select undo succeeded");
    } else {
        // cid is actually a card id.
        // a review was undone,
        /* card review undone, set up to review that card again */
        Timber.d("Single card review undo succeeded");
        card.startTimer();
        col.reset();
        sched.deferReset(card);
    }
    return card;
}
Also used : AbstractSched(com.ichi2.libanki.sched.AbstractSched) Card(com.ichi2.libanki.Card) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 62 with Sched

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

the class ContentProviderTest method testBuryCard.

/**
 * Test burying a card through the ReviewInfo endpoint
 */
@Test
public void testBuryCard() {
    // get the first card due
    // ----------------------
    Collection col = getCol();
    Card card = getFirstCardFromScheduler(col);
    // verify that the card is not already user-buried
    Assert.assertNotEquals("Card is not user-buried before test", Consts.QUEUE_TYPE_SIBLING_BURIED, card.getQueue());
    // retain the card id, we will lookup the card after the update
    long cardId = card.getId();
    // bury it through the API
    // -----------------------
    ContentResolver cr = getContentResolver();
    Uri reviewInfoUri = FlashCardsContract.ReviewInfo.CONTENT_URI;
    ContentValues values = new ContentValues();
    long noteId = card.note().getId();
    int cardOrd = card.getOrd();
    int bury = 1;
    values.put(FlashCardsContract.ReviewInfo.NOTE_ID, noteId);
    values.put(FlashCardsContract.ReviewInfo.CARD_ORD, cardOrd);
    values.put(FlashCardsContract.ReviewInfo.BURY, bury);
    int updateCount = cr.update(reviewInfoUri, values, null, null);
    assertEquals("Check if update returns 1", 1, updateCount);
    // verify that it did get buried
    // -----------------------------
    Card cardAfterUpdate = col.getCard(cardId);
    // QUEUE_TYPE_MANUALLY_BURIED was also used for SIBLING_BURIED in sched v1
    assertEquals("Card is user-buried", (schedVersion == 1) ? Consts.QUEUE_TYPE_SIBLING_BURIED : Consts.QUEUE_TYPE_MANUALLY_BURIED, cardAfterUpdate.getQueue());
    // cleanup, unbury cards
    // ---------------------
    col.getSched().unburyCards();
}
Also used : ContentValues(android.content.ContentValues) Collection(com.ichi2.libanki.Collection) Uri(android.net.Uri) Card(com.ichi2.libanki.Card) ContentResolver(android.content.ContentResolver) Test(org.junit.Test)

Aggregations

Card (com.ichi2.libanki.Card)44 Collection (com.ichi2.libanki.Collection)38 Test (org.junit.Test)35 RobolectricTest (com.ichi2.anki.RobolectricTest)28 Note (com.ichi2.libanki.Note)19 AbstractSched (com.ichi2.libanki.sched.AbstractSched)18 DeckConfig (com.ichi2.libanki.DeckConfig)11 JSONObject (com.ichi2.utils.JSONObject)9 Cursor (android.database.Cursor)7 Sched (com.ichi2.libanki.Sched)6 SchedV2 (com.ichi2.libanki.sched.SchedV2)6 JSONArray (com.ichi2.utils.JSONArray)6 SuppressLint (android.annotation.SuppressLint)4 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)4 DB (com.ichi2.libanki.DB)4 Model (com.ichi2.libanki.Model)4 Sched (com.ichi2.libanki.sched.Sched)4 ArrayList (java.util.ArrayList)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ContentValues (android.content.ContentValues)3