Skip to content
Open
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 @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 5 additions & 13 deletions app/src/main/java/org/wikipedia/games/onthisday/ScoreView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,12 @@ class ScoreView(
}
}

fun updateScore(answerState: List<Boolean>, 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<Boolean>, currentQuestionIndex: Int) {
fun updateScores(answerState: List<Boolean>, 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)
}
Expand Down
Loading