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 part of #4839 Hint dialog can show up during answer input and interrupt the user's experience #5339

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -33,6 +33,7 @@ import org.oppia.android.app.player.audio.AudioUiManager
import org.oppia.android.app.player.state.ConfettiConfig.LARGE_CONFETTI_BURST
import org.oppia.android.app.player.state.ConfettiConfig.MEDIUM_CONFETTI_BURST
import org.oppia.android.app.player.state.ConfettiConfig.MINI_CONFETTI_BURST
import org.oppia.android.app.player.state.itemviewmodel.StateItemViewModel
import org.oppia.android.app.player.state.listener.RouteToHintsAndSolutionListener
import org.oppia.android.app.player.stopplaying.StopStatePlayingSessionWithSavedProgressListener
import org.oppia.android.app.survey.SurveyWelcomeDialogFragment
Expand Down Expand Up @@ -258,7 +259,9 @@ class StateFragmentPresenter @Inject constructor(
)
.addHintsAndSolutionsSupport()
.addAudioVoiceoverSupport(
explorationId, viewModel.currentStateName, viewModel.isAudioBarVisible,
explorationId,
viewModel.currentStateName,
viewModel.isAudioBarVisible,
this::getAudioUiManager
)
.addConceptCardSupport()
Expand Down Expand Up @@ -304,6 +307,14 @@ class StateFragmentPresenter @Inject constructor(
}
}

private fun areListsTheSame(l: List<StateItemViewModel>, r: List<StateItemViewModel>): Boolean {
if (l.size != r.size) {
return false
}

return l.zip(r).all { (x, y) -> x.areContentsTheSame(y) }
}

private fun processEphemeralState(ephemeralState: EphemeralState) {
explorationCheckpointState = ephemeralState.checkpointState
val shouldSplit = splitScreenManager.shouldSplitScreen(ephemeralState.state.interaction.id)
Expand All @@ -329,10 +340,14 @@ class StateFragmentPresenter @Inject constructor(
shouldSplit
)

viewModel.itemList.clear()
viewModel.itemList += dataPair.first
viewModel.rightItemList.clear()
viewModel.rightItemList += dataPair.second
if (!areListsTheSame(viewModel.itemList, dataPair.first)) {
viewModel.itemList.clear()
viewModel.itemList += dataPair.first
}
if (!areListsTheSame(viewModel.rightItemList, dataPair.second)) {
viewModel.rightItemList.clear()
viewModel.rightItemList += dataPair.second
}

if (isInNewState) {
(binding.stateRecyclerView.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
Expand Down Expand Up @@ -400,7 +415,9 @@ class StateFragmentPresenter @Inject constructor(
return when (ephemeralStateResult) {
is AsyncResult.Failure -> {
oppiaLogger.e(
"StateFragment", "Failed to retrieve answer outcome", ephemeralStateResult.error
"StateFragment",
"Failed to retrieve answer outcome",
ephemeralStateResult.error
)
AnswerOutcome.getDefaultInstance()
}
Expand Down Expand Up @@ -465,7 +482,6 @@ class StateFragmentPresenter @Inject constructor(
}

private fun showHintsAndSolutions(helpIndex: HelpIndex, isCurrentStatePendingState: Boolean) {

if (!isCurrentStatePendingState) {
// If current state is not the pending top state, hide the hint bulb.
setHintOpenedAndUnRevealed(false)
Expand Down Expand Up @@ -499,7 +515,6 @@ class StateFragmentPresenter @Inject constructor(
private fun setHintOpenedAndUnRevealed(isHintUnrevealed: Boolean) {
viewModel.setHintOpenedAndUnRevealedVisibility(isHintUnrevealed)
if (isHintUnrevealed) {

val hintBulbAnimation = AnimationUtils.loadAnimation(
context,
R.anim.hint_bulb_animation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,15 @@ class ContentViewModel(
val hasConversationView: Boolean,
val isSplitView: Boolean,
val supportsConceptCards: Boolean
) : StateItemViewModel(ViewType.CONTENT)
) : StateItemViewModel(ViewType.CONTENT) {
override fun areContentsTheSame(other: StateItemViewModel): Boolean {
if (this === other) return true
if (other !is ContentViewModel) return false

return htmlContent == other.htmlContent &&
gcsEntityId == other.gcsEntityId &&
hasConversationView == other.hasConversationView &&
isSplitView == other.isSplitView &&
supportsConceptCards == other.supportsConceptCards
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ class FractionInteractionViewModel private constructor(
)
}

override fun areContentsTheSame(other: StateItemViewModel): Boolean {
if (this === other) return true
if (other !is FractionInteractionViewModel) return false

return (
hasConversationView == other.hasConversationView &&
isSplitView == other.isSplitView &&
pendingAnswerError == other.pendingAnswerError &&
hintText == other.hintText
)
}

override fun getPendingAnswer(): UserAnswer = UserAnswer.newBuilder().apply {
if (answerText.isNotEmpty()) {
val answerTextString = answerText.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ abstract class StateItemViewModel(val viewType: ViewType) : ObservableViewModel(
timeToStartNoticeAnimationMs: Long?
): StateItemViewModel
}

open fun areContentsTheSame(other: StateItemViewModel): Boolean {
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,16 @@ class SubmitButtonViewModel(
val previousNavigationButtonListener: PreviousNavigationButtonListener,
val submitNavigationButtonListener: SubmitNavigationButtonListener,
val isSplitView: Boolean
) : StateItemViewModel(ViewType.SUBMIT_ANSWER_BUTTON)
) : StateItemViewModel(ViewType.SUBMIT_ANSWER_BUTTON) {
override fun areContentsTheSame(other: StateItemViewModel): Boolean {
if (this === other) return true
if (other !is SubmitButtonViewModel) return false

return (
canSubmitAnswer.get() == other.canSubmitAnswer.get() &&
hasConversationView == other.hasConversationView &&
hasPreviousButton == other.hasPreviousButton &&
isSplitView == other.isSplitView
)
}
}
Loading