Skip to content

Commit

Permalink
Add callback onStepBegin
Browse files Browse the repository at this point in the history
  • Loading branch information
roedll committed Nov 26, 2020
1 parent 2980dc2 commit 9924fc1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ class MainActivity : AppCompatActivity() {
}
}

surveyView.onStepBegin = { step ->
when (step) {
is QuestionStep -> {
Log.w ("ASDF", "step '${step?.id}': ${step.title} (${step.text})")
}
else ->
Log.w ("ASDF", "step '${step?.id}'")
}
}

val configuration = SurveyTheme(
themeColorDark = ContextCompat.getColor(this, R.color.cyan_dark),
themeColor = ContextCompat.getColor(this, R.color.cyan_normal),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.quickbirdstudios.surveykit.result.TaskResult
import com.quickbirdstudios.surveykit.steps.Step

internal interface Survey {
var onStepBegin: (Step?) -> Unit
var onStepResult: (Step?, StepResult?) -> Unit
var onSurveyFinish: (TaskResult, FinishReason) -> Unit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class SurveyView @JvmOverloads constructor(

//region Overrides

override var onStepBegin: (Step?) -> Unit = { _ -> }

override var onStepResult: (Step?, StepResult?) -> Unit = { _, _ -> }

override var onSurveyFinish: (TaskResult, FinishReason) -> Unit = { _, _ -> }
Expand Down Expand Up @@ -121,6 +123,9 @@ class SurveyView @JvmOverloads constructor(
val newStep = taskNavigator.nextStep(step, result) ?: return StepData(
FinishReason.Completed
)

onStepBegin(newStep)

val newResult = presenter(
Presenter.Transition.SlideFromRight, newStep, resultGatherer.retrieve(newStep.id)
).storeResult()
Expand All @@ -135,6 +140,9 @@ class SurveyView @JvmOverloads constructor(
taskNavigator.previousStep(step) ?: return StepData(
FinishReason.Failed
)

onStepBegin(previousStep)

val newResult = presenter(
Presenter.Transition.SlideFromLeft,
previousStep,
Expand All @@ -150,6 +158,9 @@ class SurveyView @JvmOverloads constructor(
val newStep = taskNavigator.nextStep(step) ?: return StepData(
FinishReason.Completed
)

onStepBegin(newStep)

val newResult = presenter(
Presenter.Transition.SlideFromRight, newStep, resultGatherer.retrieve(newStep.id)
).storeResult()
Expand Down

0 comments on commit 9924fc1

Please sign in to comment.