Skip to content

Commit be28527

Browse files
Piotr Zawadzkizawadz88
authored andcommitted
* Added an option to set hide Back/Next/Complete buttons programmatically via StepViewModel.
* Merged setNextButtonLabel(..) and setCompleteButtonLabel(..) to a single method setEndButtonLabel(..)
1 parent 4158546 commit be28527

File tree

12 files changed

+424
-163
lines changed

12 files changed

+424
-163
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
### Added
9+
- `setEndButtonVisible` and `setBackButtonVisible` methods in `StepViewModel.Builder` for toggling button visibility (issue #104)
10+
- New stepper type `none` which shows no progress indicator for the steps (issue #154)
11+
12+
### Changed
13+
- Updated Android Support Library version to `25.4.0` to support vector animations without a pre-Lollipop fallback (issue #154)
14+
- Changed `setNextButtonLabel` methods in `StepViewModel.Builder` to `setEndButtonLabel` so that it works for both Next and Complete buttons (issue #107)
15+
16+
[Unreleased]: https://github.com/stepstone-tech/android-material-stepper/compare/v3.3.0...develop

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Moreover, you can find there other examples, e.g. how to persist state on rotati
3131
- [StepperLayout attributes](#stepperlayout-attributes)
3232
- [View attributes](#view-attributes)
3333
- [StepperLayout style attributes](#stepperlayout-style-attributes)
34+
- [Changelog](#changelog)
3435
- [License](#license)
3536

3637
## Supported steppers
@@ -272,21 +273,21 @@ In such case you need to override the `getViewModel(int)` method from the `StepA
272273
switch (position) {
273274
case 0:
274275
builder
275-
.setNextButtonLabel("This way")
276+
.setEndButtonLabel("This way")
276277
.setBackButtonLabel("Cancel")
277278
.setNextButtonEndDrawableResId(R.drawable.ms_forward_arrow)
278279
.setBackButtonStartDrawableResId(StepViewModel.NULL_DRAWABLE);
279280
break;
280281
case 1:
281282
builder
282-
.setNextButtonLabel(R.string.go_to_summary)
283+
.setEndButtonLabel(R.string.go_to_summary)
283284
.setBackButtonLabel("Go to first")
284285
.setBackButtonStartDrawableResId(R.drawable.ms_back_arrow);
285286
break;
286287
case 2:
287288
builder
288289
.setBackButtonLabel("Go back")
289-
.setCompleteButtonLabel("I'm done!");
290+
.setEndButtonLabel("I'm done!");
290291
break;
291292
default:
292293
throw new IllegalArgumentException("Unsupported position: " + position);
@@ -295,6 +296,10 @@ In such case you need to override the `getViewModel(int)` method from the `StepA
295296
}
296297
```
297298

299+
It is also possible to hide Back/Next/Complete buttons on each step if needed.
300+
To do so you need to call `setBackButtonVisible(false)` and/or `setEndButtonVisible(false)` on
301+
`StepViewModel.Builder` in your adapter.
302+
298303
### Custom styling
299304
Basic styling can be done by choosing the active and inactive step colors.
300305
There are some additional properties which can be changed directly from StepperLayout's attributes e.g. the background of bottom navigation buttons (see [StepperLayout attributes](#stepperlayout-attributes))
@@ -500,7 +505,10 @@ A list of `ms_stepperLayoutTheme` attributes responsible for styling of StepperL
500505
| *ms_stepTabIconBackgroundStyle* | Used by ms_stepIconBackground in layout/ms_step_tab |
501506
| *ms_stepTabTitleStyle* | Used by ms_stepTitle in layout/ms_step_tab |
502507
| *ms_stepTabDividerStyle* | Used by ms_stepDivider in layout/ms_step_tab |
503-
508+
509+
## Changelog
510+
See [changelog](CHANGELOG.md)
511+
504512
## License
505513
Copyright 2016 StepStone Services
506514

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

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import android.view.ViewTreeObserver;
4444
import android.widget.Button;
4545
import android.widget.LinearLayout;
46+
import android.widget.TextView;
4647

4748
import com.stepstone.stepper.adapter.StepAdapter;
4849
import com.stepstone.stepper.internal.feedback.StepperFeedbackType;
@@ -885,20 +886,21 @@ private void onUpdate(int newStepPosition, boolean userTriggeredChange) {
885886
mPager.setCurrentItem(newStepPosition);
886887
final boolean isLast = isLastPosition(newStepPosition);
887888
final boolean isFirst = newStepPosition == 0;
888-
AnimationUtil.fadeViewVisibility(mNextNavigationButton, isLast ? View.GONE : View.VISIBLE, userTriggeredChange);
889-
AnimationUtil.fadeViewVisibility(mCompleteNavigationButton, !isLast ? View.GONE : View.VISIBLE, userTriggeredChange);
890-
int backButtonTargetVisibility = isFirst && !mShowBackButtonOnFirstStep ? View.GONE : View.VISIBLE;
891-
AnimationUtil.fadeViewVisibility(mBackNavigationButton, backButtonTargetVisibility, userTriggeredChange);
892-
893889
final StepViewModel viewModel = mStepAdapter.getViewModel(newStepPosition);
894890

891+
int backButtonTargetVisibility = (isFirst && !mShowBackButtonOnFirstStep) || !viewModel.isBackButtonVisible() ? View.GONE : View.VISIBLE;
892+
int nextButtonVisibility = isLast || !viewModel.isEndButtonVisible() ? View.GONE : View.VISIBLE;
893+
int completeButtonVisibility = !isLast || !viewModel.isEndButtonVisible() ? View.GONE : View.VISIBLE;
894+
895+
AnimationUtil.fadeViewVisibility(mNextNavigationButton, nextButtonVisibility, userTriggeredChange);
896+
AnimationUtil.fadeViewVisibility(mCompleteNavigationButton, completeButtonVisibility, userTriggeredChange);
897+
AnimationUtil.fadeViewVisibility(mBackNavigationButton, backButtonTargetVisibility, userTriggeredChange);
898+
895899
updateBackButton(viewModel);
896900

897-
if (!isLast) {
898-
updateNextButton(viewModel);
899-
} else {
900-
updateCompleteButton(viewModel);
901-
}
901+
updateEndButton(viewModel.getEndButtonLabel(),
902+
isLast ? mCompleteButtonText : mNextButtonText,
903+
isLast ? mCompleteNavigationButton : mNextNavigationButton);
902904

903905
setCompoundDrawablesForNavigationButtons(viewModel.getBackButtonStartDrawableResId(), viewModel.getNextButtonEndDrawableResId());
904906

@@ -910,21 +912,13 @@ private void onUpdate(int newStepPosition, boolean userTriggeredChange) {
910912
}
911913
}
912914

913-
private void updateCompleteButton(@NonNull StepViewModel viewModel) {
914-
CharSequence completeButtonTextForStep = viewModel.getCompleteButtonLabel();
915-
if (completeButtonTextForStep == null) {
916-
mCompleteNavigationButton.setText(mCompleteButtonText);
917-
} else {
918-
mCompleteNavigationButton.setText(completeButtonTextForStep);
919-
}
920-
}
921-
922-
private void updateNextButton(@NonNull StepViewModel viewModel) {
923-
CharSequence nextButtonTextForStep = viewModel.getNextButtonLabel();
924-
if (nextButtonTextForStep == null) {
925-
mNextNavigationButton.setText(mNextButtonText);
915+
private void updateEndButton(@Nullable CharSequence endButtonTextForStep,
916+
@Nullable CharSequence defaultEndButtonText,
917+
@NonNull TextView endButton) {
918+
if (endButtonTextForStep == null) {
919+
endButton.setText(defaultEndButtonText);
926920
} else {
927-
mNextNavigationButton.setText(nextButtonTextForStep);
921+
endButton.setText(endButtonTextForStep);
928922
}
929923
}
930924

0 commit comments

Comments
 (0)