diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/CreateDeckDialog.kt b/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/CreateDeckDialog.kt
index 715f55caa989..bc1ab2f2205d 100644
--- a/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/CreateDeckDialog.kt
+++ b/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/CreateDeckDialog.kt
@@ -26,10 +26,12 @@ import com.ichi2.anki.R
import com.ichi2.anki.UIUtils.showThemedToast
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.annotations.NeedsTest
+import com.ichi2.libanki.Collection
import com.ichi2.libanki.DeckId
import com.ichi2.libanki.Decks
import com.ichi2.libanki.getOrCreateFilteredDeck
import com.ichi2.utils.getInputField
+import com.ichi2.utils.getInputTextLayout
import com.ichi2.utils.input
import com.ichi2.utils.negativeButton
import com.ichi2.utils.positiveButton
@@ -94,12 +96,23 @@ class CreateDeckDialog(
dialog.positiveButton.isEnabled = false
return@input
}
+ if (deckExists(getColUnsafe, maybeDeckName)) {
+ dialog.getInputTextLayout().error = context.getString(R.string.deck_already_exists)
+ dialog.positiveButton.isEnabled = false
+ return@input
+ }
+ dialog.getInputTextLayout().error = null
dialog.positiveButton.isEnabled = true
}
shownDialog = dialog
return dialog
}
+ /**
+ * @return true if the collection contains a deck with the given name
+ */
+ private fun deckExists(col: Collection, name: String): Boolean = col.decks.byName(name) != null
+
/**
* Returns the fully qualified deck name for the provided input
* @param dialogText The user supplied text in the dialog
diff --git a/AnkiDroid/src/main/res/layout/dialog_generic_text_input.xml b/AnkiDroid/src/main/res/layout/dialog_generic_text_input.xml
index 4dca75848fb3..d826e579595d 100644
--- a/AnkiDroid/src/main/res/layout/dialog_generic_text_input.xml
+++ b/AnkiDroid/src/main/res/layout/dialog_generic_text_input.xml
@@ -15,8 +15,8 @@
-->
-
+ app:errorEnabled="true"
+ android:paddingTop="16dp">
-
\ No newline at end of file
+
diff --git a/AnkiDroid/src/main/res/values/03-dialogs.xml b/AnkiDroid/src/main/res/values/03-dialogs.xml
index ab5af6b92fcf..6fc976a43808 100644
--- a/AnkiDroid/src/main/res/values/03-dialogs.xml
+++ b/AnkiDroid/src/main/res/values/03-dialogs.xml
@@ -259,4 +259,6 @@
Due to Android privacy changes, your data and automated backups will be inaccessible if the app is uninstalled
+ Deck already exists
+