From f828c6b7f631269a26790d7930a005654a84b50b Mon Sep 17 00:00:00 2001 From: Vishwajith-Shettigar Date: Mon, 22 Jan 2024 10:33:58 +0530 Subject: [PATCH] support blank input --- .../MathExpressionInteractionsViewModel.kt | 52 ++++++++++++++----- .../ExplorationProgressController.kt | 3 +- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/MathExpressionInteractionsViewModel.kt b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/MathExpressionInteractionsViewModel.kt index 132c988774b..500afa691f0 100644 --- a/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/MathExpressionInteractionsViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/player/state/itemviewmodel/MathExpressionInteractionsViewModel.kt @@ -105,12 +105,17 @@ class MathExpressionInteractionsViewModel private constructor( override fun onPropertyChanged(sender: Observable, propertyId: Int) { errorOrAvailabilityCheckReceiver.onPendingAnswerErrorOrAvailabilityCheck( pendingAnswerError, - answerText.isNotEmpty() + true ) } } errorMessage.addOnPropertyChangedCallback(callback) isAnswerAvailable.addOnPropertyChangedCallback(callback) + + errorOrAvailabilityCheckReceiver.onPendingAnswerErrorOrAvailabilityCheck( + null, + true + ) } override fun getPendingAnswer(): UserAnswer = UserAnswer.newBuilder().apply { @@ -147,18 +152,18 @@ class MathExpressionInteractionsViewModel private constructor( }.build() override fun checkPendingAnswerError(category: AnswerErrorCategory): String? { - if (answerText.isNotEmpty()) { - pendingAnswerError = when (category) { - // There's no support for real-time errors. - AnswerErrorCategory.REAL_TIME -> null - AnswerErrorCategory.SUBMIT_TIME -> { - interactionType.computeSubmitTimeError( - answerText.toString(), allowedVariables, resourceHandler - ) - } + + pendingAnswerError = when (category) { + // There's no support for real-time errors. + AnswerErrorCategory.REAL_TIME -> null + AnswerErrorCategory.SUBMIT_TIME -> { + interactionType.computeSubmitTimeError( + answerText.toString(), allowedVariables, resourceHandler, interactionType + ) } - errorMessage.set(pendingAnswerError) } + errorMessage.set(pendingAnswerError) + return pendingAnswerError } @@ -290,7 +295,7 @@ class MathExpressionInteractionsViewModel private constructor( } private companion object { - private enum class InteractionType( + enum class InteractionType( val viewType: ViewType, @StringRes val defaultHintTextStringId: Int, val hasPlaceholder: Boolean, @@ -418,8 +423,29 @@ class MathExpressionInteractionsViewModel private constructor( fun computeSubmitTimeError( answerText: String, allowedVariables: List, - appLanguageResourceHandler: AppLanguageResourceHandler + appLanguageResourceHandler: AppLanguageResourceHandler, + interactionType: InteractionType ): String? { + + if (answerText.isBlank()) { + return when (interactionType) { + NUMERIC_EXPRESSION -> { + appLanguageResourceHandler.getStringInLocale( + interactionType.defaultHintTextStringId + ) + } + ALGEBRAIC_EXPRESSION -> { + appLanguageResourceHandler.getStringInLocale( + interactionType.defaultHintTextStringId + ) + } + MATH_EQUATION -> { + appLanguageResourceHandler.getStringInLocale( + interactionType.defaultHintTextStringId + ) + } + } + } return when (val parseResult = parseAnswer(answerText, allowedVariables)) { is MathParsingResult.Failure -> when (val error = parseResult.error) { is DisabledVariablesInUseError -> { diff --git a/domain/src/main/java/org/oppia/android/domain/exploration/ExplorationProgressController.kt b/domain/src/main/java/org/oppia/android/domain/exploration/ExplorationProgressController.kt index 4f939fd331c..fbca8f8d045 100644 --- a/domain/src/main/java/org/oppia/android/domain/exploration/ExplorationProgressController.kt +++ b/domain/src/main/java/org/oppia/android/domain/exploration/ExplorationProgressController.kt @@ -474,8 +474,9 @@ class ExplorationProgressController @Inject constructor( break } } - is ControllerMessage.SubmitAnswer -> + is ControllerMessage.SubmitAnswer -> { controllerState.submitAnswerImpl(message.callbackFlow, message.userAnswer) + } is ControllerMessage.HintIsRevealed -> { controllerState.submitHintIsRevealedImpl(message.callbackFlow, message.hintIndex) }