An open attachment menu adds media to the wrong field after a field reorder
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with the proposed test in AnkiDroid/src/test/java/com/ichi2/anki/StaleAttachmentSheetTest.kt, which reorders fields via notetypes.changeNotetypeOfNotes and then records an attachment through MultimediaBottomSheet. Trace how MultimediaArgsStorage gets the field index when the sheet was opened before the reorder. Done when the test passes and the recording targets the Back field at index 0 after the reorder.
Written by the indexing model from the issue text.
Description
Assisted-by: GPT-6.2-Sol xhigh & GPT-6.1-Sol xhigh & GPT-6.2-Astra xhigh
[EXISTING] An open attachment menu adds media to the wrong field after a field reorder
Subject: [EXISTING] An open attachment menu adds media to the wrong field after a field reorder
If the note's fields are reordered while its attachment menu is open, the menu's choices still target the field's old position.
⚠️ This issue existed before the PR and should likely be split off into a separate issue.
---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/StaleAttachmentSheetTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/StaleAttachmentSheetTest.kt
new file mode 100644
index 0000000000..37ccaa0010
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/StaleAttachmentSheetTest.kt
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki
+
+import android.view.View
+import androidx.core.view.allViews
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import anki.notetypes.copy
+import com.ichi2.anki.CollectionManager.withCol
+import com.ichi2.anki.compat.CompatHelper.Companion.getSerializableExtraCompat
+import com.ichi2.anki.multimedia.MultimediaActivity
+import com.ichi2.anki.multimedia.MultimediaArgsStorage
+import com.ichi2.anki.multimedia.MultimediaBottomSheet
+import com.ichi2.testutils.withSplitPaneUiAsync
+import kotlinx.coroutines.test.runTest
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.equalTo
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.Shadows.shadowOf
+import java.io.File
+
+@RunWith(AndroidJUnit4::class)
+class StaleAttachmentSheetTest : RobolectricTest() {
+ @Test
+ fun `an open attachment sheet records for its field after a field reorder`() =
+ runTest {
+ withSplitPaneUiAsync {
+ ensureCollectionLoadIsSynchronous()
+ setCardBrowserFragmented(true)
+ val type = addStandardNoteType("Back first", arrayOf("Back", "Front"), "{{Front}}", "{{Back}}")
+ val note = addBasicNote("Question", "Answer")
+ val cardId = note.firstCard().id
+ val browser = getBrowserWithNotes(0)
+ browser.viewModel.setQuery("deck:Default", forceRefresh = true)
+ browser.waitForSearchResults()
+ advanceRobolectricLooper()
+ val editor = requireNotNull(browser.fragment)
+
+ editor
+ .requireView()
+ .allViews
+ .filterIsInstance<FieldEditLine>()
+ .elementAt(1)
+ .binding.mediaButton
+ .performClick()
+ advanceRobolectricLooper()
+ val sheet = browser.supportFragmentManager.findFragmentByTag("MultimediaBottomSheet") as MultimediaBottomSheet
+
+ withCol {
+ val target = notetypes.byName(type)!!.id
+ val input =
+ notetypes.changeNotetypeInfo(note.noteTypeId, target).input.copy {
+ noteIds.add(note.id)
+ newFields[0] = 1
+ newFields[1] = 0
+ newTemplates[0] = 0
+ }
+ notetypes.changeNotetypeOfNotes(input)
+ }
+ browser.viewModel.setQuery("deck:Default", forceRefresh = true)
+ browser.waitForSearchResults()
+ advanceRobolectricLooper()
+ assertThat("the current card is retained", editor.currentEditedCard!!.id, equalTo(cardId))
+ assertThat("Back moved to the first slot", editor.editFieldAt(0)!!.text.toString(), equalTo("Answer"))
+ assertThat("the Back attachment sheet remains open", sheet.dialog?.isShowing, equalTo(true))
+
+ sheet.requireView().findViewById<View>(R.id.multimedia_action_recording).performClick()
+ advanceRobolectricLooper()
+
+ val shadow = shadowOf(browser)
+ val intent = shadow.nextStartedActivityForResult?.intent ?: shadow.nextStartedActivity
+ val file = requireNotNull(requireNotNull(intent).getSerializableExtraCompat<File>(MultimediaActivity.EXTRA_FRAGMENT_ARGS))
+ val recordingFor = MultimediaArgsStorage.create(targetContext).read(file).index
+ assertThat("the recording is for Back, now the first field", recordingFor, equalTo(0))
+ }
+ }
+}
Originally posted by @david-allison in https://github.com/ankidroid/Anki-Android/pull/22885#pullrequestreview-6048356039
- Dominant language
- Kotlin
- Stars
- 12.3k
- Forks
- 3.1k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 311
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ankidroid/Anki-Android
-
code-scan
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
ankidroid/Anki-Android#23806 ·
Maintainers usually reply within 1 day
-
code-scan
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
ankidroid/Anki-Android#23798 ·
Maintainers usually reply within 1 day
-
Send troubleshooting report does nothing with Never but says it was sentPossibly taken @rishithareddychalla claimed this today. Opencode-scan
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
ankidroid/Anki-Android#23797 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
Browse rows that fail to load show as empty linesPossibly taken @rishithareddychalla claimed this today. Opencode-scan
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ankidroid/Anki-Android#23786 · 1 comment ·
Maintainers usually reply within 1 day
-
The note editor's Cards button shows card type names as HTMLPossibly taken @rishithareddychalla claimed this today. Opencode-scan
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
ankidroid/Anki-Android#23756 · 1 comment ·
Maintainers usually reply within 1 day
All issues in ankidroid/Anki-Android
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Remove Collect againOpen
Difficulty 1/5 1-3 hours Newbie friendliness 86/100
thisisartman/Meguri#211 ·
Maintainers usually reply within 1 day
-
follow-up
Difficulty 1/5 Under an hour Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Bug: Paused screen is never cleared, so spans and logs keep the previous fragment's screen nameOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
open-telemetry/opentelemetry-android#2309 ·
Maintainers usually reply within 1 day
-
📦 expo-location Android contributor: external needs review sdk-58 severity: medium
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day