Skip to content
Open
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
31 changes: 30 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1571,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(
Expand Down Expand Up @@ -2986,6 +3014,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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,14 @@ sealed interface NoteEditorLauncher : Destination {
val deckId: DeckId,
val fieldsText: String,
val tags: List<String>? = 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()) }
}
Expand Down
3 changes: 2 additions & 1 deletion AnkiDroid/src/test/java/com/ichi2/anki/NoteEditorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down