Search in sources :

Example 1 with DUE

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

the class ContentProviderTest method testUpdateTags.

/**
 * Update tags on a note
 */
@Test
public void testUpdateTags() {
    // get the first card due
    // ----------------------
    Collection col = getCol();
    Card card = getFirstCardFromScheduler(col);
    Note note = card.note();
    long noteId = note.getId();
    // make sure the tag is what we expect initially
    // ---------------------------------------------
    List<String> tagList = note.getTags();
    assertEquals("only one tag", 1, tagList.size());
    assertEquals("check tag value", TEST_TAG, tagList.get(0));
    // update tags
    // -----------
    String tag2 = "mynewtag";
    ContentResolver cr = InstrumentationRegistry.getInstrumentation().getTargetContext().getContentResolver();
    Uri updateNoteUri = Uri.withAppendedPath(FlashCardsContract.Note.CONTENT_URI, Long.toString(noteId));
    ContentValues values = new ContentValues();
    values.put(FlashCardsContract.Note.TAGS, TEST_TAG + " " + tag2);
    int updateCount = cr.update(updateNoteUri, values, null, null);
    assertEquals("updateCount is 1", 1, updateCount);
    // lookup the note now and verify tags
    // -----------------------------------
    Note noteAfterUpdate = col.getNote(noteId);
    List<String> newTagList = noteAfterUpdate.getTags();
    assertEquals("two tags", 2, newTagList.size());
    assertEquals("check first tag", TEST_TAG, newTagList.get(0));
    assertEquals("check second tag", tag2, newTagList.get(1));
}
Also used : ContentValues(android.content.ContentValues) Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Uri(android.net.Uri) Card(com.ichi2.libanki.Card) ContentResolver(android.content.ContentResolver) Test(org.junit.Test)

Example 2 with DUE

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

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 = InstrumentationRegistry.getInstrumentation().getTargetContext().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)

Example 3 with DUE

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

the class ContentProviderTest method testSuspendCard.

/**
 * Test suspending a card through the ReviewInfo endpoint
 */
@Test
public void testSuspendCard() {
    // get the first card due
    // ----------------------
    Collection col = getCol();
    Card card = getFirstCardFromScheduler(col);
    // verify that the card is not already suspended
    Assert.assertNotEquals("Card is not suspended before test", Consts.QUEUE_TYPE_SUSPENDED, card.getQueue());
    // retain the card id, we will lookup the card after the update
    long cardId = card.getId();
    // suspend it through the API
    // --------------------------
    ContentResolver cr = InstrumentationRegistry.getInstrumentation().getTargetContext().getContentResolver();
    Uri reviewInfoUri = FlashCardsContract.ReviewInfo.CONTENT_URI;
    ContentValues values = new ContentValues();
    long noteId = card.note().getId();
    int cardOrd = card.getOrd();
    int suspend = 1;
    values.put(FlashCardsContract.ReviewInfo.NOTE_ID, noteId);
    values.put(FlashCardsContract.ReviewInfo.CARD_ORD, cardOrd);
    values.put(FlashCardsContract.ReviewInfo.SUSPEND, suspend);
    int updateCount = cr.update(reviewInfoUri, values, null, null);
    assertEquals("Check if update returns 1", 1, updateCount);
    // verify that it did get suspended
    // --------------------------------
    Card cardAfterUpdate = col.getCard(cardId);
    assertEquals("Card is suspended", Consts.QUEUE_TYPE_SUSPENDED, cardAfterUpdate.getQueue());
    // cleanup, unsuspend card and reschedule
    // --------------------------------------
    col.getSched().unsuspendCards(new long[] { cardId });
    col.reset();
}
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)

Example 4 with DUE

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

the class StudyOptionsFragment method handleDeckSelection.

