Search in sources :

Example 11 with CardBrowser

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

the class CardBrowserTest method canChangeDeckToRegularDeck.

@Test
public void canChangeDeckToRegularDeck() {
    addDeck("Hello");
    CardBrowser b = getBrowserWithNotes(5);
    List<Deck> decks = b.getValidDecksForChangeDeck();
    for (Deck d : decks) {
        if (d.getString("name").equals("Hello")) {
            return;
        }
    }
    Assert.fail("Added deck was not found in the Card Browser");
}
Also used : Deck(com.ichi2.libanki.Deck) Test(org.junit.Test)

Example 12 with CardBrowser

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

the class CardBrowserTest method filterByFlagDisplaysProperly.

@Test
public void filterByFlagDisplaysProperly() {
    Note cardWithRedFlag = addNoteUsingBasicModel("Card with red flag", "Reverse");
    flagCardForNote(cardWithRedFlag, 1);
    Note cardWithGreenFlag = addNoteUsingBasicModel("Card with green flag", "Reverse");
    flagCardForNote(cardWithGreenFlag, 3);
    Note anotherCardWithRedFlag = addNoteUsingBasicModel("Second card with red flag", "Reverse");
    flagCardForNote(anotherCardWithRedFlag, 1);
    CardBrowser b = getBrowserWithNoNewCards();
    b.filterByFlag(1);
    advanceRobolectricLooperWithSleep();
    assertThat("Flagged cards should be returned", b.getCardCount(), is(2));
}
Also used : Note(com.ichi2.libanki.Note) Test(org.junit.Test)

Example 13 with CardBrowser

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

the class CardBrowserTest method changeDeckIntegrationTestDynamicAndNon.

@Test
public void changeDeckIntegrationTestDynamicAndNon() {
    addDeck("Hello");
    addDynamicDeck("World");
    HashSet<String> validNames = new HashSet<>();
    validNames.add("Default");
    validNames.add("Hello");
    CardBrowser b = getBrowserWithNotes(5);
    List<Deck> decks = b.getValidDecksForChangeDeck();
    for (Deck d : decks) {
        assertThat(validNames, hasItem(d.getString("name")));
    }
    assertThat("Additional unexpected decks were present", decks.size(), is(2));
}
Also used : Deck(com.ichi2.libanki.Deck) Matchers.containsString(org.hamcrest.Matchers.containsString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with CardBrowser

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

the class CardBrowserTest method cannotChangeDeckToDynamicDeck.

@Test
public void cannotChangeDeckToDynamicDeck() {
    // 5932 - dynamic decks are meant to have cards added to them through "Rebuild".
    addDynamicDeck("World");
    CardBrowser b = getBrowserWithNotes(5);
    List<Deck> decks = b.getValidDecksForChangeDeck();
    for (Deck d : decks) {
        if (d.getString("name").equals("World")) {
            Assert.fail("Dynamic decks should not be transferred to by the browser.");
        }
    }
}
Also used : Deck(com.ichi2.libanki.Deck) Test(org.junit.Test)

Example 15 with CardBrowser

use of com.ichi2.anki.CardBrowser in project Anki-Android by Ramblurr.

the class CardBrowser method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // FIXME:
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == DeckPicker.RESULT_DB_ERROR) {
        closeCardBrowser(DeckPicker.RESULT_DB_ERROR);
    }
    // switching back to the multimedia card editor.
    if (requestCode == EDIT_CARD && resultCode == MultimediaCardEditorActivity.RESULT_DELETED) {
        deleteNote(sCardBrowserCard);
        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDeleteNoteHandler, new DeckTask.TaskData(mCol.getSched(), sCardBrowserCard, 3));
    } else if (requestCode == EDIT_CARD && resultCode != RESULT_CANCELED) {
        // Log.i(AnkiDroidApp.TAG, "CardBrowser: Saving card...");
        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UPDATE_FACT, mUpdateCardHandler, new DeckTask.TaskData(mCol.getSched(), sCardBrowserCard, false));
    } else if (requestCode == ADD_NOTE && resultCode == RESULT_OK) {
        mSearchTerms = mSearchEditText.getText().toString().toLowerCase();
        searchCards();
    }
}
Also used : TaskData(com.ichi2.async.DeckTask.TaskData) DeckTask(com.ichi2.async.DeckTask) TaskData(com.ichi2.async.DeckTask.TaskData)

Aggregations

Test (org.junit.Test)16 Intent (android.content.Intent)9 Deck (com.ichi2.libanki.Deck)9 Note (com.ichi2.libanki.Note)7 Card (com.ichi2.libanki.Card)6 MenuItem (android.view.MenuItem)5 CollectionTask (com.ichi2.async.CollectionTask)5 JSONObject (com.ichi2.utils.JSONObject)5 HashSet (java.util.HashSet)5 IntentFilter (android.content.IntentFilter)4 SharedPreferences (android.content.SharedPreferences)4 View (android.view.View)4 AdapterView (android.widget.AdapterView)4 SearchView (androidx.appcompat.widget.SearchView)4 Bundle (android.os.Bundle)3 ListView (android.widget.ListView)3 TextView (android.widget.TextView)3 IntegerDialog (com.ichi2.anki.dialogs.IntegerDialog)3 SimpleMessageDialog (com.ichi2.anki.dialogs.SimpleMessageDialog)3 Consts (com.ichi2.libanki.Consts)3