Search in sources :

Example 91 with DECK

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

the class CardTemplateEditor method onDeckSelected.

/**
 * When a deck is selected via Deck Override
 */
@Override
public void onDeckSelected(@Nullable SelectableDeck deck) {
    if (getTempModel().getModel().isCloze()) {
        Timber.w("Attempted to set deck for cloze model");
        UIUtils.showThemedToast(this, getString(R.string.multimedia_editor_something_wrong), true);
        return;
    }
    int ordinal = mViewPager.getCurrentItem();
    JSONObject template = getTempModel().getTemplate(ordinal);
    String templateName = template.getString("name");
    if (deck != null && Decks.isDynamic(getCol(), deck.getDeckId())) {
        Timber.w("Attempted to set default deck of %s to dynamic deck %s", templateName, deck.getName());
        UIUtils.showThemedToast(this, getString(R.string.multimedia_editor_something_wrong), true);
        return;
    }
    String message;
    if (deck == null) {
        Timber.i("Removing default template from template '%s'", templateName);
        template.put("did", JSONObject.NULL);
        message = getString(R.string.model_manager_deck_override_removed_message, templateName);
    } else {
        Timber.i("Setting template '%s' to '%s'", templateName, deck.getName());
        template.put("did", deck.getDeckId());
        message = getString(R.string.model_manager_deck_override_added_message, templateName, deck.getName());
    }
    UIUtils.showThemedToast(this, message, true);
    // Deck Override can change from "on" <-> "off"
    supportInvalidateOptionsMenu();
}
Also used : JSONObject(com.ichi2.utils.JSONObject)

Example 92 with DECK

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

the class CardBrowserTest method checkIfSearchAllDecksWorks.

@Test
public void checkIfSearchAllDecksWorks() {
    addNoteUsingBasicModel("Hello", "World");
    long deck = addDeck("Test Deck");
    getCol().getDecks().select(deck);
    Card c2 = addNoteUsingBasicModel("Front", "Back").firstCard();
    c2.setDid(deck);
    c2.flush();
    CardBrowser cardBrowser = getBrowserWithNoNewCards();
    cardBrowser.searchCards("Hello");
    advanceRobolectricLooperWithSleep();
    assertThat("Card browser should have Test Deck as the selected deck", cardBrowser.getSelectedDeckNameForUi(), is("Test Deck"));
    assertThat("Result should be empty", cardBrowser.getCardCount(), is(0));
    cardBrowser.searchAllDecks();
    advanceRobolectricLooperWithSleep();
    assertThat("Result should contain one card", cardBrowser.getCardCount(), is(1));
}
Also used : Card(com.ichi2.libanki.Card) Test(org.junit.Test)

Example 93 with DECK

use of com.ichi2.anki.CardBrowser.Column.DECK 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 94 with DECK

use of com.ichi2.anki.CardBrowser.Column.DECK 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 95 with DECK

use of com.ichi2.anki.CardBrowser.Column.DECK 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)

Aggregations

Deck (com.ichi2.libanki.Deck)100 Collection (com.ichi2.libanki.Collection)97 JSONObject (com.ichi2.utils.JSONObject)88 Test (org.junit.Test)80 JSONArray (com.ichi2.utils.JSONArray)55 Card (com.ichi2.libanki.Card)53 Note (com.ichi2.libanki.Note)50 ArrayList (java.util.ArrayList)47 RobolectricTest (com.ichi2.anki.RobolectricTest)44 DeckConfig (com.ichi2.libanki.DeckConfig)37 JSONException (com.ichi2.utils.JSONException)34 NonNull (androidx.annotation.NonNull)30 HashMap (java.util.HashMap)29 Model (com.ichi2.libanki.Model)23 Map (java.util.Map)22 Intent (android.content.Intent)21 Resources (android.content.res.Resources)18 TextView (android.widget.TextView)18 SharedPreferences (android.content.SharedPreferences)17 Cursor (android.database.Cursor)17