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 #2476: Fixed Revealing Second hint due to orientation change [Blocked on #2572] #2557

Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
98099e2
Fixed Revealing Second hint
FareesHussain Jan 24, 2021
eb761b7
ktlint fix
FareesHussain Jan 24, 2021
54c9e9e
making HintHandler life cycle aware
FareesHussain Feb 5, 2021
dfb1007
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Feb 5, 2021
4dcedf1
ktlint fix
FareesHussain Feb 5, 2021
96b3c48
NIT fix
FareesHussain Feb 5, 2021
7674576
Using proto in bundle
FareesHussain Feb 6, 2021
0a566c3
Added single proto for to handle the hint related configuration changes.
FareesHussain Feb 10, 2021
e8789f5
Ktlint fix
FareesHussain Feb 10, 2021
e601ff9
protobuf fix
FareesHussain Feb 10, 2021
4ca52dc
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Feb 10, 2021
b63e7ce
Resolving requested changes
FareesHussain Feb 11, 2021
376a9bb
Resolving requested changes
FareesHussain Feb 12, 2021
1c89e04
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Feb 12, 2021
cae5567
Using defaults for the StatePlayerSavedHintState
FareesHussain Feb 12, 2021
39814de
Resolving requested changes
FareesHussain Feb 13, 2021
782cc3d
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Feb 13, 2021
aae3817
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
FareesHussain Feb 16, 2021
b8bc619
Resolving requested changes
FareesHussain Feb 17, 2021
e3d6cb5
Merge branch 'develop' into avoid-revealing-second-hint-on-config-change
BenHenning Feb 24, 2021
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 @@ -82,10 +82,16 @@ class StateFragment :
internalProfileId,
topicId,
storyId,
explorationId
explorationId,
savedInstanceState
)
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
stateFragmentPresenter.handleOnSaveInstanceState(outState)
}

