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

Commit e1e3281

Browse files
committed
StepView: New attribute "step_summary_done"
Signed-off-by: Fung <[email protected]>
1 parent f21bd30 commit e1e3281

File tree

4 files changed

+53
-7
lines changed

4 files changed

+53
-7
lines changed

demo/src/main/java/moe/feng/common/stepperview/demo/fragment/VerticalStepperAdapterDemoFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
4040
public @Nullable String getSummary(int index) {
4141
switch (index) {
4242
case 0:
43-
return "Summarized if needed";
43+
return "Summarized if needed" + (mVerticalStepperView.getCurrentStep() > index ? "; isDone!" : "");
4444
case 2:
45-
return "Last step";
45+
return "Last step" + (mVerticalStepperView.getCurrentStep() > index ? "; isDone!" : "");
4646
default:
4747
return null;
4848
}

demo/src/main/res/layout/fragment_vertical_stepper.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
app:step_index="1"
2020
app:step_title="Step 1"
2121
app:step_summary="Summarized if needed"
22+
app:step_summary_done="Summarized if needed. Done"
2223
app:step_state="selected">
2324

2425
<LinearLayout
@@ -121,6 +122,7 @@
121122
app:step_index="3"
122123
app:step_title="Step 3"
123124
app:step_summary="Last step"
125+
app:step_summary_done="Last step. Done"
124126
app:step_is_last="true">
125127

126128
<LinearLayout

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

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class VerticalStepperItemView extends FrameLayout {
4343
/**
4444
* Step state
4545
*/
46-
private String mTitle, mSummary;
46+
private String mTitle, mSummary, mSummaryFinished = null;
4747
private int mIndex = 1;
4848
private boolean isLastStep = false;
4949
private int mState = STATE_NORMAL;
@@ -87,6 +87,7 @@ public VerticalStepperItemView(Context context, AttributeSet attrs, int defStyle
8787

8888
mTitle = a.getString(R.styleable.VerticalStepperItemView_step_title);
8989
mSummary = a.getString(R.styleable.VerticalStepperItemView_step_summary);
90+
mSummaryFinished = a.getString(R.styleable.VerticalStepperItemView_step_summary_done);
9091
mIndex = a.getInt(R.styleable.VerticalStepperItemView_step_index, 1);
9192
mState = a.getInt(R.styleable.VerticalStepperItemView_step_state, STATE_NORMAL);
9293
isLastStep = a.getBoolean(R.styleable.VerticalStepperItemView_step_is_last, false);
@@ -105,7 +106,7 @@ public VerticalStepperItemView(Context context, AttributeSet attrs, int defStyle
105106
}
106107

107108
setTitle(mTitle);
108-
setSummary(mSummary);
109+
updateSummaryView();
109110
setIndex(mIndex);
110111
setState(mState);
111112
setIsLastStep(isLastStep);
@@ -263,6 +264,7 @@ public synchronized void setState(@State int state) {
263264
mState = state;
264265

265266
updateMarginBottom();
267+
updateSummaryView();
266268
}
267269

268270
/**
@@ -343,8 +345,7 @@ public void setErrorText(@StringRes int errorTextRes) {
343345
*/
344346
public void setSummary(@Nullable String summary) {
345347
mSummary = summary;
346-
mSummaryText.setText(mErrorText != null ? mErrorText : summary);
347-
mSummaryText.setVisibility(mState != STATE_SELECTED && !TextUtils.isEmpty(mSummaryText.getText()) ? View.VISIBLE : View.GONE);
348+
updateSummaryView();
348349
}
349350

350351
/**
@@ -365,6 +366,46 @@ public String getSummary() {
365366
return mSummary;
366367
}
367368

369+
/**
370+
* Set finished summary for this step.
371+
* If you set a null value, it will hide the summary view or show default summary.
372+
*
373+
* @param summary The summary should be set or null
374+
*/
375+
public void setSummaryFinished(@Nullable String summary) {
376+
mSummaryFinished = summary;
377+
updateSummaryView();
378+
}
379+
380+
/**
381+
* Set summary for this step.
382+
*
383+
* @param summaryRes The summary resource should be set
384+
*/
385+
public void setSummaryFinished(@StringRes int summaryRes) {
386+
setSummaryFinished(getResources().getString(summaryRes));
387+
}
388+
389+
/**
390+
* Get the summary of this step
391+
*
392+
* @return The summary of this step
393+
*/
394+
public String getSummaryFinished() {
395+
return mSummaryFinished;
396+
}
397+
398+
/**
399+
* Update summary view
400+
*/
401+
private void updateSummaryView() {
402+
mSummaryText.setText(
403+
mErrorText != null ? mErrorText
404+
: (mSummaryFinished != null && mState == STATE_DONE) ? mSummaryFinished : mSummary
405+
);
406+
mSummaryText.setVisibility(mState != STATE_SELECTED && !TextUtils.isEmpty(mSummaryText.getText()) ? View.VISIBLE : View.GONE);
407+
}
408+
368409
/**
369410
* Set index for this step
370411
*
@@ -691,6 +732,7 @@ public Parcelable onSaveInstanceState() {
691732
ItemViewState state = new ItemViewState(super.onSaveInstanceState());
692733
state.title = mTitle;
693734
state.summary = mSummary;
735+
state.summaryFinished = mSummaryFinished;
694736
state.index = mIndex;
695737
state.isLastStep = isLastStep;
696738
state.state = mState;
@@ -713,6 +755,7 @@ public void onRestoreInstanceState(Parcelable state) {
713755
super.onRestoreInstanceState(viewState.getSuperState());
714756
setTitle(viewState.title);
715757
setSummary(viewState.summary);
758+
setSummaryFinished(viewState.summaryFinished);
716759
setIndex(viewState.index);
717760
setIsLastStep(viewState.isLastStep);
718761
setState(viewState.state);
@@ -732,7 +775,7 @@ protected static class ItemViewState extends BaseSavedState {
732775

733776
private static final String STATE = VerticalStepperItemView.class.getSimpleName() + ".STATE";
734777

735-
String title, summary;
778+
String title, summary, summaryFinished;
736779
int index = 1;
737780
boolean isLastStep = false;
738781
int state = STATE_NORMAL;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<attr name="step_index" format="integer"/>
2424
<attr name="step_title" format="string"/>
2525
<attr name="step_summary" format="string"/>
26+
<attr name="step_summary_done" format="string"/>
2627
<attr name="step_is_last" format="boolean"/>
2728
<attr name="step_state" format="enum">
2829
<enum name="normal" value="0"/>

0 commit comments

Comments
 (0)