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
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.oppia.android.app.player.audio

import android.util.Log
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
import androidx.databinding.ObservableBoolean
import androidx.databinding.ObservableField
import androidx.lifecycle.LiveData
Expand Down Expand Up @@ -66,11 +67,16 @@ class AudioViewModel @Inject constructor(
processPlayStatusLiveData()
}

fun setStateAndExplorationId(newState: State, id: String) {
fun setStateAndExplorationId(newState: State?, id: String?) {
if (newState == null || id == null) {
Log.e("AudioViewModel", "Failed to set state or id - parameters are null")
return
}
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
state = newState
explorationId = id
}


adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
fun loadMainContentAudio(allowAutoPlay: Boolean, reloadingContent: Boolean) {
hasFeedback = false
loadAudio(contentId = null, allowAutoPlay, reloadingContent)
Expand All @@ -88,6 +94,11 @@ class AudioViewModel @Inject constructor(
* @param allowAutoPlay If false, audio is guaranteed not to be autoPlayed.
*/
private fun loadAudio(contentId: String?, allowAutoPlay: Boolean, reloadingMainContent: Boolean) {
if (!::state.isInitialized || !::explorationId.isInitialized) {
Log.w("AudioViewModel", "Cannot load audio: state or explorationId is not initialized.")
return
}
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved

val targetContentId = contentId ?: state.content.contentId
val voiceoverMapping =
state.recordedVoiceoversMap[targetContentId] ?: VoiceoverMapping.getDefaultInstance()
Expand Down
Loading