From 661c20401420289a51ec27effb13442d48c4fd3d Mon Sep 17 00:00:00 2001 From: Aryan171 <62366692+Aryan171@users.noreply.github.com> Date: Wed, 29 Oct 2025 23:47:00 +0530 Subject: [PATCH 1/5] feat(note-editor): Add EXTRA_NOTE_TYPE_ID constant A new `EXTRA_NOTE_TYPE_ID` constant is added to `NoteEditorFragment`. This allows passing the note type ID as an intent extra. --- AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt index fee01c57961b..72ead5a7c5c0 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt @@ -2986,6 +2986,7 @@ class NoteEditorFragment : const val RELOAD_REQUIRED_EXTRA_KEY = "reloadRequired" const val EXTRA_IMG_OCCLUSION = "image_uri" const val IN_CARD_BROWSER_ACTIVITY = "inCardBrowserActivity" + const val EXTRA_NOTE_TYPE_ID = "NOTE_TYPE_ID" // calling activity enum class NoteEditorCaller( From 5a88e2ef3c24688a9dd1294bb96131b84e1c0f3e Mon Sep 17 00:00:00 2001 From: Aryan171 <62366692+Aryan171@users.noreply.github.com> Date: Wed, 29 Oct 2025 23:48:01 +0530 Subject: [PATCH 2/5] feat(note-editor): Allow specifying note type when adding a note The `AddNote` launcher data class now includes an optional `noteTypeId` parameter. This allows callers to specify the desired note type when launching the NoteEditor to add a new note. --- .../main/java/com/ichi2/anki/noteeditor/NoteEditorLauncher.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/noteeditor/NoteEditorLauncher.kt b/AnkiDroid/src/main/java/com/ichi2/anki/noteeditor/NoteEditorLauncher.kt index c3941d33372f..dbdc0ce249b3 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/noteeditor/NoteEditorLauncher.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/noteeditor/NoteEditorLauncher.kt @@ -207,12 +207,14 @@ sealed interface NoteEditorLauncher : Destination { val deckId: DeckId, val fieldsText: String, val tags: List? = null, + val noteTypeId: Long? = null, ) : NoteEditorLauncher { override fun toBundle(): Bundle = bundleOf( NoteEditorFragment.EXTRA_CALLER to NoteEditorCaller.NOTEEDITOR.value, NoteEditorFragment.EXTRA_DID to deckId, NoteEditorFragment.EXTRA_CONTENTS to fieldsText, + NoteEditorFragment.EXTRA_NOTE_TYPE_ID to noteTypeId, ).also { bundle -> tags?.let { tags -> bundle.putStringArray(NoteEditorFragment.EXTRA_TAGS, tags.toTypedArray()) } } From 0f02bd7f70799f1fee388f0456973cce3b730c33 Mon Sep 17 00:00:00 2001 From: Aryan171 <62366692+Aryan171@users.noreply.github.com> Date: Wed, 29 Oct 2025 23:50:18 +0530 Subject: [PATCH 3/5] feat(note-editor): Set note type when adding a new note Allow the note type to be specified via `EXTRA_NOTE_TYPE_ID` when creating a new note. If a valid `noteTypeId` is provided, the NoteEditor will pre-select the corresponding note type from the spinner. If no ID is provided or the ID is invalid, it defaults to the first available note type. --- .../java/com/ichi2/anki/NoteEditorFragment.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt index 72ead5a7c5c0..16910acf6354 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt @@ -842,6 +842,27 @@ class NoteEditorFragment : if (addNote) { noteTypeSpinner!!.onItemSelectedListener = SetNoteTypeListener() requireAnkiActivity().setToolbarTitle(R.string.menu_add) + + // set the note type + val noteTypeId: Long? = + if (!allNoteTypeIds.isNullOrEmpty()) { + requireArguments().getLong( + EXTRA_NOTE_TYPE_ID, + allNoteTypeIds!![0], + ) + } else { + null + } + val noteTypeIdIndex: Int = + if (noteTypeId != null && !allNoteTypeIds.isNullOrEmpty()) { + allNoteTypeIds!!.indexOfFirst { it == noteTypeId }.let { + if (it == -1) 0 else it + } + } else { + 0 + } + noteTypeSpinner!!.setSelection(noteTypeIdIndex) + // set information transferred by intent var contents: String? = null val tags = requireArguments().getStringArray(EXTRA_TAGS) From cb706e859ffad2f30bd81e4f41c99b3a7125f1c9 Mon Sep 17 00:00:00 2001 From: Aryan171 <62366692+Aryan171@users.noreply.github.com> Date: Thu, 30 Oct 2025 00:20:01 +0530 Subject: [PATCH 4/5] feat(note-editor): specify note type when copying note When copying a note, the current note's type ID is now explicitly passed to the new NoteEditor instance. This ensures the copied note correctly defaults to the same type as the original. --- .../src/main/java/com/ichi2/anki/NoteEditorFragment.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt index 16910acf6354..9d30af0b4bd0 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt @@ -1592,7 +1592,14 @@ class NoteEditorFragment : } fun copyNote() { - launchNoteEditor(NoteEditorLauncher.CopyNote(deckId, fieldsText, selectedTags)) { } + val noteTypeId = + if (currentlySelectedNotetype != null) { + currentlySelectedNotetype!!.id + } else { + editorNote?.notetype?.id + } + + launchNoteEditor(NoteEditorLauncher.CopyNote(deckId, fieldsText, selectedTags, noteTypeId)) { } } private fun launchNoteEditor( From a004f546866ccd4aa67aa22c7ba5388c8fc4dd2e Mon Sep 17 00:00:00 2001 From: Aryan171 <62366692+Aryan171@users.noreply.github.com> Date: Thu, 30 Oct 2025 02:48:39 +0530 Subject: [PATCH 5/5] test(NoteEditor): Use `setCurrentlySelectedNoteType` in builder The `col.notetypes.setCurrent()` call was replaced with the more appropriate `noteEditor.setCurrentlySelectedNoteType()` to set the notetype in the `NoteEditorFragment` test builder. An `advanceRobolectricLooper()` call was added to ensure the UI updates correctly after setting the notetype. --- AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorTest.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorTest.kt index 0bcf69b9e9db..c9d6f58385c5 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorTest.kt @@ -635,9 +635,10 @@ class NoteEditorTest : RobolectricTest() { } fun buildInternal(): NoteEditorFragment { - col.notetypes.setCurrent(notetype) val noteEditor = getNoteEditorAddingNote(REVIEWER) advanceRobolectricLooper() + noteEditor.setCurrentlySelectedNoteType(notetype.id) + advanceRobolectricLooper() // image occlusion does not need a first field if (this.firstField != null) { noteEditor.setFieldValueFromUi(0, firstField)