From 52e1261cc5605eace61a5627f038c57d3fa317c4 Mon Sep 17 00:00:00 2001 From: masclot Date: Tue, 17 Oct 2023 16:32:42 +0200 Subject: [PATCH] In FractionInteraction UI, leave submit button enabled when answer is empty. Show an error on submitting an empty answer. --- .../FractionInteractionViewModel.kt | 30 ++++++++++++------- app/src/main/res/values/strings.xml | 1 + 2 files changed, 21 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 22d42a74744..2360454d433 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 @@ -43,12 +43,17 @@ class FractionInteractionViewModel private constructor( override fun onPropertyChanged(sender: Observable, propertyId: Int) { errorOrAvailabilityCheckReceiver.onPendingAnswerErrorOrAvailabilityCheck( pendingAnswerError, - answerText.isNotEmpty() + true // Allow submit on empty answer ) } } errorMessage.addOnPropertyChangedCallback(callback) isAnswerAvailable.addOnPropertyChangedCallback(callback) + // Apply defaults: + errorOrAvailabilityCheckReceiver.onPendingAnswerErrorOrAvailabilityCheck( + null, + true + ) } override fun getPendingAnswer(): UserAnswer = UserAnswer.newBuilder().apply { @@ -64,23 +69,28 @@ class FractionInteractionViewModel private constructor( /** 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()) { - when (category) { - AnswerErrorCategory.REAL_TIME -> { + when (category) { + AnswerErrorCategory.REAL_TIME -> { + if (answerText.isNotEmpty()) { pendingAnswerError = FractionParsingUiError.createFromParsingError( fractionParser.getRealTimeAnswerError(answerText.toString()) ).getErrorMessageFromStringRes(resourceHandler) + } else { + pendingAnswerError = null } - AnswerErrorCategory.SUBMIT_TIME -> { - pendingAnswerError = - FractionParsingUiError.createFromParsingError( - fractionParser.getSubmitTimeError(answerText.toString()) - ).getErrorMessageFromStringRes(resourceHandler) + } + AnswerErrorCategory.SUBMIT_TIME -> { + pendingAnswerError = if (answerText.isNotEmpty()) { + FractionParsingUiError.createFromParsingError( + fractionParser.getSubmitTimeError(answerText.toString()) + ).getErrorMessageFromStringRes(resourceHandler) + } else { + resourceHandler.getStringInLocale(R.string.interaction_answer_empty_on_submit) } } - errorMessage.set(pendingAnswerError) } + errorMessage.set(pendingAnswerError) return pendingAnswerError } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 79ec1534ff1..30e6545b825 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -606,4 +606,5 @@ Lock Icon Download Status html Content + "Enter an answer to continue"