Skip to content
This repository was archived by the owner on Aug 22, 2020. It is now read-only.

Commit c132ffc

Browse files
committed
New attr: always show summary
Signed-off-by: Fung <[email protected]>
1 parent 52753f2 commit c132ffc

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

library/src/main/java/moe/feng/common/stepperview/IStepperView.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,11 @@ interface IStepperView {
6868
*/
6969
Drawable getDoneIcon();
7070

71+
/**
72+
* Should show summary always
73+
*
74+
* @return If should show summary always
75+
*/
76+
boolean isAlwaysShowSummary();
77+
7178
}

library/src/main/java/moe/feng/common/stepperview/VerticalStepperItemView.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class VerticalStepperItemView extends FrameLayout {
5656
private int mNormalColor, mActivatedColor, mLineColor, mErrorColor;
5757
private Drawable mDoneIcon;
5858
private boolean mAnimationEnabled = true;
59+
private boolean mAlwaysShowSummary = false;
5960

6061
/**
6162
* The bind views
@@ -97,6 +98,7 @@ public VerticalStepperItemView(Context context, AttributeSet attrs, int defStyle
9798
mAnimationEnabled = a.getBoolean(R.styleable.VerticalStepperItemView_step_enable_animation, true);
9899
mLineColor = a.getColor(R.styleable.VerticalStepperItemView_step_line_color, mLineColor);
99100
mErrorColor = a.getColor(R.styleable.VerticalStepperItemView_step_error_highlight_color, mErrorColor);
101+
mAlwaysShowSummary = a.getBoolean(R.styleable.VerticalStepperItemView_step_show_summary_always, mAlwaysShowSummary);
100102

101103
if (a.hasValue(R.styleable.VerticalStepperItemView_step_done_icon)) {
102104
mDoneIcon = a.getDrawable(R.styleable.VerticalStepperItemView_step_done_icon);
@@ -304,7 +306,26 @@ public CharSequence getTitle() {
304306
return mTitle;
305307
}
306308

307-
/**
309+
/**
310+
* Set should show summary always.
311+
*
312+
* @param alwaysShowSummary new value
313+
*/
314+
public void setAlwaysShowSummary(boolean alwaysShowSummary) {
315+
mAlwaysShowSummary = alwaysShowSummary;
316+
updateSummaryView();
317+
}
318+
319+
/**
320+
* Should show summary always
321+
*
322+
* @return If should show summary always
323+
*/
324+
public boolean isAlwaysShowSummary() {
325+
return mAlwaysShowSummary;
326+
}
327+
328+
/**
308329
* Set error text for this step. If you want to remove error text, the param should be null.
309330
*
310331
* @param errorText The error text should be set or zero for removing error text
@@ -403,7 +424,10 @@ private void updateSummaryView() {
403424
mErrorText != null ? mErrorText
404425
: (mSummaryFinished != null && mState == STATE_DONE) ? mSummaryFinished : mSummary
405426
);
406-
mSummaryText.setVisibility(mState != STATE_SELECTED && !TextUtils.isEmpty(mSummaryText.getText()) ? View.VISIBLE : View.GONE);
427+
mSummaryText.setVisibility(
428+
(mState != STATE_SELECTED || mAlwaysShowSummary) && !TextUtils.isEmpty(mSummaryText.getText()) ?
429+
View.VISIBLE : View.GONE
430+
);
407431
}
408432

409433
/**
@@ -785,6 +809,8 @@ protected static class ItemViewState extends BaseSavedState {
785809
int normalColor, activatedColor, lineColor, errorColor;
786810
Drawable doneIcon;
787811

812+
boolean alwaysShowSummary;
813+
788814
ItemViewState(Parcelable superState) {
789815
super(superState);
790816
}

library/src/main/java/moe/feng/common/stepperview/VerticalStepperView.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class VerticalStepperView extends FrameLayout implements IStepperView {
3636
private int mAnimationDuration;
3737
private int mNormalColor, mActivatedColor, mLineColor, mErrorColor;
3838
private Drawable mDoneIcon;
39+
private boolean mAlwaysShowSummary = false;
3940

4041
public VerticalStepperView(Context context) {
4142
this(context, null);
@@ -60,6 +61,7 @@ public VerticalStepperView(Context context, AttributeSet attrs, int defStyleAttr
6061
mAnimationEnabled = a.getBoolean(R.styleable.VerticalStepperView_step_enable_animation, true);
6162
mLineColor = a.getColor(R.styleable.VerticalStepperView_step_line_color, mLineColor);
6263
mErrorColor = a.getColor(R.styleable.VerticalStepperView_step_error_highlight_color, mErrorColor);
64+
mAlwaysShowSummary = a.getBoolean(R.styleable.VerticalStepperView_step_show_summary_always, mAlwaysShowSummary);
6365

6466
if (a.hasValue(R.styleable.VerticalStepperView_step_done_icon)) {
6567
mDoneIcon = a.getDrawable(R.styleable.VerticalStepperView_step_done_icon);
@@ -106,6 +108,26 @@ public void updateSteppers() {
106108
mAdapter.notifyDataSetChanged();
107109
}
108110

111+
/**
112+
* Set should show summary always.
113+
*
114+
* @param alwaysShowSummary new value
115+
*/
116+
public void setAlwaysShowSummary(boolean alwaysShowSummary) {
117+
mAlwaysShowSummary = alwaysShowSummary;
118+
updateSteppers();
119+
}
120+
121+
/**
122+
* Should show summary always
123+
*
124+
* @return If should show summary always
125+
*/
126+
@Override
127+
public boolean isAlwaysShowSummary() {
128+
return mAlwaysShowSummary;
129+
}
130+
109131
/**
110132
* Set error text for item. If you want to remove error text, the errorText param should be null.
111133
*
@@ -415,6 +437,7 @@ public void onBindViewHolder(ItemHolder holder, int position) {
415437
holder.mItemView.setLineColor(mLineColor);
416438
holder.mItemView.setErrorColor(mErrorColor);
417439
holder.mItemView.setErrorText(mErrorTexts[position]);
440+
holder.mItemView.setAlwaysShowSummary(mAlwaysShowSummary);
418441
if (getCurrentStep() > position) {
419442
holder.mItemView.setState(VerticalStepperItemView.STATE_DONE);
420443
} else if (getCurrentStep() < position) {

library/src/main/res/values/attrs.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<attr name="step_enable_animation" format="boolean"/>
99
<attr name="step_line_color" format="color"/>
1010
<attr name="step_error_highlight_color" format="color"/>
11+
<attr name="step_show_summary_always" format="boolean"/>
1112

1213
<declare-styleable name="VerticalStepperView">
1314
<attr name="step_normal_color"/>
@@ -17,6 +18,7 @@
1718
<attr name="step_enable_animation"/>
1819
<attr name="step_line_color"/>
1920
<attr name="step_error_highlight_color"/>
21+
<attr name="step_show_summary_always"/>
2022
</declare-styleable>
2123

2224
<declare-styleable name="VerticalStepperItemView">
@@ -37,6 +39,7 @@
3739
<attr name="step_enable_animation"/>
3840
<attr name="step_line_color"/>
3941
<attr name="step_error_highlight_color"/>
42+
<attr name="step_show_summary_always"/>
4043
</declare-styleable>
4144

4245
</resources>

0 commit comments

Comments
 (0)