Skip to content

Commit

Permalink
Merge branch 'develop' into technical-analytics-milestone-3
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmurerwa authored Apr 7, 2024
2 parents 4106575 + 9e8553c commit 78dc3e1
Show file tree
Hide file tree
Showing 13 changed files with 729 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.core.view.doOnPreDraw
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.Transformations
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityScope
Expand Down Expand Up @@ -297,11 +298,7 @@ class ExplorationActivityPresenter @Inject constructor(
}
is AsyncResult.Success -> {
oppiaLogger.d("ExplorationActivity", "Successfully stopped exploration")
if (isCompletion) {
maybeShowSurveyDialog(profileId, topicId)
} else {
backPressActivitySelector()
}
maybeShowSurveyDialog(profileId, topicId)
}
}
}
Expand Down Expand Up @@ -528,42 +525,48 @@ class ExplorationActivityPresenter @Inject constructor(
}

private fun maybeShowSurveyDialog(profileId: ProfileId, topicId: String) {
surveyGatingController.maybeShowSurvey(profileId, topicId).toLiveData()
.observe(
activity
) { gatingResult ->
when (gatingResult) {
is AsyncResult.Pending -> {
oppiaLogger.d("ExplorationActivity", "A gating decision is pending")
}
is AsyncResult.Failure -> {
oppiaLogger.e(
"ExplorationActivity",
"Failed to retrieve gating decision",
gatingResult.error
)
backPressActivitySelector()
}
is AsyncResult.Success -> {
if (gatingResult.value) {
val dialogFragment =
SurveyWelcomeDialogFragment.newInstance(
profileId,
topicId,
explorationId,
SURVEY_QUESTIONS
)
val transaction = activity.supportFragmentManager.beginTransaction()
transaction
.add(dialogFragment, TAG_SURVEY_WELCOME_DIALOG)
.addToBackStack(null)
.commit()
} else {
val liveData = surveyGatingController.maybeShowSurvey(profileId, topicId).toLiveData()
liveData.observe(
activity,
object : Observer<AsyncResult<Boolean>> {
override fun onChanged(gatingResult: AsyncResult<Boolean>?) {
when (gatingResult) {
is AsyncResult.Pending -> {
oppiaLogger.d("ExplorationActivity", "A gating decision is pending")
}
is AsyncResult.Failure -> {
oppiaLogger.e(
"ExplorationActivity",
"Failed to retrieve gating decision",
gatingResult.error
)
backPressActivitySelector()
}
is AsyncResult.Success -> {
if (gatingResult.value) {
val dialogFragment =
SurveyWelcomeDialogFragment.newInstance(
profileId,
topicId,
explorationId,
SURVEY_QUESTIONS
)
val transaction = activity.supportFragmentManager.beginTransaction()
transaction
.add(dialogFragment, TAG_SURVEY_WELCOME_DIALOG)
.addToBackStack(null)
.commit()

// Changes to underlying DataProviders will update the gating result.
liveData.removeObserver(this)
} else {
backPressActivitySelector()
}
}
}
}
}
)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ class StateFragmentPresenter @Inject constructor(
fun onReturnToTopicButtonClicked() {
hideKeyboard()
markExplorationCompleted()
maybeShowSurveyDialog(profileId, topicId)
}

private fun showOrHideAudioByState(state: State) {
Expand Down Expand Up @@ -455,13 +454,17 @@ class StateFragmentPresenter @Inject constructor(
fun getExplorationCheckpointState() = explorationCheckpointState

private fun markExplorationCompleted() {
storyProgressController.recordCompletedChapter(
val markStoryCompletedLivedata = storyProgressController.recordCompletedChapter(
profileId,
topicId,
storyId,
explorationId,
oppiaClock.getCurrentTimeMs()
)
).toLiveData()

// Only check gating result when the previous operation has completed because gating depends on
// result of saving the time spent in the exploration, at the end of the exploration.
markStoryCompletedLivedata.observe(fragment, { maybeShowSurveyDialog(profileId, topicId) })
}

private fun showHintsAndSolutions(helpIndex: HelpIndex, isCurrentStatePendingState: Boolean) {
Expand Down Expand Up @@ -535,44 +538,43 @@ class StateFragmentPresenter @Inject constructor(
}

private fun maybeShowSurveyDialog(profileId: ProfileId, topicId: String) {
surveyGatingController.maybeShowSurvey(profileId, topicId).toLiveData()
.observe(
activity,
{ gatingResult ->
when (gatingResult) {
is AsyncResult.Pending -> {
oppiaLogger.d("StateFragment", "A gating decision is pending")
}
is AsyncResult.Failure -> {
oppiaLogger.e(
"StateFragment",
"Failed to retrieve gating decision",
gatingResult.error
)
surveyGatingController.maybeShowSurvey(profileId, topicId).toLiveData().observe(
activity,
{ gatingResult ->
when (gatingResult) {
is AsyncResult.Pending -> {
oppiaLogger.d("StateFragment", "A gating decision is pending")
}
is AsyncResult.Failure -> {
oppiaLogger.e(
"StateFragment",
"Failed to retrieve gating decision",
gatingResult.error
)
(activity as StopStatePlayingSessionWithSavedProgressListener)
.deleteCurrentProgressAndStopSession(isCompletion = true)
}
is AsyncResult.Success -> {
if (gatingResult.value) {
val dialogFragment =
SurveyWelcomeDialogFragment.newInstance(
profileId,
topicId,
explorationId,
SURVEY_QUESTIONS
)
val transaction = activity.supportFragmentManager.beginTransaction()
transaction
.add(dialogFragment, TAG_SURVEY_WELCOME_DIALOG)
.commitNow()
} else {
(activity as StopStatePlayingSessionWithSavedProgressListener)
.deleteCurrentProgressAndStopSession(isCompletion = true)
}
is AsyncResult.Success -> {
if (gatingResult.value) {
val dialogFragment =
SurveyWelcomeDialogFragment.newInstance(
profileId,
topicId,
explorationId,
SURVEY_QUESTIONS
)
val transaction = activity.supportFragmentManager.beginTransaction()
transaction
.add(dialogFragment, TAG_SURVEY_WELCOME_DIALOG)
.commitNow()
} else {
(activity as StopStatePlayingSessionWithSavedProgressListener)
.deleteCurrentProgressAndStopSession(isCompletion = true)
}
}
}
}
)
}
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.oppia.android.app.player.state.testing
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityScope
import org.oppia.android.app.model.ProfileId
Expand Down Expand Up @@ -98,7 +97,7 @@ class StateFragmentTestActivityPresenter @Inject constructor(
}
startPlayingProvider.toLiveData().observe(
activity,
Observer<AsyncResult<Any?>> { result ->
{ result ->
when (result) {
is AsyncResult.Pending -> oppiaLogger.d(TEST_ACTIVITY_TAG, "Loading exploration")
is AsyncResult.Failure ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class SurveyWelcomeDialogFragmentPresenter @Inject constructor(
}

profileManagementController.updateSurveyLastShownTimestamp(profileId)

logSurveyPopUpShownEvent(explorationId, topicId, profileId)

return binding.root
Expand Down
Loading

0 comments on commit 78dc3e1

Please sign in to comment.