@@ -69,18 +69,21 @@ public interface StepperListener {
6969
7070 /**
7171 * Called when all of the steps were completed successfully
72+ *
7273 * @param completeButton the complete button that was clicked to complete the flow
7374 */
7475 void onCompleted (View completeButton );
7576
7677 /**
7778 * Called when a verification error occurs for one of the steps
79+ *
7880 * @param verificationError verification error
7981 */
8082 void onError (VerificationError verificationError );
8183
8284 /**
8385 * Called when the current step position changes
86+ *
8487 * @param newStepPosition new step position
8588 */
8689 void onStepSelected (int newStepPosition );
@@ -125,6 +128,23 @@ public final void goToNextStep() {
125128 }
126129
127130 }
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+
128148 private ViewPager mPager ;
129149
130150 private Button mBackNavigationButton ;
@@ -143,9 +163,9 @@ public final void goToNextStep() {
143163
144164 private ColorStateList mBackButtonColor ;
145165
146- private ColorStateList mNextButtonColor ;
166+ private ColorStateList mNextButtonColor ;
147167
148- private ColorStateList mCompleteButtonColor ;
168+ private ColorStateList mCompleteButtonColor ;
149169
150170 @ ColorInt
151171 private int mUnselectedColor ;
@@ -226,6 +246,7 @@ public void setListener(@NonNull StepperListener listener) {
226246
227247 /**
228248 * Sets the new step adapter and updates the stepper layout based on the new adapter.
249+ *
229250 * @param stepAdapter step adapter
230251 */
231252 public void setAdapter (@ NonNull AbstractStepAdapter stepAdapter ) {
@@ -246,7 +267,8 @@ public void run() {
246267
247268 /**
248269 * 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
250272 * @param currentStepPosition the initial step position, must be in the range of the adapter item count
251273 */
252274 public void setAdapter (@ NonNull AbstractStepAdapter stepAdapter , @ IntRange (from = 0 ) int currentStepPosition ) {
@@ -256,6 +278,7 @@ public void setAdapter(@NonNull AbstractStepAdapter stepAdapter, @IntRange(from
256278
257279 /**
258280 * Overrides the default page transformer used in the underlying {@link ViewPager}
281+ *
259282 * @param pageTransformer new page transformer
260283 */
261284 public void setPageTransformer (@ Nullable ViewPager .PageTransformer pageTransformer ) {
@@ -277,9 +300,9 @@ public int getTabStepDividerWidth() {
277300 @ Override
278301 @ UiThread
279302 public void onTabClicked (int position ) {
280- if (position > mCurrentStepPosition ){
303+ if (position > mCurrentStepPosition ) {
281304 onNext ();
282- } else if (position < mCurrentStepPosition ){
305+ } else if (position < mCurrentStepPosition ) {
283306 setCurrentStepPosition (position );
284307 }
285308 }
@@ -455,14 +478,14 @@ private Step findCurrentStep() {
455478 }
456479
457480 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 ();
463488 }
464- mCurrentStepPosition --;
465- onUpdate (mCurrentStepPosition );
466489 }
467490
468491 @ UiThread
@@ -474,7 +497,7 @@ private void onNext() {
474497 }
475498 OnNextClickedCallback onNextClickedCallback = new OnNextClickedCallback ();
476499 if (step instanceof BlockingStep ) {
477- ((BlockingStep )step ).onNextClicked (onNextClickedCallback );
500+ ((BlockingStep ) step ).onNextClicked (onNextClickedCallback );
478501 } else {
479502 onNextClickedCallback .goToNextStep ();
480503 }
0 commit comments