fix: ensure MP3 controls show after loading MP3/JSON pair

This commit is contained in:
dave 2025-04-08 17:31:01 +03:00
parent babf28e77c
commit c22a20b2c8

@ -520,20 +520,22 @@ class MainViewModel(
} }
private fun handlePlayText() { private fun handlePlayText() {
Timber.d("handlePlayText called.")
viewModelScope.launch { viewModelScope.launch {
// Decide which text to speak: prioritize loaded doc, then user input // --- ADD CHECK: Do not start TTS if an MP3 is loaded ---
val textToSpeak = when { if (_currentMp3Uri.value != null) {
currentPageText.value.isNotEmpty() -> currentPageText.value Timber.w("handlePlayText: MP3 URI is loaded ($_currentMp3Uri.value). Skipping TTS playback.")
fullDocumentText.value.isNotEmpty() -> fullDocumentText.value return@launch
userInputText.value.isNotEmpty() -> userInputText.value
else -> {
Timber.w("PlayText action called but no text available (document or input).")
return@launch
}
} }
// --- END CHECK ---
Timber.d("handlePlayText: Speaking text starting with: '${textToSpeak.take(50)}...'") val textToSpeak = getCurrentDocumentStateUseCase.currentPageText.value
speakTextUseCase(textToSpeak) if (!textToSpeak.isNullOrBlank()) {
Timber.d("Speaking current page text: '${textToSpeak.take(50)}...'")
speakTextUseCase(textToSpeak)
} else {
Timber.w("PlayText action called but no text available (document or input).")
}
} }
} }
@ -1082,6 +1084,11 @@ class MainViewModel(
processDocumentUseCase.processText(reconstructedText) processDocumentUseCase.processText(reconstructedText)
// State should now be updated in the repository, triggering UI updates // State should now be updated in the repository, triggering UI updates
_processingStatus.value = PdfProcessingStatus.READY_TO_PLAY // Use the READY state _processingStatus.value = PdfProcessingStatus.READY_TO_PLAY // Use the READY state
// *** ADDED: Set the current MP3 URI state ***
_currentMp3Uri.value = mp3Uri
// *** END ADDED ***
Timber.d("Document state updated via use case. Attempting to play MP3: $mp3Uri") Timber.d("Document state updated via use case. Attempting to play MP3: $mp3Uri")
playMp3UseCase(mp3Uri) // Play after state is set playMp3UseCase(mp3Uri) // Play after state is set
} catch (processError: Exception) { } catch (processError: Exception) {