feat(card-browser): field selection dialog for advanced searches [DEV ONLY]#20491
Open
david-allison wants to merge 4 commits intoankidroid:mainfrom
Open
feat(card-browser): field selection dialog for advanced searches [DEV ONLY]#20491david-allison wants to merge 4 commits intoankidroid:mainfrom
david-allison wants to merge 4 commits intoankidroid:mainfrom
Conversation
Supports Advanced Search performing different actions based on what is selected Example: inserting fields Prep for issue 18709
Allows selection of a single field, returning the name via the Fragment Result API * This is a simple view over `InsertFieldDialog`, which I plan to heavily extend to handle special fields and field filters * PR 20041 * `ResultType` formalizes using the Fragment Result API bundle to switch on similar actions, without needing multiple listeners Part of issue 18709 Assisted-by: GPT-5 Mini - `ResultType` docs
`FieldSelectionDialog` is used to obtain the field selection, this returns the field name and a `ResultType`, which is then used to obtain the search string building logic from `AdvancedSearchFieldsTab` and builds the search string. Removed option: "Search a field with a space in the name" - "a field:text" `buildSearchString` handles adding quotes appropriately Building the search string was much more complex than expected. The Anki backend 'buildSearchString' converts text = '*text*' to '\*text\*' and there is no way to unescape this The fix I eventually settled on was to use placeholders in these special cases. This is mostly because field names with spaces wrapped the search in quotes, and it was risking a bug '!!BEFORE!!' and '!!AFTER!!' are placeholders The search logic for each tab was going to get complex, so I extracted the majority of the logic to a 'AdvancedSearchXTab' class I'm happy that this has kept `AdvancedSearchFragment` relatively lean, whilst extending the functionality Issue 18709 Builds on PR 20071
Member
Author
Collaborator
|
Instead of "text", why not place the cursor there so the user can immediately type the actual text? I prefer just "Select field" in the title since it makes it clearer that you're meant to select a field. Also, because of this dialog: UI design is tough
I looked at the material 3 guidelines for dialogs and they actually state that "headlines" are optional, but the supporting text and the button text are not?! To make it more confusing, Google Calendar has this dialog: and Gmail has this: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Purpose / Description
In #20071 I introduced an 'advanced search' feature in dev for the card browser. This PR improves this feature for the 'Fields' tab
Tapping any but the last option opens up a
FieldSelectionDialog, so we can replacefieldwith the field name. This also allows us to remove theSearch a field with a space in the nameoption, as we usebuildSearchStringto handle this case.Change to the search text after tapping
Fixes
Approach
OptionTypeto support extensionFieldSelectionDialog, which uses the Fragment Result API to communicateOptionType, add most of the logic which handles this inAdvancedSearchFieldsTab, and haveAdvancedSearchFragmentcoordinate between this and theFieldSelectionDialogFieldSelectionDialoghas a number of extension points which mean that it will differ fromInsertFieldDialogInsertFieldDialog
FieldSelectionDialog
How Has This Been Tested?
card_browser_fields.webm
Learning (optional, can help others)
Collection.buildSearchString
field = front; text = "*a*"returnsfront:\*a\*with no way to avoid escaping. Many of the strings which we are replacing use*, so this is hacked aroundhttps://docs.ankiweb.net/searching.html#limiting-to-a-field
Checklist