diff --git a/app/src/main/java/org/oppia/android/app/player/state/StateFragment.kt b/app/src/main/java/org/oppia/android/app/player/state/StateFragment.kt index 1eff9e90ff0..bac7746d3de 100755 --- a/app/src/main/java/org/oppia/android/app/player/state/StateFragment.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/StateFragment.kt @@ -129,4 +129,18 @@ class StateFragment : fun revealSolution() = stateFragmentPresenter.revealSolution() fun dismissConceptCard() = stateFragmentPresenter.dismissConceptCard() + + override fun onResume() { + super.onResume() + stateFragmentPresenter.handleOnResume() + } + + override fun onDestroyView() { + super.onDestroyView() + stateFragmentPresenter.handleDestroyView() + } + + override fun setPendingAnswer(userAnswer: UserAnswer) { +// TODO("Not yet implemented") + } } diff --git a/app/src/main/java/org/oppia/android/app/player/state/StateFragmentPresenter.kt b/app/src/main/java/org/oppia/android/app/player/state/StateFragmentPresenter.kt index a7af47200fa..a4f15747151 100755 --- a/app/src/main/java/org/oppia/android/app/player/state/StateFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/StateFragmentPresenter.kt @@ -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 @@ -37,6 +38,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 @@ -163,6 +165,7 @@ class StateFragmentPresenter @Inject constructor( viewModel.setHintBulbVisibility(false) hideKeyboard() moveToNextState() + RetriveUserAnswer.clearUserAnswer() } fun onNextButtonClicked() = moveToNextState() @@ -541,4 +544,18 @@ class StateFragmentPresenter @Inject constructor( oppiaClock.getCurrentTimeMs() ) } + + fun handleOnResume() { + RetriveUserAnswer.getUserAnswer()?.let { + viewModel.setPendingAnswer(it, recyclerViewAssembler::getPendingAnswerHandler) + Log.d("testSingleton", "userAnswer -> ${it.answer}") + Log.d("testSingleton", "userAnswer -> $it") + } + } + + fun handleDestroyView() { + RetriveUserAnswer.setUserAnswer( + viewModel.getPendingAnswer(recyclerViewAssembler::getPendingAnswerHandler) + ) + } } diff --git a/app/src/main/java/org/oppia/android/app/player/state/StateViewModel.kt b/app/src/main/java/org/oppia/android/app/player/state/StateViewModel.kt index a2e284ae53c..9b2bb19cf01 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/StateViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/StateViewModel.kt @@ -58,6 +58,13 @@ class StateViewModel @Inject constructor() : ObservableViewModel() { ) ?: UserAnswer.getDefaultInstance() } + fun setPendingAnswer( + userAnswer: UserAnswer, + retrieveAnswerHandler: (List) -> InteractionAnswerHandler? + ) { + retrieveAnswerHandler(getAnswerItemList())?.setPendingAnswer(userAnswer) + } + private fun getPendingAnswerWithoutError( answerHandler: InteractionAnswerHandler? ): UserAnswer? { diff --git a/app/src/main/java/org/oppia/android/app/player/state/answerhandling/InteractionAnswerHandler.kt b/app/src/main/java/org/oppia/android/app/player/state/answerhandling/InteractionAnswerHandler.kt index cb8251b3295..461ec634c0a 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/answerhandling/InteractionAnswerHandler.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/answerhandling/InteractionAnswerHandler.kt @@ -26,6 +26,8 @@ interface InteractionAnswerHandler { fun getPendingAnswer(): UserAnswer? { return null } + + fun setPendingAnswer(userAnswer: UserAnswer) } /** diff --git a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/ContinueInteractionViewModel.kt b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/ContinueInteractionViewModel.kt index a59acca203a..0355f2edffb 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/ContinueInteractionViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/ContinueInteractionViewModel.kt @@ -37,6 +37,10 @@ class ContinueInteractionViewModel( .build() } + override fun setPendingAnswer(userAnswer: UserAnswer) { +// TODO("Not yet implemented") + } + fun handleButtonClicked() { interactionAnswerReceiver.onAnswerReadyForSubmission(getPendingAnswer()) } diff --git a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/DragAndDropSortInteractionViewModel.kt b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/DragAndDropSortInteractionViewModel.kt index d52e45442b1..ca814322d47 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/DragAndDropSortInteractionViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/DragAndDropSortInteractionViewModel.kt @@ -121,6 +121,10 @@ class DragAndDropSortInteractionViewModel( return userAnswerBuilder.build() } + override fun setPendingAnswer(userAnswer: UserAnswer) { +// TODO("Not yet implemented") + } + /** Returns an HTML list containing all of the HTML string elements as items in the list. */ private fun convertItemsToAnswer(htmlItems: List): ListOfSetsOfHtmlStrings { return ListOfSetsOfHtmlStrings.newBuilder() diff --git a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/FractionInteractionViewModel.kt b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/FractionInteractionViewModel.kt index c142dc3cb3e..e8fa5d458bb 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/FractionInteractionViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/FractionInteractionViewModel.kt @@ -3,6 +3,7 @@ package org.oppia.android.app.player.state.itemviewmodel import android.content.Context import android.text.Editable import android.text.TextWatcher +import android.util.Log import androidx.databinding.Observable import androidx.databinding.ObservableField import org.oppia.android.R @@ -23,7 +24,7 @@ class FractionInteractionViewModel( private val interactionAnswerErrorOrAvailabilityCheckReceiver: InteractionAnswerErrorOrAvailabilityCheckReceiver // ktlint-disable max-line-length ) : StateItemViewModel(ViewType.FRACTION_INPUT_INTERACTION), InteractionAnswerHandler { private var pendingAnswerError: String? = null - var answerText: CharSequence = "" + var answerText = "" var isAnswerAvailable = ObservableField(false) var errorMessage = ObservableField("") @@ -56,6 +57,12 @@ class FractionInteractionViewModel( return userAnswerBuilder.build() } + override fun setPendingAnswer(userAnswer: UserAnswer) { + answerText = userAnswer.plainAnswer + notifyChange() + Log.d("testSingleton", "i've set the value finally it is ${userAnswer.plainAnswer}") + } + /** It checks the pending error for the current fraction input, and correspondingly updates the error string based on the specified error category. */ override fun checkPendingAnswerError(category: AnswerErrorCategory): String? { if (answerText.isNotEmpty()) { @@ -84,12 +91,14 @@ class FractionInteractionViewModel( } override fun onTextChanged(answer: CharSequence, start: Int, before: Int, count: Int) { - answerText = answer.toString().trim() - val isAnswerTextAvailable = answerText.isNotEmpty() - if (isAnswerTextAvailable != isAnswerAvailable.get()) { - isAnswerAvailable.set(isAnswerTextAvailable) + if (answer.isNotEmpty()) { + answerText = answer.toString().trim() + val isAnswerTextAvailable = answerText.isNotEmpty() + if (isAnswerTextAvailable != isAnswerAvailable.get()) { + isAnswerAvailable.set(isAnswerTextAvailable) + } + checkPendingAnswerError(AnswerErrorCategory.REAL_TIME) } - checkPendingAnswerError(AnswerErrorCategory.REAL_TIME) } override fun afterTextChanged(s: Editable) { diff --git a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/ImageRegionSelectionInteractionViewModel.kt b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/ImageRegionSelectionInteractionViewModel.kt index 8b4dc01544a..3b8700b0463 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/ImageRegionSelectionInteractionViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/ImageRegionSelectionInteractionViewModel.kt @@ -76,6 +76,10 @@ class ImageRegionSelectionInteractionViewModel( return userAnswerBuilder.build() } + override fun setPendingAnswer(userAnswer: UserAnswer) { +// TODO("Not yet implemented") + } + private fun parseClickOnImage(answerTextString: String): ClickOnImage { val region = selectableRegions.find { it.label == answerTextString } return ClickOnImage.newBuilder() diff --git a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/NumericInputViewModel.kt b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/NumericInputViewModel.kt index 0825021f7e9..6b7be2a731e 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/NumericInputViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/NumericInputViewModel.kt @@ -84,4 +84,8 @@ class NumericInputViewModel( } return userAnswerBuilder.build() } + + override fun setPendingAnswer(userAnswer: UserAnswer) { +// TODO("Not yet implemented") + } } diff --git a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/RatioExpressionInputInteractionViewModel.kt b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/RatioExpressionInputInteractionViewModel.kt index 0979bd4e785..7315c3b7636 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/RatioExpressionInputInteractionViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/RatioExpressionInputInteractionViewModel.kt @@ -34,6 +34,10 @@ class RatioExpressionInputInteractionViewModel( private val numberOfTerms = interaction.customizationArgsMap["numberOfTerms"]?.signedInt ?: 0 + override fun setPendingAnswer(userAnswer: UserAnswer) { +// TODO("Not yet implemented") + } + init { val callback: Observable.OnPropertyChangedCallback = object : Observable.OnPropertyChangedCallback() { diff --git a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/SelectionInteractionViewModel.kt b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/SelectionInteractionViewModel.kt index 7c59bd0c252..d94e34a9ee2 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/SelectionInteractionViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/SelectionInteractionViewModel.kt @@ -95,6 +95,10 @@ class SelectionInteractionViewModel( return userAnswerBuilder.build() } + override fun setPendingAnswer(userAnswer: UserAnswer) { +// TODO("Not yet implemented") + } + /** Returns an HTML list containing all of the HTML string elements as items in the list. */ private fun convertSelectedItemsToHtmlString(subtitledHtmls: Collection): String { return when (subtitledHtmls.size) { diff --git a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/TextInputViewModel.kt b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/TextInputViewModel.kt index db5e2711d60..54f3a9ba62b 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/TextInputViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/TextInputViewModel.kt @@ -64,6 +64,10 @@ class TextInputViewModel( return userAnswerBuilder.build() } + override fun setPendingAnswer(userAnswer: UserAnswer) { +// TODO("Not yet implemented") + } + private fun deriveHintText(interaction: Interaction): CharSequence { // The default placeholder for text input is empty. return interaction.customizationArgsMap["placeholder"]?.subtitledUnicode?.unicodeStr ?: "" diff --git a/domain/src/main/java/org/oppia/android/domain/state/RetriveUserAnswer.kt b/domain/src/main/java/org/oppia/android/domain/state/RetriveUserAnswer.kt new file mode 100644 index 00000000000..d801dfd86cc --- /dev/null +++ b/domain/src/main/java/org/oppia/android/domain/state/RetriveUserAnswer.kt @@ -0,0 +1,25 @@ +package org.oppia.android.domain.state + +import org.oppia.android.app.model.UserAnswer + +object RetriveUserAnswer { + // 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 + } +}