From 12f24b93a16d1ad2313a79d14b47d290ce7d486c Mon Sep 17 00:00:00 2001 From: Mani <12841290+infinyte7@users.noreply.github.com> Date: Fri, 6 Aug 2021 04:02:45 +0800 Subject: [PATCH] js api to search card --- .../java/com/ichi2/anki/AbstractFlashcardViewer.java | 11 +++++++++++ .../src/main/java/com/ichi2/anki/CardBrowser.java | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java b/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java index 7640c57b4256..8bda5898a17d 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java +++ b/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java @@ -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 { diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.java b/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.java index 6d0ec45a67b8..8f9f900c20af 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.java +++ b/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.java @@ -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(); + } }