fix: Show red text if the tag already exists and disable the button#20368
fix: Show red text if the tag already exists and disable the button#20368PrathamDevX wants to merge 2 commits intoankidroid:mainfrom
Conversation
|
First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible. |
|
Important Maintainers: This PR contains Strings changes
|
|
|
||
| addTag(input.toString()) | ||
| d?.dismiss() | ||
| } | ||
|
|
||
| val inputET = addTagDialog.getInputField() | ||
|
|
||
| inputET.filters = arrayOf(addTagFilter) |
There was a problem hiding this comment.
Thanks for pointing this out.
There was a problem hiding this comment.
The changes are not done yet
| inputET.filters = arrayOf(addTagFilter) | ||
|
|
||
| if (!prefixTag.isNullOrEmpty()) { | ||
| // utilize the addTagFilter to append '::' properly by appending a space to prefixTag |
There was a problem hiding this comment.
Why removing the comment?
There was a problem hiding this comment.
Sorry, that wasn’t intentional. I’ll add it back.
| // SAFE WAY TO FIND TextInputLayout | ||
| val textInputLayout = | ||
| generateSequence(inputET.parent) { (it as? View)?.parent } | ||
| .filterIsInstance<com.google.android.material.textfield.TextInputLayout>() | ||
| .firstOrNull() |
There was a problem hiding this comment.
How is this a safe way? Can you explain
There was a problem hiding this comment.
I used this approach to search up the view hierarchy for TextInputLayout instead of assuming a fixed parent. I called it “safe” in that sense, but I understand it still depends on the current layout structure. I can adjust the wording or simplify the approach if needed.
There was a problem hiding this comment.
I’ve made the requested changes in the latest commit.
| <string name="dyn_deck_desc">This is a special deck for studying outside of the normal schedule. Cards will be automatically returned to their original decks after you review them. Deleting this deck from the deck list will return all remaining cards to their original deck.</string> | ||
| <string name="tag_editor_add_feedback">Touch “%2$s” to confirm adding “%1$s”</string> | ||
| <string name="tag_editor_add_feedback_existing">Existing tag “%1$s” selected</string> | ||
| <string name="tag_already_exists">Tag "%1$s" already exists</string> |
There was a problem hiding this comment.
Can be generic doesn't need to have the tag name in the string
There was a problem hiding this comment.
Ok, I will change it to generic.
criticalAY
left a comment
There was a problem hiding this comment.
Changes are not reverted
Purpose / Description
The PR fixes the issue where adding an already existing tag does not provide proper validation feedback.
Now the Add Tag dialog shows a red error message and disables the OK button when a duplicate tag is entered.
Fixes
Approach
Added validation in
TagsDialog.ktto check whether the entered tag already exists.TagsUtil.getUniformedTag()How Has This Been Tested?
Ran the app and verified that when entering an existing tag in the Add Tag dialog, a red error message is displayed and the OK button remains disabled.
Also verified that entering a new unique tag enables the OK button and allows the tag to be added successfully.
before:

after:

Learning (optional, can help others)
None
Links to blog posts, patterns, libraries or addons used to solve this problem
Checklist