Search in sources :

Example 1 with CURRENT_DECK

use of com.ichi2.libanki.Decks.CURRENT_DECK in project Anki-Android by ankidroid.

the class Decks method select.

/**
 * {@inheritDoc}
 */
@Override
public void select(long did) {
    String name = mDecks.get(did).getString("name");
    // current deck
    mCol.set_config(CURRENT_DECK, did);
    // and active decks (current + all children)
    // Note: TreeMap is already sorted
    TreeMap<String, Long> actv = children(did);
    actv.put(name, did);
    JSONArray activeDecks = new JSONArray();
    for (Long n : actv.values()) {
        activeDecks.put(n);
    }
    mCol.set_config(ACTIVE_DECKS, activeDecks);
}
Also used : JSONArray(com.ichi2.utils.JSONArray)

Example 2 with CURRENT_DECK

use of com.ichi2.libanki.Decks.CURRENT_DECK in project Anki-Android by ankidroid.

the class NoteEditorTest method copyNoteCopiesDeckId.

@Test
public void copyNoteCopiesDeckId() {
    // value returned if deck not found
    final int DECK_ID_NOT_FOUND = -404;
    long currentDid = addDeck("Basic::Test");
    getCol().set_config(CURRENT_DECK, currentDid);
    Note n = super.addNoteUsingBasicModel("Test", "Note");
    n.model().put("did", currentDid);
    NoteEditor editor = getNoteEditorEditingExistingBasicNote("Test", "Note", FromScreen.DECK_LIST);
    // Change DID if going through default path
    getCol().set_config(CURRENT_DECK, Consts.DEFAULT_DECK_ID);
    Intent copyNoteIntent = getCopyNoteIntent(editor);
    NoteEditor newNoteEditor = super.startActivityNormallyOpenCollectionWithIntent(NoteEditor.class, copyNoteIntent);
    assertThat("Selected deck ID should be the current deck id", editor.getDeckId(), is(currentDid));
    assertThat("Deck ID in the intent should be the selected deck id", copyNoteIntent.getLongExtra(NoteEditor.EXTRA_DID, DECK_ID_NOT_FOUND), is(currentDid));
    assertThat("Deck ID in the new note should be the ID provided in the intent", newNoteEditor.getDeckId(), is(currentDid));
}
Also used : Note(com.ichi2.libanki.Note) Intent(android.content.Intent) Test(org.junit.Test)

Aggregations

Intent (android.content.Intent)1 Note (com.ichi2.libanki.Note)1 JSONArray (com.ichi2.utils.JSONArray)1 Test (org.junit.Test)1