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

Commit

Permalink
StepView: New attribute "step_summary_done"
Browse files Browse the repository at this point in the history
Signed-off-by: Fung <[email protected]>
  • Loading branch information
fython committed Aug 17, 2017
1 parent f21bd30 commit e1e3281
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
public @Nullable String getSummary(int index) {
switch (index) {
case 0:
return "Summarized if needed";
return "Summarized if needed" + (mVerticalStepperView.getCurrentStep() > index ? "; isDone!" : "");
case 2:
return "Last step";
return "Last step" + (mVerticalStepperView.getCurrentStep() > index ? "; isDone!" : "");
default:
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions demo/src/main/res/layout/fragment_vertical_stepper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
app:step_index="1"
app:step_title="Step 1"
app:step_summary="Summarized if needed"
app:step_summary_done="Summarized if needed. Done"
app:step_state="selected">

<LinearLayout
Expand Down Expand Up @@ -121,6 +122,7 @@
app:step_index="3"
app:step_title="Step 3"
app:step_summary="Last step"
app:step_summary_done="Last step. Done"
app:step_is_last="true">

<LinearLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class VerticalStepperItemView extends FrameLayout {
/**
* Step state
*/
private String mTitle, mSummary;
private String mTitle, mSummary, mSummaryFinished = null;
private int mIndex = 1;
private boolean isLastStep = false;
private int mState = STATE_NORMAL;
Expand Down Expand Up @@ -87,6 +87,7 @@ public VerticalStepperItemView(Context context, AttributeSet attrs, int defStyle

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

setTitle(mTitle);
setSummary(mSummary);
updateSummaryView();
setIndex(mIndex);
setState(mState);
setIsLastStep(isLastStep);
Expand Down Expand Up @@ -263,6 +264,7 @@ public synchronized void setState(@State int state) {
mState = state;

updateMarginBottom();
updateSummaryView();
}

/**
Expand Down Expand Up @@ -343,8 +345,7 @@ public void setErrorText(@StringRes int errorTextRes) {
*/
public void setSummary(@Nullable String summary) {
mSummary = summary;
mSummaryText.setText(mErrorText != null ? mErrorText : summary);
mSummaryText.setVisibility(mState != STATE_SELECTED && !TextUtils.isEmpty(mSummaryText.getText()) ? View.VISIBLE : View.GONE);
updateSummaryView();
}

/**
Expand All @@ -365,6 +366,46 @@ public String getSummary() {
return mSummary;
}

/**
* Set finished summary for this step.
* If you set a null value, it will hide the summary view or show default summary.
*
* @param summary The summary should be set or null
*/
public void setSummaryFinished(@Nullable String summary) {
mSummaryFinished = summary;
updateSummaryView();
}

/**
* Set summary for this step.
*
* @param summaryRes The summary resource should be set
*/
public void setSummaryFinished(@StringRes int summaryRes) {
setSummaryFinished(getResources().getString(summaryRes));
}

/**
* Get the summary of this step
*
* @return The summary of this step
*/
public String getSummaryFinished() {
return mSummaryFinished;
}

/**
* Update summary view
*/
private void updateSummaryView() {
mSummaryText.setText(
mErrorText != null ? mErrorText
: (mSummaryFinished != null && mState == STATE_DONE) ? mSummaryFinished : mSummary
);
mSummaryText.setVisibility(mState != STATE_SELECTED && !TextUtils.isEmpty(mSummaryText.getText()) ? View.VISIBLE : View.GONE);
}

/**
* Set index for this step
*
Expand Down Expand Up @@ -691,6 +732,7 @@ public Parcelable onSaveInstanceState() {
ItemViewState state = new ItemViewState(super.onSaveInstanceState());
state.title = mTitle;
state.summary = mSummary;
state.summaryFinished = mSummaryFinished;
state.index = mIndex;
state.isLastStep = isLastStep;
state.state = mState;
Expand All @@ -713,6 +755,7 @@ public void onRestoreInstanceState(Parcelable state) {
super.onRestoreInstanceState(viewState.getSuperState());
setTitle(viewState.title);
setSummary(viewState.summary);
setSummaryFinished(viewState.summaryFinished);
setIndex(viewState.index);
setIsLastStep(viewState.isLastStep);
setState(viewState.state);
Expand All @@ -732,7 +775,7 @@ protected static class ItemViewState extends BaseSavedState {

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

String title, summary;
String title, summary, summaryFinished;
int index = 1;
boolean isLastStep = false;
int state = STATE_NORMAL;
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<attr name="step_index" format="integer"/>
<attr name="step_title" format="string"/>
<attr name="step_summary" format="string"/>
<attr name="step_summary_done" format="string"/>
<attr name="step_is_last" format="boolean"/>
<attr name="step_state" format="enum">
<enum name="normal" value="0"/>
Expand Down

0 comments on commit e1e3281

Please sign in to comment.