From 5cf09d07fa99f9f9edc3a915c1942f3e85648e7a Mon Sep 17 00:00:00 2001 From: Farees Hussain Date: Wed, 11 Nov 2020 10:40:00 +0530 Subject: [PATCH 1/9] issue 2098 --- .idea/gradle.xml | 3 ++- .idea/misc.xml | 4 ++-- .../domain/classify/rules/RuleQualifiers.kt | 20 +++++++++---------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 6aa35f75034..6466b7bedb7 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -20,7 +20,8 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index f06c82261e6..d5d35ec44f1 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,9 +1,9 @@ - + - + \ No newline at end of file diff --git a/domain/src/main/java/org/oppia/android/domain/classify/rules/RuleQualifiers.kt b/domain/src/main/java/org/oppia/android/domain/classify/rules/RuleQualifiers.kt index a868bd537f0..18b9d9faed7 100644 --- a/domain/src/main/java/org/oppia/android/domain/classify/rules/RuleQualifiers.kt +++ b/domain/src/main/java/org/oppia/android/domain/classify/rules/RuleQualifiers.kt @@ -2,42 +2,42 @@ package org.oppia.android.domain.classify.rules import javax.inject.Qualifier -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the continue interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the continue interaction. */ @Qualifier annotation class ContinueRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the fraction input interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the fraction input interaction. */ @Qualifier annotation class FractionInputRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the item selection interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the item selection interaction. */ @Qualifier annotation class ItemSelectionInputRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the multiple choice interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the multiple choice interaction. */ @Qualifier annotation class MultipleChoiceInputRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the number with units interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the number with units interaction. */ @Qualifier annotation class NumberWithUnitsRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the text input interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the text input interaction. */ @Qualifier annotation class TextInputRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the numeric input interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the numeric input interaction. */ @Qualifier annotation class NumericInputRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the drag drop sort input interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the drag drop sort input interaction. */ @Qualifier annotation class DragDropSortInputRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the image click input interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the image click input interaction. */ @Qualifier annotation class ImageClickInputRules -/** Corresponds to [org.oppia.domain.classify.RuleClassifier]s that can be used by the ratio input interaction. */ +/** Corresponds to [org.oppia.android.domain.classify.RuleClassifier]s that can be used by the ratio input interaction. */ @Qualifier annotation class RatioExpressionInputRules From f3483f87c4133e87aedb77afa920b55cb5f05e0a Mon Sep 17 00:00:00 2001 From: farees Date: Thu, 31 Dec 2020 22:47:15 +0530 Subject: [PATCH 2/9] test commit --- .idea/gradle.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 6aa35f75034..6466b7bedb7 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -20,7 +20,8 @@ - + \ No newline at end of file From 2110cdf3f857b0834be04db4f7d810d85a561082 Mon Sep 17 00:00:00 2001 From: Farees Hussain Date: Fri, 1 Jan 2021 01:11:14 +0530 Subject: [PATCH 3/9] Update gradle.xml --- .idea/gradle.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 6466b7bedb7..6aa35f75034 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -20,8 +20,7 @@ - \ No newline at end of file + From e09a602460edb2e233447bc56356571a70238a9a Mon Sep 17 00:00:00 2001 From: Farees Hussain Date: Fri, 1 Jan 2021 01:11:48 +0530 Subject: [PATCH 4/9] Update misc.xml --- .idea/misc.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d5d35ec44f1..f06c82261e6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,9 +1,9 @@ - + - \ No newline at end of file + From 38fb39f7e13d5bc80b044f1364220af6a6b6f87b Mon Sep 17 00:00:00 2001 From: farees Date: Fri, 1 Jan 2021 06:38:11 +0530 Subject: [PATCH 5/9] Fix gradle.xml --- .idea/gradle.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 6466b7bedb7..6aa35f75034 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -20,8 +20,7 @@ - \ No newline at end of file + From b2ce885ae96e4dde09a30184f0b2b2ecc3c32446 Mon Sep 17 00:00:00 2001 From: farees Date: Mon, 18 Jan 2021 23:55:16 +0530 Subject: [PATCH 6/9] Initial implementation --- .../android/app/player/state/StateFragment.kt | 10 ++++++++ .../player/state/StateFragmentPresenter.kt | 16 ++++++++++++ .../android/domain/state/InputInteraction.kt | 25 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 domain/src/main/java/org/oppia/android/domain/state/InputInteraction.kt 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..9ba812fcc30 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,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() + } } 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 43737cab4be..4642b8660a2 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 @@ -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.InputInteraction import org.oppia.android.domain.topic.StoryProgressController import org.oppia.android.util.data.AsyncResult import org.oppia.android.util.data.DataProviders.Companion.toLiveData @@ -154,6 +156,7 @@ class StateFragmentPresenter @Inject constructor( viewModel.setHintBulbVisibility(false) hideKeyboard() moveToNextState() + InputInteraction.clearUserAnswer() } fun onNextButtonClicked() = moveToNextState() @@ -521,4 +524,17 @@ class StateFragmentPresenter @Inject constructor( Date().time ) } + + fun handleOnResume() { + InputInteraction.getUserAnswer()?.let { + Log.d("testSingleton", "userAnswer -> ${it.answer}") + Log.d("testSingleton", "userAnswer -> $it") + } + } + + fun handleDestroyView() { + InputInteraction.setUserAnswer( + viewModel.getPendingAnswer(recyclerViewAssembler::getPendingAnswerHandler) + ) + } } diff --git a/domain/src/main/java/org/oppia/android/domain/state/InputInteraction.kt b/domain/src/main/java/org/oppia/android/domain/state/InputInteraction.kt new file mode 100644 index 00000000000..2597cd5bd32 --- /dev/null +++ b/domain/src/main/java/org/oppia/android/domain/state/InputInteraction.kt @@ -0,0 +1,25 @@ +package org.oppia.android.domain.state + +import org.oppia.android.app.model.UserAnswer + +object InputInteraction { + // 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 + } +} From bcfc5806f35fb60f28dda261d24775350e2a7fa1 Mon Sep 17 00:00:00 2001 From: farees Date: Tue, 19 Jan 2021 00:19:50 +0530 Subject: [PATCH 7/9] Updated singleton title --- .../android/app/player/state/StateFragmentPresenter.kt | 8 ++++---- .../state/{InputInteraction.kt => RetriveUserAnswer.kt} | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) rename domain/src/main/java/org/oppia/android/domain/state/{InputInteraction.kt => RetriveUserAnswer.kt} (96%) 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 4642b8660a2..86fe2c021a2 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 @@ -33,7 +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.InputInteraction +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 @@ -156,7 +156,7 @@ class StateFragmentPresenter @Inject constructor( viewModel.setHintBulbVisibility(false) hideKeyboard() moveToNextState() - InputInteraction.clearUserAnswer() + RetriveUserAnswer.clearUserAnswer() } fun onNextButtonClicked() = moveToNextState() @@ -526,14 +526,14 @@ class StateFragmentPresenter @Inject constructor( } fun handleOnResume() { - InputInteraction.getUserAnswer()?.let { + RetriveUserAnswer.getUserAnswer()?.let { Log.d("testSingleton", "userAnswer -> ${it.answer}") Log.d("testSingleton", "userAnswer -> $it") } } fun handleDestroyView() { - InputInteraction.setUserAnswer( + RetriveUserAnswer.setUserAnswer( viewModel.getPendingAnswer(recyclerViewAssembler::getPendingAnswerHandler) ) } diff --git a/domain/src/main/java/org/oppia/android/domain/state/InputInteraction.kt b/domain/src/main/java/org/oppia/android/domain/state/RetriveUserAnswer.kt similarity index 96% rename from domain/src/main/java/org/oppia/android/domain/state/InputInteraction.kt rename to domain/src/main/java/org/oppia/android/domain/state/RetriveUserAnswer.kt index 2597cd5bd32..d801dfd86cc 100644 --- a/domain/src/main/java/org/oppia/android/domain/state/InputInteraction.kt +++ b/domain/src/main/java/org/oppia/android/domain/state/RetriveUserAnswer.kt @@ -2,7 +2,7 @@ package org.oppia.android.domain.state import org.oppia.android.app.model.UserAnswer -object InputInteraction { +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] From 5c608758afed7fcfdc147df77cd831811bb69d6b Mon Sep 17 00:00:00 2001 From: farees Date: Sat, 6 Feb 2021 16:54:11 +0530 Subject: [PATCH 8/9] Added support for FractionInteractionViewModel.kt --- .../android/app/player/state/StateFragment.kt | 4 +++ .../player/state/StateFragmentPresenter.kt | 1 + .../app/player/state/StateViewModel.kt | 7 ++++ .../InteractionAnswerHandler.kt | 2 ++ .../ContinueInteractionViewModel.kt | 4 +++ .../DragAndDropSortInteractionViewModel.kt | 4 +++ .../FractionInteractionViewModel.kt | 32 ++++++++++++------- ...mageRegionSelectionInteractionViewModel.kt | 4 +++ .../itemviewmodel/NumericInputViewModel.kt | 4 +++ ...atioExpressionInputInteractionViewModel.kt | 4 +++ .../SelectionInteractionViewModel.kt | 4 +++ .../state/itemviewmodel/TextInputViewModel.kt | 4 +++ 12 files changed, 62 insertions(+), 12 deletions(-) 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 9ba812fcc30..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 @@ -139,4 +139,8 @@ class StateFragment : 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 86fe2c021a2..d8a3d34b1d1 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 @@ -527,6 +527,7 @@ class StateFragmentPresenter @Inject constructor( fun handleOnResume() { RetriveUserAnswer.getUserAnswer()?.let { + viewModel.setPendingAnswer(it, recyclerViewAssembler::getPendingAnswerHandler) Log.d("testSingleton", "userAnswer -> ${it.answer}") Log.d("testSingleton", "userAnswer -> $it") } 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 978c6c45e95..556c410f591 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 @@ -106,6 +106,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..ecff07b2fb6 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 = ObservableField("") var isAnswerAvailable = ObservableField(false) var errorMessage = ObservableField("") @@ -36,7 +37,7 @@ class FractionInteractionViewModel( override fun onPropertyChanged(sender: Observable, propertyId: Int) { interactionAnswerErrorOrAvailabilityCheckReceiver.onPendingAnswerErrorOrAvailabilityCheck( pendingAnswerError, - answerText.isNotEmpty() + answerText.get()!!.isNotEmpty() ) } } @@ -46,8 +47,8 @@ class FractionInteractionViewModel( override fun getPendingAnswer(): UserAnswer { val userAnswerBuilder = UserAnswer.newBuilder() - if (answerText.isNotEmpty()) { - val answerTextString = answerText.toString() + if (answerText.get()!!.isNotEmpty()) { + val answerTextString = answerText.get().toString() userAnswerBuilder.answer = InteractionObject.newBuilder() .setFraction(stringToFractionParser.parseFractionFromString(answerTextString)) .build() @@ -56,19 +57,24 @@ class FractionInteractionViewModel( return userAnswerBuilder.build() } + override fun setPendingAnswer(userAnswer: UserAnswer) { + answerText.set(userAnswer.plainAnswer) + 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()) { + if (answerText.get()!!.isNotEmpty()) { when (category) { AnswerErrorCategory.REAL_TIME -> pendingAnswerError = - stringToFractionParser.getRealTimeAnswerError(answerText.toString()) + stringToFractionParser.getRealTimeAnswerError(answerText.get().toString()) .getErrorMessageFromStringRes( context ) AnswerErrorCategory.SUBMIT_TIME -> pendingAnswerError = - stringToFractionParser.getSubmitTimeError(answerText.toString()) + stringToFractionParser.getSubmitTimeError(answerText.get().toString()) .getErrorMessageFromStringRes( context ) @@ -84,12 +90,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.set(answer.toString().trim()) + val isAnswerTextAvailable = answerText.get()!!.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 d2b17cb5fb4..f68c866d669 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 @@ -85,6 +85,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(htmlItems: Collection): String { return when (htmlItems.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 ?: "" From 3205455548dfb5bd2627d9c208deca3fba91e468 Mon Sep 17 00:00:00 2001 From: farees Date: Wed, 10 Feb 2021 23:51:38 +0530 Subject: [PATCH 9/9] Using notifyChange() --- .../FractionInteractionViewModel.kt | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) 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 ecff07b2fb6..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 @@ -24,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 = ObservableField("") + var answerText = "" var isAnswerAvailable = ObservableField(false) var errorMessage = ObservableField("") @@ -37,7 +37,7 @@ class FractionInteractionViewModel( override fun onPropertyChanged(sender: Observable, propertyId: Int) { interactionAnswerErrorOrAvailabilityCheckReceiver.onPendingAnswerErrorOrAvailabilityCheck( pendingAnswerError, - answerText.get()!!.isNotEmpty() + answerText.isNotEmpty() ) } } @@ -47,8 +47,8 @@ class FractionInteractionViewModel( override fun getPendingAnswer(): UserAnswer { val userAnswerBuilder = UserAnswer.newBuilder() - if (answerText.get()!!.isNotEmpty()) { - val answerTextString = answerText.get().toString() + if (answerText.isNotEmpty()) { + val answerTextString = answerText.toString() userAnswerBuilder.answer = InteractionObject.newBuilder() .setFraction(stringToFractionParser.parseFractionFromString(answerTextString)) .build() @@ -58,23 +58,24 @@ class FractionInteractionViewModel( } override fun setPendingAnswer(userAnswer: UserAnswer) { - answerText.set(userAnswer.plainAnswer) + 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.get()!!.isNotEmpty()) { + if (answerText.isNotEmpty()) { when (category) { AnswerErrorCategory.REAL_TIME -> pendingAnswerError = - stringToFractionParser.getRealTimeAnswerError(answerText.get().toString()) + stringToFractionParser.getRealTimeAnswerError(answerText.toString()) .getErrorMessageFromStringRes( context ) AnswerErrorCategory.SUBMIT_TIME -> pendingAnswerError = - stringToFractionParser.getSubmitTimeError(answerText.get().toString()) + stringToFractionParser.getSubmitTimeError(answerText.toString()) .getErrorMessageFromStringRes( context ) @@ -91,8 +92,8 @@ class FractionInteractionViewModel( override fun onTextChanged(answer: CharSequence, start: Int, before: Int, count: Int) { if (answer.isNotEmpty()) { - answerText.set(answer.toString().trim()) - val isAnswerTextAvailable = answerText.get()!!.isNotEmpty() + answerText = answer.toString().trim() + val isAnswerTextAvailable = answerText.isNotEmpty() if (isAnswerTextAvailable != isAnswerAvailable.get()) { isAnswerAvailable.set(isAnswerTextAvailable) }