Skip to content

Commit

Permalink
Shared: Send step viewed request after feature destroying (#1098)
Browse files Browse the repository at this point in the history
^ALTAPPS-1297
  • Loading branch information
ivan-magda authored Jul 5, 2024
1 parent 54c0160 commit 5b64552
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.hyperskill.app.step.presentation.StepFeature.InternalAction
import org.hyperskill.app.step.presentation.StepFeature.Message
import org.hyperskill.app.step.presentation.StepFeature.ViewState
import org.hyperskill.app.step.presentation.StepReducer
import org.hyperskill.app.step.presentation.ViewStepActionDispatcher
import org.hyperskill.app.step.view.mapper.StepViewStateMapper
import org.hyperskill.app.step_completion.domain.flow.StepCompletedFlow
import org.hyperskill.app.step_completion.presentation.StepCompletionActionDispatcher
Expand Down Expand Up @@ -88,5 +89,6 @@ internal object StepFeatureBuilder {
.wrapWithAnalyticLogger(analyticInteractor) {
(it as? InternalAction.LogAnalyticEvent)?.analyticEvent
}
.wrapWithActionDispatcher(ViewStepActionDispatcher(stepInteractor))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ internal class StepActionDispatcher(
when (action) {
is InternalAction.FetchStep ->
handleFetchStepAction(action, ::onNewMessage)
is InternalAction.ViewStep ->
stepInteractor.viewStep(action.stepId, action.stepContext)
is InternalAction.UpdateNextLearningActivityState ->
handleUpdateNextLearningActivityStateAction(action)
is InternalAction.StartSolvingTimer ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.hyperskill.app.step.presentation

import kotlinx.coroutines.CompletableJob
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import org.hyperskill.app.step.domain.interactor.StepInteractor
import ru.nobird.app.presentation.redux.dispatcher.ActionDispatcher

internal class ViewStepActionDispatcher(
private val stepInteractor: StepInteractor
) : ActionDispatcher<StepFeature.Action, StepFeature.Message> {

private val coroutineScope: CoroutineScope =
CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)

private var isCancelled: Boolean = false

override fun handleAction(action: StepFeature.Action) {
if (!isCancelled && action is StepFeature.InternalAction.ViewStep) {
coroutineScope.launch {
stepInteractor.viewStep(action.stepId, action.stepContext)
}
}
}

override fun setListener(listener: (message: StepFeature.Message) -> Unit) {
// no op
}

override fun cancel() {
isCancelled = true
(coroutineScope.coroutineContext[Job] as? CompletableJob)?.complete()
}
}

0 comments on commit 5b64552

Please sign in to comment.