Skip to content

Enhance Add Note Type dialog styling and validation#20512

Merged
lukstbit merged 1 commit intoankidroid:mainfrom
Chaos10001:chaos
Mar 26, 2026
Merged

Enhance Add Note Type dialog styling and validation#20512
lukstbit merged 1 commit intoankidroid:mainfrom
Chaos10001:chaos

Conversation

@Chaos10001
Copy link
Copy Markdown
Contributor

@Chaos10001 Chaos10001 commented Mar 18, 2026

Purpose / Description

This PR modernizes the Add Note Type dialog by replacing outdated UI components with Material Design elements and introducing real-time validation. These changes provide immediate feedback to the user and align the dialog with modern Android design standards.

Fixes

Approach

Changes

  1. UI Modernization
    (i) Material Components: Replaced the standard EditText with TextInputLayout using the OutlinedBox style. This adds a professional border and a floating "Name" label.

(ii) Copy Updates: Changed dialog title from "Type" to "Add note type".
· Updated confirmation button from "OK" to "Add" for better intent clarity.

  1. Validation Logic & Feedback
    (i)Real-time Detection: Implemented an addTextChangedListener to compare user input against existing note type names.

(ii)Error Handling: Utilized TextInputLayout.setError() to trigger a red border and a "This note name already exists" message when a duplicate is detected.

(iii)State Management: The "Add" button is now dynamically disabled while a validation error is present.

How Has This Been Tested?

Device: Techno spark 30

Test Steps:

  1. Navigate to the Manage Note Types screen.

  2. Tap the + button to open the new dialog.

  3. Verification: Confirmed the title displays "Add note type".

  4. Duplicate Test: Entered an existing name (e.g., "Basic").
    · Result: Border turned red; error message appeared; "Add" button disabled.

  5. Unique Test: Entered a new, unique name.
    · Result: Error cleared; "Add" button enabled.

1000644839
1000644838

@github-actions
Copy link
Copy Markdown
Contributor

Important

Maintainers: This PR contains Strings changes

  1. Sync Translations before merging this PR and wait for the action to complete
  2. Review and merge the auto-generated PR in order to sync all user-submitted translations
  3. Sync Translations again and merge the PR so the huge automated string changes caused by merging this PR are by themselves and easy to review

@ZornHadNoChoice
Copy link
Copy Markdown
Collaborator

ZornHadNoChoice commented Mar 19, 2026

It's up to the maintainers to decide which PR to merge, but please read my comment here #20479 (comment) and additionally, reduce the vertical padding in the dialog.

Comment thread AnkiDroid/src/main/res/values/17-model-manager.xml Outdated
@david-allison
Copy link
Copy Markdown
Member

@Chaos10001
Copy link
Copy Markdown
Contributor Author

@david-allison Lint issue resolved

Copy link
Copy Markdown
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!!!!!

The padding of the dialog doesn't match the spec: https://m3.material.io/components/dialogs/specs

Please note my review comments on: #20479, s there may be additional useful context

All minor issues, should be good to get this in 👍

Comment thread AnkiDroid/src/main/java/com/ichi2/anki/notetype/AddNewNotesType.kt Outdated
Comment thread AnkiDroid/src/main/res/layout/dialog_new_note_type.xml Outdated
Comment thread AnkiDroid/src/main/res/values/03-dialogs.xml Outdated
Comment thread AnkiDroid/src/main/java/com/ichi2/anki/notetype/AddNewNotesType.kt Outdated
Comment thread AnkiDroid/src/main/res/values/03-dialogs.xml Outdated
<string name="model_field_editor_reposition_menu">Reposition field</string>
<string name="model_field_editor_changing">Updating fields</string>
<string name="model_field_editor_sort_field">Sort by this field</string>
<string name="model_editor_name">Name</string>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this generic, move it out the file and use name="name_prompt"

Copy link
Copy Markdown
Member

@david-allison david-allison Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unresolved

Comment thread AnkiDroid/src/main/res/values/17-model-manager.xml Outdated
Copy link
Copy Markdown
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, forgot to submit this.

A before/after screenshot would be great! Last round 🤞.

I'll get it over the finish line if it needs more, it's ALMOST done 👍

Comment thread AnkiDroid/src/main/res/values/sentence-case.xml Outdated
Comment thread AnkiDroid/src/main/res/values/03-dialogs.xml
Comment thread AnkiDroid/src/main/java/com/ichi2/anki/notetype/AddNewNotesType.kt Outdated
@Chaos10001
Copy link
Copy Markdown
Contributor Author

Before
563613066-6ff5ae78-fcb7-4ed8-86cf-49bb5db05bb4

After
1000659159
1000659158

Comment thread AnkiDroid/src/main/java/com/ichi2/anki/notetype/AddNewNotesType.kt Outdated
@david-allison
Copy link
Copy Markdown
Member

Last one I think!

