@@ -69,18 +69,21 @@ public interface StepperListener {
69
69
70
70
/**
71
71
* Called when all of the steps were completed successfully
72
+ *
72
73
* @param completeButton the complete button that was clicked to complete the flow
73
74
*/
74
75
void onCompleted (View completeButton );
75
76
76
77
/**
77
78
* Called when a verification error occurs for one of the steps
79
+ *
78
80
* @param verificationError verification error
79
81
*/
80
82
void onError (VerificationError verificationError );
81
83
82
84
/**
83
85
* Called when the current step position changes
86
+ *
84
87
* @param newStepPosition new step position
85
88
*/
86
89
void onStepSelected (int newStepPosition );
@@ -125,6 +128,23 @@ public final void goToNextStep() {
125
128
}
126
129
127
130
}
131
+
132
+ public final class OnBackClickedCallback {
133
+
134
+ @ UiThread
135
+ public final void goToPrevStep () {
136
+ if (mCurrentStepPosition <= 0 ) {
137
+ if (mShowBackButtonOnFirstStep ) {
138
+ mListener .onReturn ();
139
+ }
140
+ return ;
141
+ }
142
+ mCurrentStepPosition --;
143
+ onUpdate (mCurrentStepPosition );
144
+ }
145
+
146
+ }
147
+
128
148
private ViewPager mPager ;
129
149
130
150
private Button mBackNavigationButton ;
@@ -143,9 +163,9 @@ public final void goToNextStep() {
143
163
144
164
private ColorStateList mBackButtonColor ;
145
165
146
- private ColorStateList mNextButtonColor ;
166
+ private ColorStateList mNextButtonColor ;
147
167
148
- private ColorStateList mCompleteButtonColor ;
168
+ private ColorStateList mCompleteButtonColor ;
149
169
150
170
@ ColorInt
151
171
private int mUnselectedColor ;
@@ -226,6 +246,7 @@ public void setListener(@NonNull StepperListener listener) {
226
246
227
247
/**
228
248
* Sets the new step adapter and updates the stepper layout based on the new adapter.
249
+ *
229
250
* @param stepAdapter step adapter
230
251
*/
231
252
public void setAdapter (@ NonNull AbstractStepAdapter stepAdapter ) {
@@ -246,7 +267,8 @@ public void run() {
246
267
247
268
/**
248
269
* Sets the new step adapter and updates the stepper layout based on the new adapter.
249
- * @param stepAdapter step adapter
270
+ *
271
+ * @param stepAdapter step adapter
250
272
* @param currentStepPosition the initial step position, must be in the range of the adapter item count
251
273
*/
252
274
public void setAdapter (@ NonNull AbstractStepAdapter stepAdapter , @ IntRange (from = 0 ) int currentStepPosition ) {
@@ -256,6 +278,7 @@ public void setAdapter(@NonNull AbstractStepAdapter stepAdapter, @IntRange(from
256
278
257
279
/**
258
280
* Overrides the default page transformer used in the underlying {@link ViewPager}
281
+ *
259
282
* @param pageTransformer new page transformer
260
283
*/
261
284
public void setPageTransformer (@ Nullable ViewPager .PageTransformer pageTransformer ) {
@@ -277,9 +300,9 @@ public int getTabStepDividerWidth() {
277
300
@ Override
278
301
@ UiThread
279
302
public void onTabClicked (int position ) {
280
- if (position > mCurrentStepPosition ){
303
+ if (position > mCurrentStepPosition ) {
281
304
onNext ();
282
- } else if (position < mCurrentStepPosition ){
305
+ } else if (position < mCurrentStepPosition ) {
283
306
setCurrentStepPosition (position );
284
307
}
285
308
}
@@ -455,14 +478,14 @@ private Step findCurrentStep() {
455
478
}
456
479
457
480
private void onPrevious () {
458
- if (mCurrentStepPosition <= 0 ) {
459
- if (mShowBackButtonOnFirstStep ) {
460
- mListener .onReturn ();
461
- }
462
- return ;
481
+ Step step = findCurrentStep ();
482
+
483
+ OnBackClickedCallback onBackClickedCallback = new OnBackClickedCallback ();
484
+ if (step instanceof BlockingStep ) {
485
+ ((BlockingStep ) step ).onBackClicked (onBackClickedCallback );
486
+ } else {
487
+ onBackClickedCallback .goToPrevStep ();
463
488
}
464
- mCurrentStepPosition --;
465
- onUpdate (mCurrentStepPosition );
466
489
}
467
490
468
491
@ UiThread
@@ -474,7 +497,7 @@ private void onNext() {
474
497
}
475
498
OnNextClickedCallback onNextClickedCallback = new OnNextClickedCallback ();
476
499
if (step instanceof BlockingStep ) {
477
- ((BlockingStep )step ).onNextClicked (onNextClickedCallback );
500
+ ((BlockingStep ) step ).onNextClicked (onNextClickedCallback );
478
501
} else {
479
502
onNextClickedCallback .goToNextStep ();
480
503
}
0 commit comments