Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add callback 'onStepBegin' #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,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}'")
Comment on lines +204 to +208
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would show a Toast or something in the View just to make sure view interactions do not break. But logs are fine as well 👍

}
}

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 @@ -92,6 +92,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 @@ -122,6 +124,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 @@ -136,6 +141,9 @@ class SurveyView @JvmOverloads constructor(
taskNavigator.previousStep(step) ?: return StepData(
FinishReason.Failed
)

onStepBegin(previousStep)

val newResult = presenter(
Presenter.Transition.SlideFromLeft,
previousStep,
Expand All @@ -151,6 +159,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