From 97e77a4cea030d500197d38af75754955a5de158 Mon Sep 17 00:00:00 2001 From: Prince kushwaha Date: Tue, 7 Nov 2023 17:19:02 +0530 Subject: [PATCH] Replaced Toast with Snackbar in ReadText.kt --- AnkiDroid/src/main/java/com/ichi2/anki/ReadText.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/ReadText.kt b/AnkiDroid/src/main/java/com/ichi2/anki/ReadText.kt index 02704583b004..c1bbd75086eb 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/ReadText.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/ReadText.kt @@ -243,6 +243,7 @@ object ReadText { // Store weak reference to Activity to prevent memory leak flashCardViewer = WeakReference(context) mCompletionListener = listener + val ankiActivityContext = context as? AnkiActivity // Create new TTS object and setup its onInit Listener textToSpeech = TextToSpeech(context) { status: Int -> if (status == TextToSpeech.SUCCESS) { @@ -251,7 +252,9 @@ object ReadText { Timber.d("TTS initialized and available languages found") (context as AbstractFlashcardViewer).ttsInitialized() } else { - showThemedToast(context, context.getString(R.string.no_tts_available_message), false) + if (ankiActivityContext != null) { + ankiActivityContext.showSnackbar(R.string.no_tts_available_message) + } Timber.w("TTS initialized but no available languages found") } textToSpeech!!.setOnUtteranceProgressListener(object : UtteranceProgressListener() { @@ -286,7 +289,9 @@ object ReadText { } } // Show toast that it's getting initialized, as it can take a while before the sound plays the first time - showThemedToast(context, context.getString(R.string.initializing_tts), false) + if (ankiActivityContext != null) { + ankiActivityContext.showSnackbar(R.string.initializing_tts) + } } fun errorToDeveloperString(errorCode: Int): String {