From 7de9fe7ed3465ced7b6a56d872926b7c2417343b Mon Sep 17 00:00:00 2001 From: MorenoTropical <154519856+morenotropical@users.noreply.github.com> Date: Sun, 1 Sep 2024 07:43:10 -0300 Subject: [PATCH] add filtered deck option to browser --- .../main/java/com/ichi2/anki/CardBrowser.kt | 19 +++++++++++++++++++ .../com/ichi2/anki/FilteredDeckOptions.kt | 6 ++++++ AnkiDroid/src/main/res/menu/card_browser.xml | 6 ++++++ 3 files changed, 31 insertions(+) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt b/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt index 186682d07eab..5be691df8f7d 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt @@ -77,6 +77,7 @@ import com.ichi2.anki.dialogs.CardBrowserMySearchesDialog import com.ichi2.anki.dialogs.CardBrowserMySearchesDialog.Companion.newInstance import com.ichi2.anki.dialogs.CardBrowserMySearchesDialog.MySearchesDialogListener import com.ichi2.anki.dialogs.CardBrowserOrderDialog +import com.ichi2.anki.dialogs.CreateDeckDialog import com.ichi2.anki.dialogs.DeckSelectionDialog import com.ichi2.anki.dialogs.DeckSelectionDialog.Companion.newInstance import com.ichi2.anki.dialogs.DeckSelectionDialog.DeckSelectionListener @@ -927,6 +928,7 @@ open class CardBrowser : subMenu -> setupFlags(subMenu, Mode.SINGLE_SELECT) } + menu.findItem(R.id.action_create_filtered_deck).title = TR.qtMiscCreateFilteredDeck() saveSearchItem = menu.findItem(R.id.action_save_search) saveSearchItem?.isVisible = false // the searchview's query always starts empty. mySearchesItem = menu.findItem(R.id.action_list_my_searches) @@ -1251,10 +1253,27 @@ open class CardBrowser : R.id.action_export_selected -> { exportSelected() } + R.id.action_create_filtered_deck -> { + showCreateFilteredDeckDialog() + } } return super.onOptionsItemSelected(item) } + private fun showCreateFilteredDeckDialog() { + val dialog = CreateDeckDialog(this, R.string.new_deck, CreateDeckDialog.DeckDialogType.FILTERED_DECK, null) + dialog.onNewDeckCreated = { + val intent = Intent(this, FilteredDeckOptions::class.java) + intent.putExtra("search", viewModel.searchTerms) + startActivity(intent) + } + launchCatchingTask { + withProgress { + dialog.showFilteredDeckDialog() + } + } + } + /** * @see CardBrowserViewModel.searchForSuspendedCards */ diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/FilteredDeckOptions.kt b/AnkiDroid/src/main/java/com/ichi2/anki/FilteredDeckOptions.kt index e4e2489d53aa..02b70ea6b37b 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/FilteredDeckOptions.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/FilteredDeckOptions.kt @@ -26,6 +26,7 @@ import android.preference.EditTextPreference import android.preference.ListPreference import android.preference.Preference import android.preference.PreferenceCategory +import androidx.core.content.edit import com.ichi2.anki.analytics.UsageAnalytics import com.ichi2.annotations.NeedsTest import com.ichi2.libanki.Collection @@ -222,6 +223,11 @@ class FilteredDeckOptions : } else { pref = DeckPreferenceHack() pref.registerOnSharedPreferenceChangeListener(this) + extras?.getString("search")?.let { search -> + pref.edit { + putString("search", search) + } + } addPreferences(col) buildLists() updateSummaries() diff --git a/AnkiDroid/src/main/res/menu/card_browser.xml b/AnkiDroid/src/main/res/menu/card_browser.xml index 750f60a2993c..56cec25b9b3f 100644 --- a/AnkiDroid/src/main/res/menu/card_browser.xml +++ b/AnkiDroid/src/main/res/menu/card_browser.xml @@ -63,4 +63,10 @@ android:title="@string/study_options" ankidroid:showAsAction="never"/> + + \ No newline at end of file