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 #1737: Singleton for exploration to handle input for configuration changes #2514

Closed
Closed
Show file tree
Hide file tree
Changes from 13 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 @@ -129,4 +129,14 @@ class StateFragment :
fun revealSolution() = stateFragmentPresenter.revealSolution()

fun dismissConceptCard() = stateFragmentPresenter.dismissConceptCard()

override fun onResume() {
super.onResume()
stateFragmentPresenter.handleOnResume()
}

override fun onDestroyView() {
super.onDestroyView()
stateFragmentPresenter.handleDestroyView()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.oppia.android.app.player.state

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -32,6 +33,7 @@ import org.oppia.android.app.utility.SplitScreenManager
import org.oppia.android.app.viewmodel.ViewModelProvider
import org.oppia.android.databinding.StateFragmentBinding
import org.oppia.android.domain.exploration.ExplorationProgressController
import org.oppia.android.domain.state.RetriveUserAnswer
import org.oppia.android.domain.topic.StoryProgressController
import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
Expand Down Expand Up @@ -154,6 +156,7 @@ class StateFragmentPresenter @Inject constructor(
viewModel.setHintBulbVisibility(false)
hideKeyboard()
moveToNextState()
RetriveUserAnswer.clearUserAnswer()
}

fun onNextButtonClicked() = moveToNextState()
Expand Down Expand Up @@ -521,4 +524,17 @@ class StateFragmentPresenter @Inject constructor(
Date().time
)
}

fun handleOnResume() {
RetriveUserAnswer.getUserAnswer()?.let {
Log.d("testSingleton", "userAnswer -> ${it.answer}")
Log.d("testSingleton", "userAnswer -> $it")
}
}

fun handleDestroyView() {
RetriveUserAnswer.setUserAnswer(
viewModel.getPendingAnswer(recyclerViewAssembler::getPendingAnswerHandler)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.oppia.android.domain.state

import org.oppia.android.app.model.UserAnswer

object RetriveUserAnswer {
Copy link
Member

Choose a reason for hiding this comment

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

This should be a Dagger singleton (see other @Singleton marked classes in the codebase).

// text and error message for fraction [FractionInteractionView.kt]
// list of check boxes as a string and back to check box [SelectionInteractionView.kt]
// text and error msg for [NumericInputInteractionView.kt]
// text and error message for [RatioInputInteractionView.kt]
// text for [TextInputInteractionView.kt]
// list for drag & drop [DragDropSortInteractionView.kt]
// list for drag & drop with merging [DragDropSortInteractionView.kt]
// selected img in the [ImageRegionSelectionInteractionView.kt]

private var userAnswer: UserAnswer? = null

fun setUserAnswer(solution: UserAnswer) {
this.userAnswer = solution
}
fun getUserAnswer(): UserAnswer? = userAnswer

fun clearUserAnswer() {
userAnswer = null
}
}