Skip to content

Commit

Permalink
js api to search card
Browse files Browse the repository at this point in the history
  • Loading branch information
krmanik authored and mikehardy committed Aug 5, 2021
1 parent 2ac3e80 commit 12f24b9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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

0 comments on commit 12f24b9

Please sign in to comment.