Skip to content

Commit

Permalink
Fix #3325: Domain layer mechanism for saving checkpoints. (#3408)
Browse files Browse the repository at this point in the history
* add controller and tests

* NIT

* added tests for constant

* moved enum to a different file

* fixed lint

* fixed comments

* saving

* added mech to save checkpoints

* lint fix

* added module to UI-tests

* added exploration storage module to ui tests

* nit

* added module in missed files

* lint fix

* fixed saving

* lint fix

* nit changes

* nit changes

* fixed function names

* fixed failing domain tests and some nits

* completed saving approach

* added more tests and fixed failing tests

* checkpointing disabled by default

* fix

* improved mechanism to save checkpoints

* nit changes

* nit

* nit changes

* suppressed ExperimantalCoroutinesApi warning

* nit

* nit

* nit

* nit

* nit

* nit

* removed commit

* removed visibleForTesting

* nit

* Revert "removed visibleForTesting"

This reverts commit 7963300.

* added TODO for the issue

* nit

* added missing module in develop

* nit

* reverted changes back in StateDeck.kt

* fixed failing tests

* added more tests

* changed approach to stop exploration and nit changes

* nit

* nit

* nit

* nits in comments

* applied suggestion in stateDeck

* nit
  • Loading branch information
MaskedCarrot authored Jul 16, 2021
1 parent 984a19c commit c325fc8
Show file tree
Hide file tree
Showing 25 changed files with 1,933 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class RecentlyPlayedFragmentPresenter @Inject constructor(
private val topicListController: TopicListController,
@StoryHtmlParserEntityType private val entityType: String
) {
// TODO(#3479): Enable checkpointing once mechanism to resume exploration with checkpoints is
// implemented.

private val routeToExplorationListener = activity as RouteToExplorationListener
private var internalProfileId: Int = -1
Expand Down Expand Up @@ -218,7 +220,11 @@ class RecentlyPlayedFragmentPresenter @Inject constructor(

private fun playExploration(topicId: String, storyId: String, explorationId: String) {
explorationDataController.startPlayingExploration(
explorationId
internalProfileId,
topicId,
storyId,
explorationId,
shouldSavePartialProgress = false
).observe(
fragment,
Observer<AsyncResult<Any?>> { result ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,6 @@ class ExplorationFragment : InjectableFragment() {
}

fun dismissConceptCard() = explorationFragmentPresenter.dismissConceptCard()

fun getExplorationCheckpointState() = explorationFragmentPresenter.getExplorationCheckpointState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class ExplorationFragmentPresenter @Inject constructor(

fun dismissConceptCard() = getStateFragment()?.dismissConceptCard()

fun getExplorationCheckpointState() = getStateFragment()?.getExplorationCheckpointState()

private fun getStateFragment(): StateFragment? {
return fragment
.childFragmentManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,6 @@ class StateFragment :
fun revealSolution() = stateFragmentPresenter.revealSolution()

fun dismissConceptCard() = stateFragmentPresenter.dismissConceptCard()

fun getExplorationCheckpointState() = stateFragmentPresenter.getExplorationCheckpointState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import nl.dionsegijn.konfetti.KonfettiView
import org.oppia.android.R
import org.oppia.android.app.fragment.FragmentScope
import org.oppia.android.app.model.AnswerOutcome
import org.oppia.android.app.model.CheckpointState
import org.oppia.android.app.model.EphemeralState
import org.oppia.android.app.model.HelpIndex
import org.oppia.android.app.model.Hint
Expand Down Expand Up @@ -91,6 +92,8 @@ class StateFragmentPresenter @Inject constructor(
explorationProgressController.getCurrentState().toLiveData()
}

private var explorationCheckpointState: CheckpointState = CheckpointState.CHECKPOINT_UNSAVED

fun handleCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down Expand Up @@ -317,6 +320,7 @@ class StateFragmentPresenter @Inject constructor(
}

val ephemeralState = result.getOrThrow()
explorationCheckpointState = ephemeralState.checkpointState
val shouldSplit = splitScreenManager.shouldSplitScreen(ephemeralState.state.interaction.id)
if (shouldSplit) {
viewModel.isSplitView.set(true)
Expand Down Expand Up @@ -524,6 +528,9 @@ class StateFragmentPresenter @Inject constructor(
}
}

/** Returns the checkpoint state for the current exploration. */
fun getExplorationCheckpointState() = explorationCheckpointState

private fun markExplorationAsRecentlyPlayed() {
storyProgressController.recordRecentlyPlayedChapter(
profileId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ class StateFragmentTestActivityPresenter @Inject constructor(
// TODO(#59): With proper test ordering & isolation, this hacky clean-up should not be necessary since each test
// should run with a new application instance.
explorationDataController.stopPlayingExploration()
explorationDataController.startPlayingExploration(explorationId)
explorationDataController.startPlayingExploration(
profileId,
topicId,
storyId,
explorationId,
shouldSavePartialProgress = false
)
.observe(
activity,
Observer<AsyncResult<Any?>> { result ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class StoryChapterSummaryViewModel(
val chapterSummary: ChapterSummary,
val entityType: String
) : StoryItemViewModel() {
// TODO(#3479): Enable checkpointing once mechanism to resume exploration with checkpoints is
// implemented.

val explorationId: String = chapterSummary.explorationId
val name: String = chapterSummary.name
val summary: String = chapterSummary.summary
Expand All @@ -33,7 +36,11 @@ class StoryChapterSummaryViewModel(
fun onExplorationClicked() {
explorationDataController.stopPlayingExploration()
explorationDataController.startPlayingExploration(
explorationId
internalProfileId,
topicId,
storyId,
explorationId,
shouldSavePartialProgress = false
).observe(
fragment,
Observer<AsyncResult<Any?>> { result ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ class ExplorationTestActivityPresenter @Inject constructor(
private fun playExplorationButton() {
explorationDataController.stopPlayingExploration()
explorationDataController.startPlayingExploration(
EXPLORATION_ID
INTERNAL_PROFILE_ID,
TOPIC_ID,
STORY_ID,
EXPLORATION_ID,
shouldSavePartialProgress = false
).observe(
activity,
Observer<AsyncResult<Any?>> { result ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class TopicLessonsFragmentPresenter @Inject constructor(
private val oppiaLogger: OppiaLogger,
private val explorationDataController: ExplorationDataController,
) {
// TODO(#3479): Enable checkpointing once mechanism to resume exploration with checkpoints is
// implemented.

private val routeToExplorationListener = activity as RouteToExplorationListener
private val routeToStoryListener = activity as RouteToStoryListener

Expand Down Expand Up @@ -202,7 +205,11 @@ class TopicLessonsFragmentPresenter @Inject constructor(
backflowScreen: Int?
) {
explorationDataController.startPlayingExploration(
explorationId
internalProfileId,
topicId,
storyId,
explorationId,
shouldSavePartialProgress = false
).observe(
fragment,
Observer<AsyncResult<Any?>> { result ->
Expand Down
Loading

0 comments on commit c325fc8

Please sign in to comment.