Skip to content

Commit d37d992

Browse files
committed
Added examples, polymorphed the error structure and cleared error state onCompleted
1 parent 3eb62cd commit d37d992

File tree

14 files changed

+117
-12
lines changed

14 files changed

+117
-12
lines changed

material-stepper/src/main/java/com/stepstone/stepper/StepperLayout.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,9 @@ public void setShowErrorStateOnBack(boolean mShowErrorStateOnBack) {
353353
*/
354354
public void setShowErrorState(boolean mShowErrorState) {
355355
this.mShowErrorState = mShowErrorState;
356-
357-
/**
356+
}
357+
358+
/**
358359
* Set the number of steps that should be retained to either side of the
359360
* current step in the view hierarchy in an idle state. Steps beyond this
360361
* limit will be recreated from the adapter when needed.
@@ -546,8 +547,8 @@ private void onNext() {
546547
}
547548

548549
//if moving forward and got no errors, set hasError to false, so we can have the tab with the check mark.
549-
if(mShowErrorState && mStepperType instanceof TabsStepperType)
550-
mTabsContainer.setErrorStep(mCurrentStepPosition, false);
550+
if(mShowErrorState)
551+
mStepperType.setErrorStep(mCurrentStepPosition, false);
551552

552553
OnNextClickedCallback onNextClickedCallback = new OnNextClickedCallback();
553554
if (step instanceof BlockingStep) {
@@ -572,8 +573,8 @@ private void onError(@NonNull VerificationError verificationError) {
572573
step.onError(verificationError);
573574

574575
//if moving forward and got errors, set hasError to true, showing the error drawable.
575-
if(mShowErrorState && mStepperType instanceof TabsStepperType)
576-
mTabsContainer.setErrorStep(mCurrentStepPosition, true);
576+
if(mShowErrorState)
577+
mStepperType.setErrorStep(mCurrentStepPosition, true);
577578

578579
}
579580
mListener.onError(verificationError);
@@ -584,6 +585,7 @@ private void onComplete(View completeButton) {
584585
if (verifyCurrentStep(step)) {
585586
return;
586587
}
588+
mStepperType.setErrorStep(mCurrentStepPosition, false);
587589
mListener.onCompleted(completeButton);
588590
}
589591

@@ -604,10 +606,7 @@ private void onUpdate(int newStepPosition, boolean animate) {
604606
}
605607

606608
//needs to be here in case user for any reason decide to change whether or not to show errors when going back.
607-
if(mStepperType instanceof TabsStepperType) {
608-
mTabsContainer.setShowErrorStateOnBack(mShowErrorStateOnBack);
609-
}
610-
609+
mStepperType.showErrorStateOnBack(mShowErrorStateOnBack);
611610
mStepperType.onStepSelected(newStepPosition);
612611
mListener.onStepSelected(newStepPosition);
613612
Step step = mStepAdapter.findStep(mPager, newStepPosition);

material-stepper/src/main/java/com/stepstone/stepper/internal/StepTab.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,19 @@ public void updateState(final boolean done, final boolean showErrorOnBack, final
124124
* Update the error state of this tab. If it has error, show the error drawable.
125125
* @param hasError whether the tab has errors or not.
126126
*/
127-
public void updateErrorState(boolean hasError) {
127+
public void updateErrorState(boolean done, boolean hasError) {
128128
if(hasError) {
129129
mStepDoneIndicator.setVisibility(View.GONE);
130130
mStepNumber.setVisibility(View.GONE);
131131
mStepErrorIndicator.setVisibility(VISIBLE);
132132
mStepErrorIndicator.setColorFilter(mErrorColor);
133133
mStepTitle.setTextColor(mErrorColor);
134+
} else if(done) {
135+
mStepDoneIndicator.setVisibility(View.VISIBLE);
136+
mStepErrorIndicator.setVisibility(GONE);
137+
colorViewBackground(mStepDoneIndicator, true);
138+
139+
mStepTitle.setTextColor(ContextCompat.getColor(getContext(), R.color.ms_black));
134140
}
135141

136142
this.hasError = hasError;

material-stepper/src/main/java/com/stepstone/stepper/internal/TabsContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public void setErrorStep(int stepPosition, boolean hasError){
186186
return;
187187

188188
StepTab childTab = (StepTab) mTabsInnerContainer.getChildAt(stepPosition);
189-
childTab.updateErrorState(hasError);
189+
childTab.updateErrorState(mStepTitles.size() - 1 == stepPosition ,hasError);
190190
}
191191

192192
private View createStepTab(final int position, @Nullable CharSequence title) {

material-stepper/src/main/java/com/stepstone/stepper/type/AbstractStepperType.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ public AbstractStepperType(StepperLayout stepperLayout) {
5454
*/
5555
public abstract void onStepSelected(int newStepPosition);
5656

57+
/**
58+
* Called to set whether the stepPosition has an error or not, changing it's appearance.
59+
* @param stepPosition the step to set the error
60+
* @param hasError whether it has error or not
61+
*/
62+
public void setErrorStep(int stepPosition, boolean hasError){ }
63+
64+
/**
65+
* Called to set whether navigating backwards should keep the error state.
66+
* @param mShowErrorStateOnBack
67+
*/
68+
public void showErrorStateOnBack(boolean mShowErrorStateOnBack){ }
69+
5770
/**
5871
* Called when {@link StepperLayout}'s adapter gets changed
5972
* @param stepAdapter new stepper adapter

material-stepper/src/main/java/com/stepstone/stepper/type/TabsStepperType.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ public void onStepSelected(int newStepPosition) {
5454
mTabsContainer.setCurrentStep(newStepPosition);
5555
}
5656

57+
/**
58+
* {@inheritDoc}
59+
*/
60+
@Override
61+
public void setErrorStep(int stepPosition, boolean hasError) {
62+
mTabsContainer.setErrorStep(stepPosition, hasError);
63+
}
64+
65+
/**
66+
* {@inheritDoc}
67+
*/
68+
@Override
69+
public void showErrorStateOnBack(boolean mShowErrorStateOnBack) {
70+
mTabsContainer.setShowErrorStateOnBack(mShowErrorStateOnBack);
71+
}
72+
5773
/**
5874
* {@inheritDoc}
5975
*/

sample/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
<activity android:name=".DefaultTabsActivity" />
2626
<activity android:name=".StyledTabsActivity" />
2727
<activity android:name=".ShowErrorOnBackTabActivity"/>
28+
<activity android:name=".ShowErrorTabActivity" />
29+
<activity android:name=".ShowErrorCustomColorTabActivity" />
2830
<activity android:name=".CombinationActivity" />
2931
<activity android:name=".CustomPageTransformerActivity" />
3032
<activity android:name=".DelayedTransitionStepperActivity" />

sample/src/main/java/com/stepstone/stepper/sample/MainActivity.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ public void onStyledTabs(View view) {
6868
startActivity(new Intent(this, StyledTabsActivity.class));
6969
}
7070

71+
@OnClick(R.id.errorTabs)
72+
public void onErrorTabs(View view) {
73+
startActivity(new Intent(this, ShowErrorTabActivity.class));
74+
}
75+
76+
@OnClick(R.id.errorColorTabs)
77+
public void onCustomColorErrorTabs(View view) {
78+
startActivity(new Intent(this, ShowErrorCustomColorTabActivity.class));
79+
}
80+
7181
@OnClick(R.id.errorOnBackTabs)
7282
public void onErrorOnBackTabs(View view) {
7383
startActivity(new Intent(this, ShowErrorOnBackTabActivity.class));
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.stepstone.stepper.sample;
2+
3+
/**
4+
* Created by leonardo on 1/16/17.
5+
*/
6+
7+
public class ShowErrorCustomColorTabActivity extends AbstractStepperActivity {
8+
@Override
9+
protected int getLayoutResId() {
10+
return R.layout.activity_error_custom_color_tabs;
11+
}
12+
}

sample/src/main/java/com/stepstone/stepper/sample/ShowErrorOnBackTabActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class ShowErrorOnBackTabActivity extends AbstractStepperActivity {
1111
@Override
1212
protected void onCreate(Bundle savedInstanceState) {
1313
super.onCreate(savedInstanceState);
14+
mStepperLayout.setShowErrorState(true);
1415
mStepperLayout.setShowErrorStateOnBack(true);
1516
}
1617

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.stepstone.stepper.sample;
2+
3+
/**
4+
* Created by leonardo on 1/16/17.
5+
*/
6+
7+
public class ShowErrorTabActivity extends AbstractStepperActivity {
8+
9+
@Override
10+
protected int getLayoutResId() {
11+
return R.layout.activity_error_tabs;
12+
}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<com.stepstone.stepper.StepperLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:id="@+id/stepperLayout"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:orientation="vertical"
8+
app:ms_stepperType="tabs"
9+
app:ms_showErrorState="true"
10+
app:ms_errorColor="@color/colorButton"/>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<com.stepstone.stepper.StepperLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:id="@+id/stepperLayout"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:orientation="vertical"
8+
app:ms_stepperType="tabs"
9+
app:ms_showErrorState="true" />

sample/src/main/res/layout/activity_main.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@
5858
android:layout_height="wrap_content"
5959
android:text="@string/styled_tabs" />
6060

61+
<Button
62+
android:id="@+id/errorTabs"
63+
android:layout_width="wrap_content"
64+
android:layout_height="wrap_content"
65+
android:text="@string/error_tabs" />
66+
67+
<Button
68+
android:id="@+id/errorColorTabs"
69+
android:layout_width="wrap_content"
70+
android:layout_height="wrap_content"
71+
android:text="@string/error_color_tabs" />
72+
6173
<Button
6274
android:id="@+id/errorOnBackTabs"
6375
android:layout_width="wrap_content"

sample/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<string name="styled_progress_bar">Styled progress bar</string>
88
<string name="default_tabs">Default tabs</string>
99
<string name="styled_tabs">Styled tabs</string>
10+
<string name="error_tabs">Show errors on tabs</string>
11+
<string name="error_color_tabs">Custom color error tabs</string>
1012
<string name="error_back_tabs">Keep error back tabs</string>
1113
<string name="combination">Dots in portrait, tabs in landscape</string>
1214
<string name="custom_page_transformer">Custom PageTransformer</string>

0 commit comments

Comments
 (0)