Skip to content

Commit

Permalink
add filtered deck option to browser
Browse files Browse the repository at this point in the history
  • Loading branch information
MorenoTropical committed Sep 2, 2024
1 parent 015b06f commit 7de9fe7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
*/
Expand Down
6 changes: 6 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/FilteredDeckOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions AnkiDroid/src/main/res/menu/card_browser.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@
android:title="@string/study_options"
ankidroid:showAsAction="never"/>

<item
android:id="@+id/action_create_filtered_deck"
ankidroid:showAsAction="never"
tools:title="Create filtered deck..."
/>

</menu>

0 comments on commit 7de9fe7

Please sign in to comment.