Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get deck name using JS API #8500

Merged
merged 2 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4098,6 +4098,11 @@ public boolean ankiIsInNightMode() {
@JavascriptInterface
public boolean ankiIsDisplayingAnswer() { return isDisplayingAnswer(); };

@JavascriptInterface
public String ankiGetDeckName() {
return Decks.basename(getCol().getDecks().get(mCurrentCard.getDid()).getString("name"));
}

@JavascriptInterface
public boolean ankiIsActiveNetworkMetered() {
try {
Expand Down
21 changes: 21 additions & 0 deletions AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,27 @@ public void baseDeckName() {
assertThat(reviewer.getSupportActionBar().getTitle(), is("B"));
}

@Test
public void jsAnkiGetDeckName() {
Collection col = getCol();
Models models = col.getModels();
Decks decks = col.getDecks();

Long didAb = addDeck("A::B");
Model basic = models.byName(AnkiDroidApp.getAppResources().getString(R.string.basic_model_name));
basic.put("did", didAb);
addNoteUsingBasicModel("foo", "bar");

Long didA = addDeck("A");
decks.select(didA);

Reviewer reviewer = startReviewer();
JavaScriptFunction javaScriptFunction = reviewer.javaScriptFunction();

waitForAsyncTasksToComplete();
assertThat(javaScriptFunction.ankiGetDeckName(), is("B"));
}

private void toggleWhiteboard(ReviewerForMenuItems reviewer) {
reviewer.toggleWhiteboard();

Expand Down