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 Auto Advance waiting for audio when autoplay is disabled #17974

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jradchaima
Copy link
Contributor

@jradchaima jradchaima commented Feb 13, 2025

Purpose / Description

Auto Advance does not work when both "Don't play audio automatically" and "Wait for audio" are enabled

Fixes

Approach

TheFile Abstractflashcardviewer.k contain automaticAnswerShouldWaitForAudio() function
https://github.com/ankidroid/Anki-Android/blob/main/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.kt#L1309-L1312
this function only checks "Wait for audio" but ignores autoplay, which means Auto Advance might still wait even if autoplay is disabled.Since this function doesn’t check autoplay, we need to fix it so Auto Advance behaves correctly.

suspend fun automaticAnswerShouldWaitForAudio(): Boolean = withCol {
    val card = currentCard ?: return@withCol false  // Prevents null crash
    val waitForAudio = decks.configDictForDeckId(card.did).waitForAudio
    val soundConfig = CardSoundConfig.create(this, card)  // Fetch autoplay setting

    return@withCol waitForAudio && soundConfig.autoplay  //  Only wait if autoplay is enabled
}

Since ReviewerViewModel.kt does not inherit from AbstractFlashcardViewer.kt, we need a reference to an instance of AbstractFlashcardViewer.then call the function through flashcardViewer

suspend fun shouldWaitForAudio(): Boolean {
    return flashcardViewer?.automaticAnswerShouldWaitForAudio() ?: false
}

then Modify AutoAdvance.kt so it correctly calls shouldWaitForAudio() from ReviewerViewModel.kt

suspend fun shouldWaitForAudio(): Boolean {
    return viewModel.shouldWaitForAudio()  
}

How Has This Been Tested?

Instructions to reprodruce
1-(Optional) Confirm that "Auto Advance" feature is working in the selected deck in Reviewer
2-Long-press the deck in the main screen > "Deck options" >
"Audio" > set "Don't play audio automatically" enabled
(It is set to disabled by default)
3-"Auto Advance" > set "Wait for audio" enabled
(It is already set to enabled by default)
4-Tap "Save"
5-Tap the deck to open Reviewer
verfication:AutoAdvance behaves correctly

ankidroid.mp4

tested on android device samsung

Learning (optional, can help others)

Describe the research stage

Links to blog posts, patterns, libraries or addons used to solve this problem

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@BrayanDSO BrayanDSO added the Needs Author Reply Waiting for a reply from the original author label Feb 13, 2025
@BrayanDSO BrayanDSO marked this pull request as draft February 13, 2025 23:53
@jradchaima
Copy link
Contributor Author

Hi,
I removed the unnecessary code that I added to AutoAdvance.kt and ReviewerViewModel.kt, and tested auto-advance when both 'Don't play audio automatically' and 'Wait for audio' are enabled. It works fine

@BrayanDSO BrayanDSO marked this pull request as ready for review February 15, 2025 20:38
@BrayanDSO BrayanDSO added Needs Review and removed Needs Author Reply Waiting for a reply from the original author labels Feb 15, 2025
@BrayanDSO BrayanDSO added the Needs Author Reply Waiting for a reply from the original author label Feb 15, 2025
Co-authored-by: Brayan Oliveira <69634269+BrayanDSO@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Author Reply Waiting for a reply from the original author Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto Advance does not work when both "Don't play audio automatically" and "Wait for audio" are enabled
2 participants