diff --git a/app/src/main/java/org/wikipedia/games/onthisday/OnThisDayGameActivity.kt b/app/src/main/java/org/wikipedia/games/onthisday/OnThisDayGameActivity.kt index 374aa7577c0..6b259fce213 100644 --- a/app/src/main/java/org/wikipedia/games/onthisday/OnThisDayGameActivity.kt +++ b/app/src/main/java/org/wikipedia/games/onthisday/OnThisDayGameActivity.kt @@ -73,11 +73,16 @@ class OnThisDayGameActivity : BaseActivity(), BaseActivity.Callback { } windowInsets } - - supportFragmentManager.beginTransaction() - .replace(R.id.fragmentContainer, OnThisDayGameMainMenuFragment.newInstance(viewModel.invokeSource), null) - .addToBackStack(null) - .commit() + if (savedInstanceState == null) { + supportFragmentManager.beginTransaction() + .replace( + R.id.fragmentContainer, + OnThisDayGameMainMenuFragment.newInstance(viewModel.invokeSource), + null + ) + .addToBackStack(null) + .commit() + } hideAppBarDateText() } diff --git a/app/src/main/java/org/wikipedia/games/onthisday/OnThisDayGamePlayFragment.kt b/app/src/main/java/org/wikipedia/games/onthisday/OnThisDayGamePlayFragment.kt index 7e5a48def9b..4f8c0749da3 100644 --- a/app/src/main/java/org/wikipedia/games/onthisday/OnThisDayGamePlayFragment.kt +++ b/app/src/main/java/org/wikipedia/games/onthisday/OnThisDayGamePlayFragment.kt @@ -144,13 +144,11 @@ class OnThisDayGamePlayFragment : Fragment() { } private fun onGameStarted(gameState: OnThisDayGameViewModel.GameState) { - updateInitialScores(gameState) updateGameState(gameState) animateQuestionsIn() } private fun onCurrentQuestion(gameState: OnThisDayGameViewModel.GameState) { - updateInitialScores(gameState) if (gameState.currentQuestionIndex > 0 && binding.questionText1.text.isNotEmpty()) { animateQuestionsOut { updateGameState(gameState) @@ -364,7 +362,7 @@ class OnThisDayGamePlayFragment : Fragment() { mainActivity?.updateAppBarDateText(text) } - binding.scoreView.updateScore(gameState.answerState, gameState.currentQuestionIndex, gameState.currentQuestionState.goToNext) + binding.scoreView.updateScores(gameState.answerState, gameState.currentQuestionIndex, gameState.currentQuestionState.goToNext) val event1 = gameState.currentQuestionState.event1 val event2 = gameState.currentQuestionState.event2 @@ -445,10 +443,6 @@ class OnThisDayGamePlayFragment : Fragment() { binding.questionCard2.strokeWidth = otherCardView.strokeWidth } - fun updateInitialScores(gameState: OnThisDayGameViewModel.GameState) { - binding.scoreView.updateInitialScores(gameState.answerState, gameState.currentQuestionIndex) - } - fun playSound(soundName: String) { if (Prefs.isOtdSoundOn) { try { diff --git a/app/src/main/java/org/wikipedia/games/onthisday/ScoreView.kt b/app/src/main/java/org/wikipedia/games/onthisday/ScoreView.kt index 16e76b0d611..11bef0e7129 100644 --- a/app/src/main/java/org/wikipedia/games/onthisday/ScoreView.kt +++ b/app/src/main/java/org/wikipedia/games/onthisday/ScoreView.kt @@ -38,20 +38,12 @@ class ScoreView( } } - fun updateScore(answerState: List, currentQuestionIndex: Int, gotToNext: Boolean) { - if (currentQuestionIndex >= answerState.size) { - return - } - updateScoreViewAppearance( - scoreView = scoreViews[currentQuestionIndex], - isCorrect = answerState[currentQuestionIndex], - isAnswered = gotToNext // when false, user has not answered - ) - } - - fun updateInitialScores(answerState: List, currentQuestionIndex: Int) { + fun updateScores(answerState: List, currentQuestionIndex: Int, goToNext: Boolean) { for (i in answerState.indices) { - val isAnswered = i < currentQuestionIndex + // Question is answered if: + // 1. It's before the current question (i < currentQuestionIndex), OR + // 2. It's the current question AND user has submitted answer (goToNext) + val isAnswered = i < currentQuestionIndex || (i == currentQuestionIndex && goToNext) val isCorrect = isAnswered && answerState[i] updateScoreViewAppearance(scoreViews[i], isCorrect, isAnswered) }