From 9924fc101558a45543e65aaa04d0dc7f774bbf29 Mon Sep 17 00:00:00 2001 From: Lukas Roedl Date: Thu, 26 Nov 2020 15:11:18 +0100 Subject: [PATCH] Add callback onStepBegin --- .../quickbirdstudios/example/ui/main/MainActivity.kt | 10 ++++++++++ .../com.quickbirdstudios.surveykit/survey/Survey.kt | 1 + .../survey/SurveyView.kt | 11 +++++++++++ 3 files changed, 22 insertions(+) diff --git a/example/src/main/java/com/quickbirdstudios/example/ui/main/MainActivity.kt b/example/src/main/java/com/quickbirdstudios/example/ui/main/MainActivity.kt index 04cd3b4..b879390 100644 --- a/example/src/main/java/com/quickbirdstudios/example/ui/main/MainActivity.kt +++ b/example/src/main/java/com/quickbirdstudios/example/ui/main/MainActivity.kt @@ -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), diff --git a/survey/src/main/java/com.quickbirdstudios.surveykit/survey/Survey.kt b/survey/src/main/java/com.quickbirdstudios.surveykit/survey/Survey.kt index 436b015..ad8e5e5 100644 --- a/survey/src/main/java/com.quickbirdstudios.surveykit/survey/Survey.kt +++ b/survey/src/main/java/com.quickbirdstudios.surveykit/survey/Survey.kt @@ -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 diff --git a/survey/src/main/java/com.quickbirdstudios.surveykit/survey/SurveyView.kt b/survey/src/main/java/com.quickbirdstudios.surveykit/survey/SurveyView.kt index 5adb539..7465434 100644 --- a/survey/src/main/java/com.quickbirdstudios.surveykit/survey/SurveyView.kt +++ b/survey/src/main/java/com.quickbirdstudios.surveykit/survey/SurveyView.kt @@ -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 = { _, _ -> } @@ -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() @@ -135,6 +140,9 @@ class SurveyView @JvmOverloads constructor( taskNavigator.previousStep(step) ?: return StepData( FinishReason.Failed ) + + onStepBegin(previousStep) + val newResult = presenter( Presenter.Transition.SlideFromLeft, previousStep, @@ -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()