Comment on lines +79 to +80
// Previously used inconsistent padding (32/64dp) that didn't follow the spec.
// See: https://m3.material.io/components/dialogs/specs
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the issue was that the padding wasn't applied?

If it's just inconsistent, it's best to fix it in the code, so the layout would work with other screen types

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@david-allison Yeah true as well, The padding wasn't applied - I changed the value multiple times and it wasn't reflecting on the UI

Copy link
Copy Markdown
Member

@david-allison david-allison Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you fix the comment, future devs would be confused if it remained.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

<string name="model_field_editor_reposition_menu">Reposition field</string>
<string name="model_field_editor_changing">Updating fields</string>
<string name="model_field_editor_sort_field">Sort by this field</string>
<string name="model_editor_name">Name</string>
Copy link
Copy Markdown
Member

@david-allison david-allison Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unresolved

@david-allison david-allison added Needs Second Approval Has one approval, one more approval to merge squash-merge A squash & force push is required. The PR author may do this to speed up the merge process. and removed Needs Review labels Mar 22, 2026
@Chaos10001
Copy link
Copy Markdown
Contributor Author

@lukstbit fixed merge conflict

@david-allison
Copy link
Copy Markdown
Member

david-allison commented Mar 24, 2026

Please rebase/squash next time, rather than adding in a merge commit. We rebase all commits to main, so want a clean history.

Copy link
Copy Markdown
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caught a potential issue while looking into this

setTitle(TR.notetypesAddNoteType())
customView(binding.root)
positiveButton(R.string.menu_add) { _ ->
val newName = binding.notetypeNewName.text.toString()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This no longer trims the input, why?

Please add a @NeedsTest annotation to the method if this was a bug

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that didn't come from my end though — it came from the merge conflict, I had to make a balance between the merged code and my code or else I did continue getting a merge conflict

Copy link
Copy Markdown
Member

@david-allison david-allison Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you reverted the merged code, which was correct

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will work on it and tag you once I made a push then

@lukstbit lukstbit added the Needs Author Reply Waiting for a reply from the original author label Mar 24, 2026
@lukstbit lukstbit changed the title ui: enhance Add Note Type dialog styling and validation Enhance Add Note Type dialog styling and validation Mar 24, 2026
@Chaos10001
Copy link
Copy Markdown
Contributor Author

@david-allison Pls review

@david-allison david-allison removed Needs Author Reply Waiting for a reply from the original author Needs Second Approval Has one approval, one more approval to merge labels Mar 25, 2026
Copy link
Copy Markdown
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers! Very minor fixup needed

Comment thread AnkiDroid/src/main/res/layout/dialog_new_note_type.xml Outdated
Comment thread AnkiDroid/src/main/res/layout/dialog_new_note_type.xml Outdated
@david-allison david-allison added the Needs Second Approval Has one approval, one more approval to merge label Mar 26, 2026
@Chaos10001
Copy link
Copy Markdown
Contributor Author

@david-allison Pls review

Copy link
Copy Markdown
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approved previously, but the code is great, congrats!!

Can't merge it yet due to conflicts. Please modify the git history (rebase + force push) so:

  • Merge commits are removed
  • Either:
    • commits are split out into rebaseable changes
    • there is 1 squashed commit
  • commits have a good title and description

Changes:
- improve dialog appearance by using a Material 3 outlined input box
- displays a visual error when a name that already exists is entered
by the user
- implements a sentence case for TR.notetypesAddNoteType() backend string
Copy link
Copy Markdown
Member

@lukstbit lukstbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing!

To get this in I pushed to:

  • fix conflicts
  • create a single commit
  • fix some of the issues I noticed when reviewing

How the dialog looks now:

Image

@lukstbit lukstbit added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Second Approval Has one approval, one more approval to merge squash-merge A squash & force push is required. The PR author may do this to speed up the merge process. labels Mar 26, 2026
@lukstbit lukstbit enabled auto-merge March 26, 2026 19:22
@lukstbit lukstbit added this pull request to the merge queue Mar 26, 2026
Merged via the queue into ankidroid:main with commit 4e2bd4a Mar 26, 2026
15 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

Maintainers: Please Sync Translations to produce a commit with only the automated changes from this PR.

Read more about updating strings on the wiki,

@github-actions github-actions Bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Mar 26, 2026
@github-actions github-actions Bot added this to the 2.24 release milestone Mar 26, 2026
@Chaos10001
Copy link
Copy Markdown
Contributor Author

@david-allison Thank you for the constant reviews and patiently pointing out mistakes i made - it was really rewarding and i gained alot from this little interaction between us

@lukstbit Thanks for the review and final merge - I will check the issues you fixed

Its really great working with you both, Hoping to contribute more to ankidroid, Cheers🥂

@david-allison
Copy link
Copy Markdown
Member

CONGRATS!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve the "Add note type" dialog

4 participants