Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1592: Previous responses header collapsed state not retained across landscape changes #5685

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,11 @@ class StateFragment :
STATE_FRAGMENT_STATE_KEY,
stateFragmentPresenter.getUserAnswerState()
)
stateFragmentPresenter.saveExpandedState(outState)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
stateFragmentPresenter.restoreExpandedState(savedInstanceState)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.oppia.android.app.player.state

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -617,4 +618,14 @@ class StateFragmentPresenter @Inject constructor(
SurveyQuestionName.NPS
)
}

/** Saves the state of the header. */
fun saveExpandedState(outState: Bundle) {
recyclerViewAssembler.saveExpandedState(outState)
}

/** Restore the state of the header. */
fun restoreExpandedState(savedInstanceState: Bundle?) {
recyclerViewAssembler.restoreExpandedState(savedInstanceState)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.oppia.android.app.player.state

import android.app.Application
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.animation.AccelerateInterpolator
Expand Down Expand Up @@ -111,6 +112,7 @@ private typealias AudioUiManagerRetriever = () -> AudioUiManager?

private const val CONGRATULATIONS_TEXT_VIEW_FADE_MILLIS: Long = 600
private const val CONGRATULATIONS_TEXT_VIEW_VISIBLE_MILLIS: Long = 800
private const val HAS_PREVIOUS_RESPONSES_EXPANDED_KEY = "hasPreviousResponsesExpanded"

/**
* An assembler for generating the list of view models to bind to the state player recycler view.
Expand Down Expand Up @@ -1548,4 +1550,15 @@ class StatePlayerRecyclerViewAssembler private constructor(
}
}
}

/** Saves the expanded state to a Bundle. */
fun saveExpandedState(outState: Bundle) {
outState.putBoolean(HAS_PREVIOUS_RESPONSES_EXPANDED_KEY, hasPreviousResponsesExpanded)
}

/** Restores the expanded state from a Bundle. */
fun restoreExpandedState(savedInstanceState: Bundle?) {
hasPreviousResponsesExpanded =
savedInstanceState?.getBoolean(HAS_PREVIOUS_RESPONSES_EXPANDED_KEY, false) ?: false
}
Comment on lines +1555 to +1563
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have moved to using protos only for arguments.(We refactored all usages of getInt, Boolean, String etc). PTAL at

if (savedInstanceState != null) {
val stateArgs = savedInstanceState.getProto(
TOPIC_LESSONS_FRAGMENT_STATE_KEY,
TopicLessonsFragmentStateBundle.getDefaultInstance()
)
currentExpandedChapterListIndex =
stateArgs?.currentExpandedChapterListIndex ?: -1
if (currentExpandedChapterListIndex == -1) {
currentExpandedChapterListIndex = null
}
isDefaultStoryExpanded = stateArgs?.isDefaultStoryExpanded ?: false
}
for reference. The protos are created in arguments.proto.

}
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,56 @@ class StateFragmentLocalTest {
}
}

@Test
fun testStateFragment_previousResponsesExpanded_retainedOnRotation() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a duplicate test for the collapsed state.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

launchForExploration(FRACTIONS_EXPLORATION_ID_1).use { _ ->
startPlayingExploration()
playThroughFractionsState1()

submitTwoWrongAnswersForFractionsState2()

onView(withId(R.id.state_recycler_view)).perform(scrollToViewType(PREVIOUS_RESPONSES_HEADER))
onView(withId(R.id.previous_response_header)).perform(click())
testCoroutineDispatchers.runCurrent()

onView(withId(R.id.state_recycler_view))
.check(matchesChildren(withId(R.id.submitted_answer_container), times = 2))

// Rotate device to trigger configuration change
onView(isRoot()).perform(orientationLandscape())
testCoroutineDispatchers.runCurrent()

// Verify expanded state is retained after rotation
onView(withId(R.id.previous_response_header)).check(matches(isDisplayed()))
onView(withId(R.id.state_recycler_view))
.check(matchesChildren(withId(R.id.submitted_answer_container), times = 2))
}
}

@Test
fun testStateFragment_previousResponsesCollapsed_remainsCollapsedOnRotation() {
launchForExploration(FRACTIONS_EXPLORATION_ID_1).use { _ ->
startPlayingExploration()
playThroughFractionsState1()

submitTwoWrongAnswersForFractionsState2()

onView(withId(R.id.state_recycler_view)).perform(scrollToViewType(PREVIOUS_RESPONSES_HEADER))
testCoroutineDispatchers.runCurrent()

onView(withId(R.id.state_recycler_view))
.check(matchesChildren(withId(R.id.submitted_answer_container), times = 1))

// Rotate device to trigger configuration change
onView(isRoot()).perform(orientationLandscape())
testCoroutineDispatchers.runCurrent()

// Verify the header remains collapsed after rotation
onView(withId(R.id.state_recycler_view))
.check(matchesChildren(withId(R.id.submitted_answer_container), times = 1))
}
}

@Test
fun testStateFragment_stateWithoutHints_wait60s_noHintIsAvailable() {
launchForExploration(FRACTIONS_EXPLORATION_ID_1).use {
Expand Down
Loading