Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multimedia options opening more than once #17455

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ import com.ichi2.utils.positiveButton
import com.ichi2.utils.show
import com.ichi2.utils.title
import com.ichi2.widget.WidgetStatus
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import org.json.JSONArray
Expand Down Expand Up @@ -201,6 +202,8 @@ class NoteEditor : AnkiFragment(R.layout.note_editor), DeckSelectionListener, Su
private var isTagsEdited = false
private var isFieldEdited = false

private var multimediaActionJob: Job? = null

/**
* Flag which forces the calling activity to rebuild it's definition of current card from scratch
*/
Expand Down Expand Up @@ -1741,8 +1744,11 @@ class NoteEditor : AnkiFragment(R.layout.note_editor), DeckSelectionListener, Su
* @param fieldIndex the index of the field in the note where the multimedia content should be added
*/
private fun handleMultimediaActions(fieldIndex: Int) {
// Cancel any existing subscription to avoid duplicate listeners
multimediaActionJob?.cancel()

// Based on the type of multimedia action received, perform the corresponding operation
lifecycleScope.launch {
multimediaActionJob = lifecycleScope.launch {
val note: MultimediaEditableNote = getCurrentMultimediaEditableNote()
if (note.isEmpty) return@launch

Expand Down