From 08887a7e245ae7a1bd3a9df6c61d9f24a457320a Mon Sep 17 00:00:00 2001 From: David Allison <62114487+david-allison-1@users.noreply.github.com> Date: Thu, 21 Oct 2021 03:12:00 +0100 Subject: [PATCH] fix: automatic answer if TTS = "don't speak" The supplied listener wasn't called if the TTS wasn't invoked We reorder saving to metaDB in case the automatic display answer were blocking We return from `textToSpeech`: we couldn't call the listener from there as it's called in a loop and would call the listener multiple times Fixes 9170 --- .../src/main/java/com/ichi2/anki/ReadText.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/ReadText.java b/AnkiDroid/src/main/java/com/ichi2/anki/ReadText.java index 7ea6cf9533..036afed33b 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/ReadText.java +++ b/AnkiDroid/src/main/java/com/ichi2/anki/ReadText.java @@ -122,10 +122,12 @@ public class ReadText { .itemsCallback((materialDialog, view, which, charSequence) -> { String locale = dialogIds.get(which); Timber.d("ReadText.selectTts() user chose locale '%s'", locale); + MetaDB.storeLanguage(mReviewer.get(), mDid, mOrd, mQuestionAnswer, locale); if (!locale.equals(NO_TTS)) { speak(mTextToSpeak, locale, TextToSpeech.QUEUE_FLUSH); + } else { + mCompletionListener.onDone(qa); } - MetaDB.storeLanguage(mReviewer.get(), mDid, mOrd, mQuestionAnswer, locale); }); } // Show the dialog after short delay so that user gets a chance to preview the card @@ -163,11 +165,10 @@ public class ReadText { continue; } - textToSpeech(textToRead.getText(), did, ord, cardSide, + playedSound |= textToSpeech(textToRead.getText(), did, ord, cardSide, textToRead.getLocaleCode(), isFirstText ? TextToSpeech.QUEUE_FLUSH : TextToSpeech.QUEUE_ADD); isFirstText = false; - playedSound = true; } // if we didn't play a sound, call the completion listener if (!playedSound) { @@ -191,8 +192,9 @@ public class ReadText { * available. * * @param queueMode TextToSpeech.QUEUE_ADD or TextToSpeech.QUEUE_FLUSH. + * @return false if a sound was not played */ - private static void textToSpeech(String text, long did, int ord, Sound.SoundSide qa, String localeCode, + private static boolean textToSpeech(String text, long did, int ord, Sound.SoundSide qa, String localeCode, int queueMode) { mTextToSpeak = text; mQuestionAnswer = qa; @@ -215,11 +217,11 @@ public class ReadText { if (localeCode.equals(NO_TTS)) { // user has chosen not to read the text - return; + return false; } if (!localeCode.isEmpty() && isLanguageAvailable(localeCode)) { speak(mTextToSpeak, localeCode, queueMode); - return; + return true; } // Otherwise ask the user what language they want to use @@ -230,6 +232,7 @@ public class ReadText { + " (" + originalLocaleCode + ")", false); } selectTts(mTextToSpeak, mDid, mOrd, mQuestionAnswer); + return true; } /**