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 #5455: Resolve crash in AudioViewModel by initializing state variables #5561

Merged
merged 18 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
164 changes: 0 additions & 164 deletions .idea/codeStyles/Project.xml
adhiamboperes marked this conversation as resolved.
Outdated
Show resolved Hide resolved
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class AudioViewModel @Inject constructor(
}

fun loadMainContentAudio(allowAutoPlay: Boolean, reloadingContent: Boolean) {
setStateAndExplorationId(state, explorationId)
hasFeedback = false
loadAudio(contentId = null, allowAutoPlay, reloadingContent)
}
Expand All @@ -88,7 +89,12 @@ class AudioViewModel @Inject constructor(
* @param allowAutoPlay If false, audio is guaranteed not to be autoPlayed.
*/
private fun loadAudio(contentId: String?, allowAutoPlay: Boolean, reloadingMainContent: Boolean) {
val targetContentId = contentId ?: state.content.contentId
val targetContentId = when {
!contentId.isNullOrEmpty() -> contentId
this::state.isInitialized -> state.content.contentId
else -> ""
}

val voiceoverMapping =
state.recordedVoiceoversMap[targetContentId] ?: VoiceoverMapping.getDefaultInstance()

Expand All @@ -106,10 +112,9 @@ class AudioViewModel @Inject constructor(
selectedLanguageName.set(locale.getDisplayLanguage(locale))

when {
selectedLanguageCode.isEmpty() && languages.any {
it == defaultLanguage
} -> setAudioLanguageCode(defaultLanguage)
languages.any { it == selectedLanguageCode } -> setAudioLanguageCode(selectedLanguageCode)
selectedLanguageCode.isEmpty() && languages.contains(defaultLanguage) ->
setAudioLanguageCode(defaultLanguage)
languages.contains(selectedLanguageCode) -> setAudioLanguageCode(selectedLanguageCode)
languages.isNotEmpty() -> {
autoPlay = false
this.reloadingMainContent = false
Expand Down
Loading
Loading