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 #5657: Handle App Crash When Changing to Landscape After Interacting with Previous Responses #5680

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
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
import androidx.databinding.ObservableBoolean
import androidx.databinding.ObservableField
import androidx.lifecycle.LiveData
Expand Down Expand Up @@ -72,6 +73,11 @@ class AudioViewModel @Inject constructor(
}

fun loadMainContentAudio(allowAutoPlay: Boolean, reloadingContent: Boolean) {

if (!this::state.isInitialized) {
Log.e("AudioViewModel", "State is not initialized before loading audio.")
return // Avoid proceeding if the state is uninitialized.
}
setStateAndExplorationId(state, explorationId)
hasFeedback = false
loadAudio(contentId = null, allowAutoPlay, reloadingContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,25 @@ class AudioFragmentTest {
}
}

@Test
fun testAudioFragment_loadMainContentAudio_doesNotCrash() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you show proof that this test fails without the fix above?

addMediaInfo()
launch<AudioFragmentTestActivity>(
createAudioFragmentTestIntent(
internalProfileId
)
).use { scenario ->
testCoroutineDispatchers.runCurrent()
scenario.onActivity { activity ->
val audioFragment = activity.supportFragmentManager
.findFragmentById(R.id.audio_fragment_placeholder) as AudioFragment
audioFragment.loadMainContentAudio(allowAutoPlay = false)
testCoroutineDispatchers.runCurrent()
assertThat(activity.isFinishing).isFalse()
}
}
}

private fun withSeekBarPosition(position: Int) = object : TypeSafeMatcher<View>() {
override fun describeTo(description: Description) {
description.appendText("SeekBar with progress same as $position")
Expand Down
Loading