Skip to content

Commit

Permalink
support blank input
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishwajith-Shettigar committed Jan 22, 2024
1 parent bb69b22 commit f828c6b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -418,8 +423,29 @@ class MathExpressionInteractionsViewModel private constructor(
fun computeSubmitTimeError(
answerText: String,
allowedVariables: List<String>,
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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit f828c6b

Please sign in to comment.