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();
}
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));
}
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");
}
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));
}
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.");
}
}
}
Aggregations