4343import android .widget .LinearLayout ;
4444
4545import com .stepstone .stepper .adapter .StepAdapter ;
46- import com .stepstone .stepper .internal .ColorableProgressBar ;
47- import com .stepstone .stepper .internal .DottedProgressBar ;
48- import com .stepstone .stepper .internal .RightNavigationButton ;
49- import com .stepstone .stepper .internal .TabsContainer ;
50- import com .stepstone .stepper .type .AbstractStepperType ;
51- import com .stepstone .stepper .type .StepperTypeFactory ;
52- import com .stepstone .stepper .util .AnimationUtil ;
53- import com .stepstone .stepper .util .TintUtil ;
46+ import com .stepstone .stepper .internal .widget . ColorableProgressBar ;
47+ import com .stepstone .stepper .internal .widget . DottedProgressBar ;
48+ import com .stepstone .stepper .internal .widget . RightNavigationButton ;
49+ import com .stepstone .stepper .internal .widget . TabsContainer ;
50+ import com .stepstone .stepper .internal . type .AbstractStepperType ;
51+ import com .stepstone .stepper .internal . type .StepperTypeFactory ;
52+ import com .stepstone .stepper .internal . util .AnimationUtil ;
53+ import com .stepstone .stepper .internal . util .TintUtil ;
5454import com .stepstone .stepper .viewmodel .StepViewModel ;
5555
5656/**
@@ -117,10 +117,18 @@ public void onReturn() {
117117 };
118118 }
119119
120- public final class OnNextClickedCallback {
120+ public abstract class AbstractOnButtonClickedCallback {
121+
122+ public StepperLayout getStepperLayout () {
123+ return StepperLayout .this ;
124+ }
125+
126+ }
127+
128+ public class OnNextClickedCallback extends AbstractOnButtonClickedCallback {
121129
122130 @ UiThread
123- public final void goToNextStep () {
131+ public void goToNextStep () {
124132 final int totalStepCount = mStepAdapter .getCount ();
125133
126134 if (mCurrentStepPosition >= totalStepCount - 1 ) {
@@ -133,10 +141,10 @@ public final void goToNextStep() {
133141
134142 }
135143
136- public final class OnBackClickedCallback {
144+ public class OnBackClickedCallback extends AbstractOnButtonClickedCallback {
137145
138146 @ UiThread
139- public final void goToPrevStep () {
147+ public void goToPrevStep () {
140148 if (mCurrentStepPosition <= 0 ) {
141149 if (mShowBackButtonOnFirstStep ) {
142150 mListener .onReturn ();
@@ -372,19 +380,32 @@ public void setCompleteButtonVerificationFailed(boolean verificationFailed) {
372380 /**
373381 * Set whether when going backwards should clear the error state from the Tab. Default is <code>false</code>.
374382 *
375- * @param mShowErrorStateOnBack true if navigating backwards should keep the error state, false otherwise
383+ * @param showErrorStateOnBack true if navigating backwards should keep the error state, false otherwise
376384 */
377- public void setShowErrorStateOnBack (boolean mShowErrorStateOnBack ) {
378- this .mShowErrorStateOnBack = mShowErrorStateOnBack ;
385+ public void setShowErrorStateOnBack (boolean showErrorStateOnBack ) {
386+ this .mShowErrorStateOnBack = showErrorStateOnBack ;
379387 }
380388
381389 /**
382390 * Set whether the errors should be displayed when they occur or not. Default is <code>false</code>.
383391 *
384- * @param mShowErrorState true if the errors should be displayed when they occur, false otherwise
392+ * @param showErrorState true if the errors should be displayed when they occur, false otherwise
385393 */
386- public void setShowErrorState (boolean mShowErrorState ) {
387- this .mShowErrorState = mShowErrorState ;
394+ public void setShowErrorState (boolean showErrorState ) {
395+ this .mShowErrorState = showErrorState ;
396+ }
397+
398+ /**
399+ * Updates the error state in the UI.
400+ * It does nothing if showing error state is disabled.
401+ * This is used internally to show the error on tabs.
402+ * @param hasError true if error should be shown, false otherwise
403+ * @see #setShowErrorState(boolean)
404+ */
405+ public void updateErrorState (boolean hasError ) {
406+ if (mShowErrorState ) {
407+ mStepperType .setErrorStep (mCurrentStepPosition , hasError );
408+ }
388409 }
389410
390411 /**
@@ -597,9 +618,7 @@ private void onNext() {
597618 }
598619
599620 //if moving forward and got no errors, set hasError to false, so we can have the tab with the check mark.
600- if (mShowErrorState ) {
601- mStepperType .setErrorStep (mCurrentStepPosition , false );
602- }
621+ updateErrorState (false );
603622
604623 OnNextClickedCallback onNextClickedCallback = new OnNextClickedCallback ();
605624 if (step instanceof BlockingStep ) {
@@ -624,9 +643,8 @@ private void onError(@NonNull VerificationError verificationError) {
624643 step .onError (verificationError );
625644
626645 //if moving forward and got errors, set hasError to true, showing the error drawable.
627- if (mShowErrorState ) {
628- mStepperType .setErrorStep (mCurrentStepPosition , true );
629- }
646+ updateErrorState (true );
647+
630648 }
631649 mListener .onError (verificationError );
632650 }
@@ -636,7 +654,7 @@ private void onComplete() {
636654 if (verifyCurrentStep (step )) {
637655 return ;
638656 }
639- mStepperType . setErrorStep ( mCurrentStepPosition , false );
657+ updateErrorState ( false );
640658 mListener .onCompleted (mCompleteNavigationButton );
641659 }
642660
0 commit comments