Skip to content

Commit

Permalink
Addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishwajith-Shettigar committed Jul 11, 2024
1 parent 3ccf7b4 commit 4a84e3d
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,7 @@ class StateFragmentPresenter @Inject constructor(
private fun subscribeToAnswerOutcome(
answerOutcomeResultLiveData: LiveData<AsyncResult<AnswerOutcome>>
) {
if (stateViewModel.getCanSubmitAnswer().get() == true) {
recyclerViewAssembler.resetUserAnswerState()
}
recyclerViewAssembler.resetUserAnswerState()
val answerOutcomeLiveData = getAnswerOutcome(answerOutcomeResultLiveData)
answerOutcomeLiveData.observe(
fragment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ class StatePlayerRecyclerViewAssembler private constructor(
resourceBucketName: String,
entityType: String,
profileId: ProfileId,
userAnswerState: UserAnswerState = UserAnswerState.getDefaultInstance()
userAnswerState: UserAnswerState
): Builder {
return Builder(
accessibilityService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class FractionInteractionViewModel private constructor(
userAnswerState: UserAnswerState
) : StateItemViewModel(ViewType.FRACTION_INPUT_INTERACTION), InteractionAnswerHandler {
private var pendingAnswerError: String? = null
var answerText: CharSequence = userAnswerState.textualAnswer
private var answerErrorCetegory: AnswerErrorCategory = AnswerErrorCategory.NO_ERROR_UNSPECIFIED
var answerText: CharSequence = userAnswerState.textInputAnswer
private var answerErrorCetegory: AnswerErrorCategory = AnswerErrorCategory.NO_ERROR
var isAnswerAvailable = ObservableField<Boolean>(false)
var errorMessage = ObservableField<String>("")

Expand Down Expand Up @@ -118,7 +118,7 @@ class FractionInteractionViewModel private constructor(

override fun getUserAnswerState(): UserAnswerState {
return UserAnswerState.newBuilder().apply {
this.textualAnswer = answerText.toString()
this.textInputAnswer = answerText.toString()
this.answerErrorCategory = answerErrorCetegory
}.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ class MathExpressionInteractionsViewModel private constructor(
* Defines the current answer text being entered by the learner. This is expected to be directly
* bound to the corresponding edit text.
*/
var answerText: CharSequence = userAnswerState.textualAnswer
var answerText: CharSequence = userAnswerState.textInputAnswer
// The value of ths field is set from the Binding and from the TextWatcher. Any
// programmatic modification needs to be done here, so that the Binding and the TextWatcher
// do not step on each other.
set(value) {
field = value.toString().trim()
}

private var answerErrorCetegory: AnswerErrorCategory = AnswerErrorCategory.NO_ERROR_UNSPECIFIED
private var answerErrorCetegory: AnswerErrorCategory = AnswerErrorCategory.NO_ERROR

/**
* Defines whether an answer is currently available to parse. This is expected to be directly
Expand Down Expand Up @@ -126,7 +126,7 @@ class MathExpressionInteractionsViewModel private constructor(

override fun getUserAnswerState(): UserAnswerState {
return UserAnswerState.newBuilder().apply {
this.textualAnswer = answerText.toString()
this.textInputAnswer = answerText.toString()
this.answerErrorCategory = answerErrorCetegory
}.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class NumericInputViewModel private constructor(
private val resourceHandler: AppLanguageResourceHandler,
userAnswerState: UserAnswerState
) : StateItemViewModel(ViewType.NUMERIC_INPUT_INTERACTION), InteractionAnswerHandler {
var answerText: CharSequence = userAnswerState.textualAnswer
private var answerErrorCetegory: AnswerErrorCategory = AnswerErrorCategory.NO_ERROR_UNSPECIFIED
var answerText: CharSequence = userAnswerState.textInputAnswer
private var answerErrorCetegory: AnswerErrorCategory = AnswerErrorCategory.NO_ERROR
private var pendingAnswerError: String? = null
val errorMessage = ObservableField<String>("")
var isAnswerAvailable = ObservableField<Boolean>(false)
Expand Down Expand Up @@ -77,7 +77,7 @@ class NumericInputViewModel private constructor(

override fun getUserAnswerState(): UserAnswerState {
return UserAnswerState.newBuilder().apply {
this.textualAnswer = answerText.toString()
this.textInputAnswer = answerText.toString()
this.answerErrorCategory = answerErrorCetegory
}.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class RatioExpressionInputInteractionViewModel private constructor(
userAnswerState: UserAnswerState
) : StateItemViewModel(ViewType.RATIO_EXPRESSION_INPUT_INTERACTION), InteractionAnswerHandler {
private var pendingAnswerError: String? = null
var answerText: CharSequence = userAnswerState.textualAnswer
private var answerErrorCetegory: AnswerErrorCategory = AnswerErrorCategory.NO_ERROR_UNSPECIFIED
var answerText: CharSequence = userAnswerState.textInputAnswer
private var answerErrorCetegory: AnswerErrorCategory = AnswerErrorCategory.NO_ERROR
var isAnswerAvailable = ObservableField<Boolean>(false)
var errorMessage = ObservableField<String>("")

Expand Down Expand Up @@ -102,7 +102,7 @@ class RatioExpressionInputInteractionViewModel private constructor(

override fun getUserAnswerState(): UserAnswerState {
return UserAnswerState.newBuilder().apply {
this.textualAnswer = answerText.toString()
this.textInputAnswer = answerText.toString()
this.answerErrorCategory = answerErrorCetegory
}.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class SelectionInteractionViewModel private constructor(
?: listOf()
}

private var answerErrorCetegory: AnswerErrorCategory = AnswerErrorCategory.NO_ERROR_UNSPECIFIED
private var answerErrorCetegory: AnswerErrorCategory = AnswerErrorCategory.NO_ERROR

private val minAllowableSelectionCount: Int by lazy {
interaction.customizationArgsMap["minAllowableSelectionCount"]?.signedInt ?: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class TextInputViewModel private constructor(
private val translationController: TranslationController,
userAnswerState: UserAnswerState
) : StateItemViewModel(ViewType.TEXT_INPUT_INTERACTION), InteractionAnswerHandler {
var answerText: CharSequence = userAnswerState.textualAnswer
private var answerErrorCetegory: AnswerErrorCategory = AnswerErrorCategory.NO_ERROR_UNSPECIFIED
var answerText: CharSequence = userAnswerState.textInputAnswer
private var answerErrorCetegory: AnswerErrorCategory = AnswerErrorCategory.NO_ERROR
val hintText: CharSequence = deriveHintText(interaction)
private var pendingAnswerError: String? = null

Expand Down Expand Up @@ -107,7 +107,7 @@ class TextInputViewModel private constructor(

override fun getUserAnswerState(): UserAnswerState {
return UserAnswerState.newBuilder().apply {
this.textualAnswer = answerText.toString()
this.textInputAnswer = answerText.toString()
this.answerErrorCategory = answerErrorCetegory
}.build()
}
Expand Down
26 changes: 16 additions & 10 deletions model/src/main/proto/exploration.proto
Original file line number Diff line number Diff line change
Expand Up @@ -421,31 +421,37 @@ enum CheckpointState {
CHECKPOINT_UNSAVED = 3;
}

// Corresponds to a item selection answer that user has selected.
// Represents the state of item selection answers that the user has selected.
message ItemSelectionAnswerState {
// List of selected item indexes
repeated int32 selected_indexes = 1;
}

// Corresponds to a raw representation of the current answer entered by the user
// which is used to retain state on configuration changes
// Represents the user's answer state, retaining state across configuration changes.
message UserAnswerState {
// Represents the last error state.
AnswerErrorCategory answer_error_category = 1;
oneof answer_input_type{
ItemSelectionAnswerState item_selection = 2;

// A raw answer entered by user in a text-based interactions.
string textual_answer = 3;
// Type of answer input:
oneof answer_input_type {
// User's selection for selection input interactions.
ItemSelectionAnswerState item_selection = 2;
// Raw answer entered by the user in text-based interactions.
string text_input_answer = 3;
}
}

// Represents categories of errors that can be inferred from a pending answer.
enum AnswerErrorCategory {
// The error is unknown or not specified.
ERROR_UNSPECIFIED = 0;

// Corresponds to the pending answer having no error.
NO_ERROR_UNSPECIFIED = 0;
NO_ERROR = 1;

// Corresponds to errors that may be found while the user is trying to input an answer.
REAL_TIME = 1;
REAL_TIME = 2;

// Corresponds to errors that may be found only when a user tries to submit an answer.
SUBMIT_TIME = 2;
SUBMIT_TIME = 3;
}

0 comments on commit 4a84e3d

Please sign in to comment.