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 7abeb9fff1f..2daa6148499 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 @@ -219,8 +219,12 @@ class DragAndDropSortInteractionViewModel private constructor( dragDropInteractionContentViewModel.itemIndex = index dragDropInteractionContentViewModel.listSize = _choiceItems.size } - // to update the content of grouped item + + // To update the list (adapter as BindableAdapter<*>).setDataUnchecked(_choiceItems) + + // *Trigger pending answer check* to re-enable submit button + checkPendingAnswerError(AnswerErrorCategory.REAL_TIME) } fun unlinkElement(itemIndex: Int, adapter: RecyclerView.Adapter) { @@ -246,15 +250,24 @@ class DragAndDropSortInteractionViewModel private constructor( dragDropInteractionContentViewModel.itemIndex = index dragDropInteractionContentViewModel.listSize = _choiceItems.size } - // to update the list + + // *Update the list* (adapter as BindableAdapter<*>).setDataUnchecked(_choiceItems) + + // *Trigger pending answer check* to re-enable submit button + checkPendingAnswerError(AnswerErrorCategory.REAL_TIME) } private fun getSubmitTimeError(): DragAndDropSortInteractionError { - return if (_originalChoiceItems == _choiceItems) { + val hasItemsChanged = _originalChoiceItems.size != _choiceItems.size || + _originalChoiceItems.zip(_choiceItems).any { (originalItem, currentItem) -> + originalItem.htmlContent != currentItem.htmlContent + } + return if (!hasItemsChanged) { DragAndDropSortInteractionError.EMPTY_INPUT - } else + } else { DragAndDropSortInteractionError.VALID + } } /** Implementation of [StateItemViewModel.InteractionItemFactory] for this view model. */