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..bb2fb2c63d1 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 haveItemsChanged = _originalChoiceItems.size != _choiceItems.size || + _originalChoiceItems.zip(_choiceItems).any { (originalItem, currentItem) -> + originalItem.htmlContent != currentItem.htmlContent + } + return if (!haveItemsChanged) { DragAndDropSortInteractionError.EMPTY_INPUT - } else + } else { DragAndDropSortInteractionError.VALID + } } /** Implementation of [StateItemViewModel.InteractionItemFactory] for this view model. */ diff --git a/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt index b9aa97a1a1e..2637fdc90dc 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt @@ -1117,6 +1117,18 @@ class StateFragmentTest { } } + @Test + fun testStateFragment_loadDragDropExp_groupingItemsEnablesSubmitButton() { + setUpTestWithLanguageSwitchingFeatureOff() + launchForExploration(TEST_EXPLORATION_ID_4, shouldSavePartialProgress = false).use { + startPlayingExploration() + clickSubmitAnswerButton() + verifySubmitAnswerButtonIsDisabled() + mergeDragAndDropItems(position = 0) + verifySubmitAnswerButtonIsEnabled() + } + } + @Test @RunOn(TestPlatform.ESPRESSO) // TODO(#1612): Enable for Robolectric. fun testStateFragment_loadDragDropExp_retainStateOnConfigurationChange() {