Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,16 @@ class ManageNotetypes : AnkiActivity(R.layout.activity_manage_note_types) {
waitForPositiveButton = false,
displayKeyboard = true,
callback = { dialog, text ->
val textInputLayout = dialog.findViewById<com.google.android.material.textfield.TextInputLayout>(R.id.dialog_text_input_layout)
val isNotADuplicate =
!allNotetypes.map { it.name }.contains(text.toString())

if (!isNotADuplicate && text.isNotEmpty()) {
textInputLayout?.error = getString(R.string.note_type_already_exists)
} else {
textInputLayout?.error = null
}

dialog.positiveButton.isEnabled = text.isNotEmpty() && isNotADuplicate
},
)
Expand Down
3 changes: 2 additions & 1 deletion AnkiDroid/src/main/res/layout/dialog_generic_text_input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
android:paddingEnd="32dp"
android:paddingBottom="4dp"
app:errorEnabled="true"
android:paddingTop="16dp">
android:paddingTop="16dp"
android:hint="@string/name">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/dialog_text_input"
Expand Down
2 changes: 2 additions & 0 deletions AnkiDroid/src/main/res/values/03-dialogs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@

<string name="dialog_cancel">Cancel</string>
<string name="dialog_ok">OK</string>
<string name="name">Name</string>
<string name="note_type_already_exists">Note type already exists</string>
<string name="dialog_confirm" tools:ignore="UnusedResources">Confirm</string>
<string name="dialog_no">No</string>
<string name="dialog_yes">Yes</string>
Expand Down
Loading