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

JS API to open card browser and search with query #9247

Merged
merged 1 commit into from
Aug 5, 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 @@ -4221,6 +4221,17 @@ public void ankiAddTagToCard() {
runOnUiThread(() -> showTagsDialog());
}

@JavascriptInterface
public void ankiSearchCard(String query) {
Intent intent = new Intent(AbstractFlashcardViewer.this, CardBrowser.class);
Long currentCardId = getCurrentCardId();
if (currentCardId != null) {
intent.putExtra("currentCard", currentCardId);
}
intent.putExtra("search_query", query);
startActivityForResultWithAnimation(intent, REQUEST_BROWSE_CARDS, START);
}

@JavascriptInterface
public boolean ankiIsActiveNetworkMetered() {
try {
Expand Down
6 changes: 6 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,12 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.card_browser);
initNavigationDrawer(findViewById(android.R.id.content));
startLoadingCollection();

// for intent coming from search query js api
if (getIntent().getStringExtra("search_query") != null) {
mSearchTerms = getIntent().getStringExtra("search_query");
searchCards();
}
}


Expand Down