Skip to content

Commit

Permalink
optionally show BACK button in the first page of the wizard (issue #18)…
Browse files Browse the repository at this point in the history
… (#22)

- updated library version to 1.1.0
  • Loading branch information
zawadz88 authored Oct 25, 2016
1 parent ebcb71b commit c60e0e8
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 5 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Quoting the [documentation](https://www.google.com/design/spec/components/steppe
## Download (from JCenter)
```groovy
compile 'com.stepstone.stepper:material-stepper:1.0.3'
compile 'com.stepstone.stepper:material-stepper:1.1.0'
```

## Supported steppers
Expand Down Expand Up @@ -158,6 +158,11 @@ public class StepperActivity extends AppCompatActivity implements StepperLayout.
Toast.makeText(this, "onStepSelected! -> " + newStepPosition, Toast.LENGTH_SHORT).show();
}

@Override
public void onReturn() {
finish();
}

}
```

Expand Down Expand Up @@ -265,6 +270,21 @@ and declare that style in the XML you keep your styles at, e.g.
</style>
```

### Showing a Back button on first step
By default if the user is on the first step then the Back button in the bottom navigation is hidden.
This behaviour can be changed by setting ```ms_showBackButtonOnFirstStep``` to ```true```, e.g.
```xml
<?xml version="1.0" encoding="utf-8"?>
<com.stepstone.stepper.StepperLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/stepperLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:ms_showBackButtonOnFirstStep="true"
app:ms_stepperType="dots" />
```
To get a callback when this button was pressed you need set a ```StepperListener``` and write your own custom return logic in the ```onReturn()``` method to e.g. close the Activity.

### Advanced usage
For other examples, e.g. persisting state on rotation, displaying errors, changing whether the user can go to the next step, etc. check out the sample app.

Expand All @@ -285,6 +305,7 @@ For other examples, e.g. persisting state on rotation, displaying errors, changi
| *ms_nextButtonText* | string or reference | NEXT button's text |
| *ms_completeButtonText* | string or reference | COMPLETE button's text |
| *ms_tabStepDividerWidth* | dimension or reference | The width of the horizontal tab divider used in tabs stepper type |
| *ms_showBackButtonOnFirstStep* | boolean | Flag indicating if the Back (Previous step) button should be shown on the first step. False by default. |

## Missing features
- support for non-linear steppers
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

POM_GROUP_ID=com.stepstone.stepper
POM_ARTIFACT_ID=material-stepper
POM_VERSION=1.0.3
POM_VERSION=1.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public interface StepperListener {
*/
void onStepSelected(int newStepPosition);

/**
* Called when the Previous step button was pressed while on the first step
* (the button is not present by default on first step).
*/
void onReturn();

StepperListener NULL = new StepperListener() {
@Override
public void onCompleted(View completeButton) {
Expand All @@ -97,6 +103,10 @@ public void onError(VerificationError verificationError) {
@Override
public void onStepSelected(int newStepPosition) {
}

@Override
public void onReturn() {
}
};
}

Expand Down Expand Up @@ -163,6 +173,8 @@ public final void goToNextStep() {

private String mCompleteButtonText;

private boolean mShowBackButtonOnFirstStep;

private int mTypeIdentifier = AbstractStepperType.PROGRESS_BAR;

private AbstractStepAdapter mStepAdapter;
Expand Down Expand Up @@ -413,6 +425,8 @@ private void extractValuesFromAttributes(AttributeSet attrs, @AttrRes int defSty
mTabStepDividerWidth = a.getDimensionPixelOffset(R.styleable.StepperLayout_ms_tabStepDividerWidth, -1);
}

mShowBackButtonOnFirstStep = a.getBoolean(R.styleable.StepperLayout_ms_showBackButtonOnFirstStep, false);

if (a.hasValue(R.styleable.StepperLayout_ms_stepperType)) {
mTypeIdentifier = a.getInt(R.styleable.StepperLayout_ms_stepperType, DEFAULT_TAB_DIVIDER_WIDTH);
}
Expand Down Expand Up @@ -441,9 +455,12 @@ private Step findCurrentStep() {
}

private void onPrevious() {
if (mCurrentStepPosition <= 0)
if (mCurrentStepPosition <= 0) {
if (mShowBackButtonOnFirstStep) {
mListener.onReturn();
}
return;

}
mCurrentStepPosition--;
onUpdate(mCurrentStepPosition);
}
Expand Down Expand Up @@ -494,7 +511,7 @@ private void onUpdate(int newStepPosition) {
boolean isFirst = newStepPosition == 0;
mNextNavigationButton.setVisibility(isLast ? View.GONE : View.VISIBLE);
mCompleteNavigationButton.setVisibility(!isLast ? View.GONE : View.VISIBLE);
mBackNavigationButton.setVisibility(isFirst ? View.GONE : View.VISIBLE);
mBackNavigationButton.setVisibility(isFirst && !mShowBackButtonOnFirstStep ? View.GONE : View.VISIBLE);

if (!isLast) {
int nextButtonTextForStep = mStepAdapter.getNextButtonText(newStepPosition);
Expand Down
3 changes: 3 additions & 0 deletions material-stepper/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ limitations under the License.

<!-- The width of the horizontal tab divider used in tabs stepper type -->
<attr name="ms_tabStepDividerWidth" format="dimension|reference" />

<!-- Flag indicating if the Back (Previous step) button should be shown on the first step. False by default. -->
<attr name="ms_showBackButtonOnFirstStep" format="boolean" />

<!-- REQUIRED: Type of the stepper-->
<attr name="ms_stepperType">
Expand Down
2 changes: 2 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

<activity android:name=".DifferentNextButtonStepperActivity" />

<activity android:name=".ReturnButtonActivity" />

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public void onStepSelected(int newStepPosition) {
Toast.makeText(this, "onStepSelected! -> " + newStepPosition, Toast.LENGTH_SHORT).show();
}

@Override
public void onReturn() {
finish();
}

@Override
public void onChangeEndButtonsEnabled(boolean enabled) {
mStepperLayout.setNextButtonVerificationFailed(!enabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@ public void onDifferentNextButtons(View view) {
startActivity(new Intent(this, DifferentNextButtonStepperActivity.class));
}

@OnClick(R.id.showReturnButtonOnFirstStep)
public void onShowReturnButton(View view) {
startActivity(new Intent(this, ReturnButtonActivity.class));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2016 StepStone Services
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package com.stepstone.stepper.sample;

public class ReturnButtonActivity extends AbstractStepperActivity {

@Override
protected int getLayoutResId() {
return R.layout.activity_return_button;
}

}
6 changes: 6 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,11 @@
android:layout_height="wrap_content"
android:text="@string/different_next_buttons" />

<Button
android:id="@+id/showReturnButtonOnFirstStep"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/show_back_button" />

</LinearLayout>
</ScrollView>
9 changes: 9 additions & 0 deletions sample/src/main/res/layout/activity_return_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<com.stepstone.stepper.StepperLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/stepperLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:ms_showBackButtonOnFirstStep="true"
app:ms_stepperType="dots"/>
1 change: 1 addition & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<string name="custom_page_transformer">Custom PageTransformer</string>
<string name="delayed_transition">Delayed transition</string>
<string name="different_next_buttons">Different next buttons</string>
<string name="show_back_button">Show Back button on first step</string>

<string name="tab_title">Tab title</string>
<string name="lorem_ipsum">Lorem ipsum dolor sit amet, sale viris intellegam usu eu, persius patrioque sea at. Ne salutandi repudiandae mei, cu mollis accusam mediocrem mea. Altera dolorem praesent at vis. Torquatos philosophia ad quo. Omnis adipiscing has ea, mel no hinc iudico percipit.</string>
Expand Down

0 comments on commit c60e0e8

Please sign in to comment.