override fun onAnswerReadyForSubmission(answer: UserAnswer) {
stateFragmentPresenter.handleAnswerReadyForSubmission(answer)
}
Expand Down
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 @@ -88,13 +89,18 @@ class StateFragmentPresenter @Inject constructor(
internalProfileId: Int,
topicId: String,
storyId: String,
explorationId: String
explorationId: String,
savedInstanceState: Bundle?
): View? {
profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
this.topicId = topicId
this.storyId = storyId
this.explorationId = explorationId

savedInstanceState?.let {
recyclerViewAssembler.restoreState(savedInstanceState)
}

binding = StateFragmentBinding.inflate(
inflater,
container,
Expand Down Expand Up @@ -145,6 +151,10 @@ class StateFragmentPresenter @Inject constructor(
return binding.root
}

fun handleOnSaveInstanceState(bundle: Bundle) {
recyclerViewAssembler.saveState(bundle)
}
BenHenning marked this conversation as resolved.
Show resolved Hide resolved

fun handleAnswerReadyForSubmission(answer: UserAnswer) {
// An interaction has indicated that an answer is ready for submission.
handleSubmitAnswer(answer)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.oppia.android.app.player.state

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.animation.AccelerateInterpolator
Expand Down Expand Up @@ -92,6 +93,10 @@ private typealias AudioUiManagerRetriever = () -> AudioUiManager?

/** The fragment tag corresponding to the concept card dialog fragment. */
const val CONCEPT_CARD_DIALOG_FRAGMENT_TAG = "CONCEPT_CARD_FRAGMENT"
const val KEY_TRACKED_WRONG_ANSWER_COUNT = "TRACKED_WRONG_ANSWER_COUNT"
const val KEY_PREVIOUS_HELP_INDEX = "PREVIOUS_HELP_INDEX"
const val KEY_HINT_SEQUENCE_NUMBER = "HINT_SEQUENCE_NUMBER"
const val KEY_IS_HINT_VISIBLE_IN_LATEST_STATE = "IS_HINT_VISIBLE_IN_LATEST_STATE"

/**
* An assembler for generating the list of view models to bind to the state player recycler view.
Expand Down Expand Up @@ -150,6 +155,20 @@ class StatePlayerRecyclerViewAssembler private constructor(

val isCorrectAnswer = ObservableField<Boolean>(false)

fun saveState(bundle: Bundle) {
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
bundle.putInt(KEY_TRACKED_WRONG_ANSWER_COUNT, hintHandler.trackedWrongAnswerCount)
// bundle.putSerializable(KEY_PREVIOUS_HELP_INDEX, hintHandler.previousHelpIndex as Serializable)
FareesHussain marked this conversation as resolved.
Show resolved Hide resolved
bundle.putInt(KEY_HINT_SEQUENCE_NUMBER, hintHandler.hintSequenceNumber)
bundle.putBoolean(KEY_IS_HINT_VISIBLE_IN_LATEST_STATE, hintHandler.isHintVisibleInLatestState)
}

fun restoreState(bundle: Bundle) {
hintHandler.trackedWrongAnswerCount = bundle.getInt(KEY_TRACKED_WRONG_ANSWER_COUNT)
// hintHandler.previousHelpIndex = bundle.get(KEY_PREVIOUS_HELP_INDEX) as HelpIndex
hintHandler.hintSequenceNumber = bundle.getInt(KEY_HINT_SEQUENCE_NUMBER)
hintHandler.isHintVisibleInLatestState = bundle.getBoolean(KEY_IS_HINT_VISIBLE_IN_LATEST_STATE)
}

private val lifecycleSafeTimerFactory = LifecycleSafeTimerFactory(backgroundCoroutineDispatcher)

private val hintHandler = HintHandler(
Expand Down Expand Up @@ -1309,10 +1328,10 @@ class StatePlayerRecyclerViewAssembler private constructor(
private val delayShowAdditionalHintsMs: Long,
private val delayShowAdditionalHintsFromWrongAnswerMs: Long
) {
private var trackedWrongAnswerCount = 0
private var previousHelpIndex: HelpIndex = HelpIndex.getDefaultInstance()
private var hintSequenceNumber = 0
private var isHintVisibleInLatestState = false
var trackedWrongAnswerCount = 0
var previousHelpIndex: HelpIndex = HelpIndex.getDefaultInstance()
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
var hintSequenceNumber = 0
var isHintVisibleInLatestState = false
BenHenning marked this conversation as resolved.
Show resolved Hide resolved

/** Resets this handler to prepare it for a new state, cancelling any pending hints. */
fun reset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.test.espresso.action.GeneralLocation
import androidx.test.espresso.action.Press
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.closeSoftKeyboard
import androidx.test.espresso.action.ViewActions.pressBack
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions.scrollToHolder
Expand Down Expand Up @@ -103,6 +104,7 @@ import org.oppia.android.domain.oppialogger.LogStorageModule
import org.oppia.android.domain.oppialogger.loguploader.LogUploadWorkerModule
import org.oppia.android.domain.oppialogger.loguploader.WorkManagerConfigurationModule
import org.oppia.android.domain.question.QuestionModule
import org.oppia.android.domain.topic.FRACTIONS_EXPLORATION_ID_0
import org.oppia.android.domain.topic.FRACTIONS_EXPLORATION_ID_1
import org.oppia.android.domain.topic.PrimeTopicAssetsControllerModule
import org.oppia.android.domain.topic.TEST_EXPLORATION_ID_0
Expand Down Expand Up @@ -905,6 +907,99 @@ class StateFragmentTest {
}
}

@Test
fun testStateFragment_forTwoWrongAnswers_revealHint() {
FareesHussain marked this conversation as resolved.
Show resolved Hide resolved
launchForExploration(FRACTIONS_EXPLORATION_ID_0).use {
startPlayingExploration()
clickContinueInteractionButton()
clickContinueInteractionButton()
clickContinueInteractionButton()
selectMultipleChoiceOption(optionPosition = 2)
clickContinueNavigationButton()
selectMultipleChoiceOption(optionPosition = 1)
clickContinueNavigationButton()
selectMultipleChoiceOption(optionPosition = 1)
clickContinueNavigationButton()
onView(withId(R.id.hints_and_solution_fragment_container)).check(
matches(
not(isDisplayed())
)
)
selectMultipleChoiceOption(optionPosition = 1)
selectMultipleChoiceOption(optionPosition = 1)
onView(withId(R.id.hints_and_solution_fragment_container)).check(
matches(
isDisplayed()
)
)
}
}

@Test
fun testStateFragment_forTwoWrongAnswers_revealHint_dotDisappears() {
launchForExploration(FRACTIONS_EXPLORATION_ID_0).use {
startPlayingExploration()
clickContinueInteractionButton()
clickContinueInteractionButton()
clickContinueInteractionButton()
selectMultipleChoiceOption(optionPosition = 2)
clickContinueNavigationButton()
selectMultipleChoiceOption(optionPosition = 1)
clickContinueNavigationButton()
selectMultipleChoiceOption(optionPosition = 1)
clickContinueNavigationButton()

selectMultipleChoiceOption(optionPosition = 1)
selectMultipleChoiceOption(optionPosition = 1)
onView(withId(R.id.dot_hint)).check(
matches(
isDisplayed()
)
)
onView(withId(R.id.hints_and_solution_fragment_container)).perform(click())
onView(withId(R.id.reveal_hint_button)).perform(click())
onView(isRoot()).perform(pressBack())
onView(withId(R.id.dot_hint)).check(
matches(
not(isDisplayed())
)
)
}
}

@Test
fun testStateFragment_forTwoWrongAnswers_revealHint_configurationChange_newHintNotRevealed() {
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
launchForExploration(FRACTIONS_EXPLORATION_ID_0).use {
startPlayingExploration()
clickContinueInteractionButton()
clickContinueInteractionButton()
clickContinueInteractionButton()
selectMultipleChoiceOption(optionPosition = 2)
clickContinueNavigationButton()
selectMultipleChoiceOption(optionPosition = 1)
clickContinueNavigationButton()
selectMultipleChoiceOption(optionPosition = 1)
clickContinueNavigationButton()
BenHenning marked this conversation as resolved.
Show resolved Hide resolved

selectMultipleChoiceOption(optionPosition = 1)
selectMultipleChoiceOption(optionPosition = 1)
onView(withId(R.id.dot_hint)).check(
matches(
isDisplayed()
)
)
onView(withId(R.id.hints_and_solution_fragment_container)).perform(click())
onView(withId(R.id.reveal_hint_button)).perform(click())
onView(isRoot()).perform(pressBack())
rotateToLandscape()
onView(withId(R.id.dot_hint)).check(
matches(
not(isDisplayed())
)
)
}
}

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