private void handleDeckSelection(long did, boolean dontSkipStudyOptions) {
    // Clear the undo history when selecting a new deck
    if (getCol().getDecks().selected() != did) {
        getCol().clearUndo();
    }
    // Select the deck
    getCol().getDecks().select(did);
    // Also forget the last deck used by the Browser
    CardBrowser.clearLastDeckId();
    // Reset the schedule so that we get the counts for the currently selected deck
    mFocusedDeck = did;
    // Get some info about the deck to handle special cases
    int pos = mDeckListAdapter.findDeckPosition(did);
    AbstractDeckTreeNode deckDueTreeNode = mDeckListAdapter.getDeckList().get(pos);
    // if (!deckDueTreeNode.shouldDisplayCounts() || deckDueTreeNode.knownToHaveRep()) {
    // If we don't yet have numbers, we trust the user that they knows what they opens, tries to open it.
    // If there is nothing to review, it'll come back to deck picker.
    openReviewerOrStudyOptions(dontSkipStudyOptions);
// return;
// }
// There are numbers
// Figure out what action to take
// if (getCol().getSched().hasCardsTodayAfterStudyAheadLimit()) {
// // If there are cards due that can't be studied yet (due to the learn ahead limit) then go to study options
// openStudyOptions(false);
// } else if (getCol().getSched().newDue() || getCol().getSched().revDue()) {
// // If there are no cards to review because of the daily study limit then give "Study more" option
// UIUtils.showSnackbar(getAnkiActivity(), R.string.studyoptions_limit_reached, false, R.string.study_more, v -> {
// CustomStudyDialog d = CustomStudyDialog.newInstance(
// CustomStudyDialog.CONTEXT_MENU_LIMITS,
// getCol().getDecks().selected(), true, this);
// showDialogFragment(d);
// }, getView().findViewById(R.id.root_layout), mSnackbarShowHideCallback);
// // Check if we need to update the fragment or update the deck list. The same checks
// // are required for all snackbars below.
// if (mFragmented) {
// // Tablets must always show the study options that corresponds to the current deck,
// // regardless of whether the deck is currently reviewable or not.
// openStudyOptions(false);
// } else {
// // On phones, we update the deck list to ensure the currently selected deck is
// // highlighted correctly.
// updateDeckList();
// }
// } else if (getCol().getDecks().isDyn(did)) {
// // Go to the study options screen if filtered deck with no cards to study
// openStudyOptions(false);
// } else if (!deckDueTreeNode.hasChildren() && getCol().cardCount(new Long[] {did}) == 0) {
// // If the deck is empty and has no children then show a message saying it's empty
// final Uri helpUrl = Uri.parse(getResources().getString(R.string.link_manual_getting_started));
// getAnkiActivity().mayOpenUrl(helpUrl);
// UIUtils.showSnackbar(getAnkiActivity(), R.string.empty_deck, false, R.string.help,
// v -> openHelpUrl(helpUrl), getView().findViewById(R.id.root_layout), mSnackbarShowHideCallback);
// if (mFragmented) {
// openStudyOptions(false);
// } else {
// updateDeckList();
// }
// } else {
// // Otherwise say there are no cards scheduled to study, and give option to do custom study
// UIUtils.showSnackbar(getAnkiActivity(), R.string.studyoptions_empty_schedule, false, R.string.custom_study, v -> {
// CustomStudyDialog d = CustomStudyDialog.newInstance(
// CustomStudyDialog.CONTEXT_MENU_EMPTY_SCHEDULE,
// getCol().getDecks().selected(), true, this);
// showDialogFragment(d);
// }, getView().findViewById(R.id.root_layout), mSnackbarShowHideCallback);
// if (mFragmented) {
// openStudyOptions(false);
// } else {
// updateDeckList();
// }
// }
}
Also used : AbstractDeckTreeNode(com.ichi2.libanki.sched.AbstractDeckTreeNode)

Example 5 with DUE

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

the class SelfStudyActivity method removeNotesView.

/**
 * Removes cards from view. Doesn't delete them in model (database).
 *
 * @param reorderCards Whether to rearrange the positions of checked items (DEFECT: Currently deselects all)
 */
private void removeNotesView(java.util.Collection<Long> cardsIds, boolean reorderCards) {
    long reviewerCardId = getReviewerCardId();
    List<CardCache> oldMCards = getCards();
    Map<Long, Integer> idToPos = getPositionMap(oldMCards);
    Set<Long> idToRemove = new HashSet<Long>();
    for (Long cardId : cardsIds) {
        if (cardId == reviewerCardId) {
            mReloadRequired = true;
        }
        if (idToPos.containsKey(cardId)) {
            idToRemove.add(cardId);
        }
    }
    List<CardCache> newMCards = new ArrayList<>();
    int pos = 0;
    for (CardCache card : oldMCards) {
        if (!idToRemove.contains(card.getId())) {
            newMCards.add(new CardCache(card, pos++));
        }
    }
    mCards = newMCards;
    if (reorderCards) {
        // Suboptimal from a UX perspective, we should reorder
        // but this is only hit on a rare sad path and we'd need to rejig the data structures to allow an efficient
        // search
        Timber.w("Removing current selection due to unexpected removal of cards");
    }
    updateList();
}
Also used : CardCache(com.ichi2.anki.CardBrowser.CardCache) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

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