diff --git a/README.md b/README.md index b612c6e..5cfe2db 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Moreover, you can find there other examples, e.g. how to persist state on rotati - [Showing an error on tabs if step verification failed](#showing-an-error-on-tabs-if-step-verification-failed) - [Stepper feedback](#stepper-feedback) - [Changing button text color when going to the next step should be disabled](#changing-button-text-color-when-going-to-the-next-step-should-be-disabled) + - [Hiding bottom navigation bar](#hiding-bottom-navigation-bar) - [StepperLayout attributes](#stepperlayout-attributes) - [View attributes](#view-attributes) - [StepperLayout style attributes](#stepperlayout-style-attributes) @@ -56,7 +57,7 @@ Moreover, you can find there other examples, e.g. how to persist state on rotati ### Download (from JCenter) ```groovy -compile 'com.stepstone.stepper:material-stepper:3.2.3' +compile 'com.stepstone.stepper:material-stepper:3.3.0' ``` ### Create layout in XML @@ -435,6 +436,13 @@ In order to set that color: mStepperLayout.setCompleteButtonVerificationFailed(!enabled); ``` +### Hiding bottom navigation bar +Bottom navigation bar is shown by default. If in your UI you would like to +hide the bottom navigation bar you can do that by either setting +the `ms_showBottomNavigation` attribute in XML to `false` +or by setting it programmatically by calling ```StepperLayout#setShowBottomNavigation(boolean)``` +with `false`. + ## StepperLayout attributes ### View attributes @@ -463,6 +471,7 @@ For advanced styling please see [StepperLayout style attributes](#stepperlayout- | *ms_showErrorStateOnBackEnabled*| boolean | Flag indicating whether to keep showing the error state when user moves back. Only applicable for 'tabs' type. False by default. | | *ms_tabNavigationEnabled* | boolean | Flag indicating whether step navigation is possible by clicking on the tabs directly. Only applicable for 'tabs' type. True by default. | | *ms_stepperFeedbackType* | flag(s): `none` or `tabs`, `content` & `disabled_bottom_navigation` | Type(s) of stepper feedback. Can be a combination of `tabs`, `content` & `disabled_bottom_navigation`. Default is `none`.| +| *ms_showBottomNavigation* | boolean | Flag indicating if the Bottom Navigation bar should be shown on the layout. True by default. | | *ms_stepperLayoutTheme* | reference | Theme to use for even more custom styling of the stepper layout. It is recommended that it should extend @style/MSDefaultStepperLayoutTheme, which is the default theme used. | ### StepperLayout style attributes diff --git a/gradle.properties b/gradle.properties index 2944288..adf433e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,4 +19,4 @@ POM_GROUP_ID=com.stepstone.stepper POM_ARTIFACT_ID=material-stepper -POM_VERSION=3.2.3 \ No newline at end of file +POM_VERSION=3.3.0 \ No newline at end of file diff --git a/material-stepper/src/main/java/com/stepstone/stepper/StepperLayout.java b/material-stepper/src/main/java/com/stepstone/stepper/StepperLayout.java index 76108aa..375e814 100644 --- a/material-stepper/src/main/java/com/stepstone/stepper/StepperLayout.java +++ b/material-stepper/src/main/java/com/stepstone/stepper/StepperLayout.java @@ -224,6 +224,8 @@ public void goToPrevStep() { private boolean mShowBackButtonOnFirstStep; + private boolean mShowBottomNavigation; + private int mTypeIdentifier = AbstractStepperType.PROGRESS_BAR; private int mFeedbackTypeMask = StepperFeedbackType.NONE; @@ -431,26 +433,62 @@ public int getCurrentStepPosition() { return mCurrentStepPosition; } + /** + * Sets whether the Next button in the bottom navigation bar should be in the + * 'verification failed' state i.e. still clickable but with an option to display it + * differently to indicate to the user that he cannot go to the next step yet. + * @param verificationFailed false if verification failed, true otherwise + */ public void setNextButtonVerificationFailed(boolean verificationFailed) { mNextNavigationButton.setVerificationFailed(verificationFailed); } + /** + * Sets whether the Complete button in the bottom navigation bar should be in the + * 'verification failed' state i.e. still clickable but with an option to display it + * differently to indicate to the user that he cannot finish the process yet. + * @param verificationFailed false if verification failed, true otherwise + */ public void setCompleteButtonVerificationFailed(boolean verificationFailed) { mCompleteNavigationButton.setVerificationFailed(verificationFailed); } + /** + * Sets whether the Next button in the bottom navigation bar should be enabled (clickable). + * setting this to false will make it unclickable. + * @param enabled true if the button should be clickable, false otherwise + */ public void setNextButtonEnabled(boolean enabled) { mNextNavigationButton.setEnabled(enabled); } + /** + * Sets whether the Complete button in the bottom navigation bar should be enabled (clickable). + * setting this to false will make it unclickable. + * @param enabled true if the button should be clickable, false otherwise + */ public void setCompleteButtonEnabled(boolean enabled) { mCompleteNavigationButton.setEnabled(enabled); } + /** + * Sets whether the Back button in the bottom navigation bar should be enabled (clickable). + * setting this to false will make it unclickable. + * @param enabled true if the button should be clickable, false otherwise + */ public void setBackButtonEnabled(boolean enabled) { mBackNavigationButton.setEnabled(enabled); } + /** + * Set whether the bottom navigation bar (with Back/Next/Complete buttons) should be visible. + * true by default. + * @param showBottomNavigation true if bottom navigation should be visible, false otherwise + */ + public void setShowBottomNavigation(boolean showBottomNavigation) { + mStepNavigation.setVisibility(showBottomNavigation ? View.VISIBLE : View.GONE); + } + /** * Set whether when going backwards should clear the error state from the Tab. Default is false. * @@ -618,6 +656,7 @@ public boolean onTouch(View view, MotionEvent motionEvent) { mDottedProgressBar.setVisibility(GONE); mProgressBar.setVisibility(GONE); mTabsContainer.setVisibility(GONE); + mStepNavigation.setVisibility(mShowBottomNavigation ? View.VISIBLE : View.GONE); mStepperType = StepperTypeFactory.createType(mTypeIdentifier, this); mStepperFeedbackType = StepperFeedbackTypeFactory.createType(mFeedbackTypeMask, this); @@ -739,6 +778,8 @@ private void extractValuesFromAttributes(AttributeSet attrs, @AttrRes int defSty mShowBackButtonOnFirstStep = a.getBoolean(R.styleable.StepperLayout_ms_showBackButtonOnFirstStep, false); + mShowBottomNavigation = a.getBoolean(R.styleable.StepperLayout_ms_showBottomNavigation, true); + mShowErrorStateEnabled = a.getBoolean(R.styleable.StepperLayout_ms_showErrorState, false); mShowErrorStateEnabled = a.getBoolean(R.styleable.StepperLayout_ms_showErrorStateEnabled, mShowErrorStateEnabled); diff --git a/material-stepper/src/main/res/values/attrs.xml b/material-stepper/src/main/res/values/attrs.xml index 7d11f34..dff1439 100644 --- a/material-stepper/src/main/res/values/attrs.xml +++ b/material-stepper/src/main/res/values/attrs.xml @@ -52,6 +52,9 @@ limitations under the License. + + + diff --git a/material-stepper/src/test/java/com/stepstone/stepper/StepperLayoutTest.kt b/material-stepper/src/test/java/com/stepstone/stepper/StepperLayoutTest.kt index 7a6f8e6..5455b94 100644 --- a/material-stepper/src/test/java/com/stepstone/stepper/StepperLayoutTest.kt +++ b/material-stepper/src/test/java/com/stepstone/stepper/StepperLayoutTest.kt @@ -153,6 +153,58 @@ class StepperLayoutTest { assertStepperLayout().hasOrientation(LinearLayout.VERTICAL) } + @Test + fun `Horizontal orientation should be set by default`() { + //given + val attributeSet = createAttributeSetWithStepperType(TYPE_DOTS) + + //when + stepperLayout = createStepperLayoutInActivity(attributeSet) + + //then + assertStepperLayout().hasOrientation(LinearLayout.VERTICAL) + } + + @Test + fun `Bottom navigation should be visible by default`() { + //given + val attributeSet = createAttributeSetWithStepperType(TYPE_TABS) + + //when + stepperLayout = createStepperLayoutInActivity(attributeSet) + + //then + assertStepperLayout().hasBottomNavigationShown() + } + + @Test + fun `Bottom navigation should be hidden if 'ms_showBottomNavigation' attribute is set to 'false' in XML`() { + //given + val attributeSet = Robolectric.buildAttributeSet() + .addAttribute(R.attr.ms_stepperType, TYPE_TABS) + .addAttribute(R.attr.ms_showBottomNavigation, "false") + .build() + + //when + stepperLayout = createStepperLayoutInActivity(attributeSet) + + //then + assertStepperLayout().hasBottomNavigationHidden() + } + + @Test + fun `Bottom navigation should be hidden if set programmatically`() { + //given + val attributeSet = createAttributeSetWithStepperType(TYPE_TABS) + stepperLayout = createStepperLayoutInActivity(attributeSet) + + //when + stepperLayout.setShowBottomNavigation(false) + + //then + assertStepperLayout().hasBottomNavigationHidden() + } + fun createAttributeSetWithStepperType(stepperType: String): AttributeSet { return Robolectric.buildAttributeSet() .addAttribute(R.attr.ms_stepperType, stepperType) diff --git a/material-stepper/src/test/java/com/stepstone/stepper/test/assertion/StepperLayoutAssert.kt b/material-stepper/src/test/java/com/stepstone/stepper/test/assertion/StepperLayoutAssert.kt index 363b166..0e687b4 100644 --- a/material-stepper/src/test/java/com/stepstone/stepper/test/assertion/StepperLayoutAssert.kt +++ b/material-stepper/src/test/java/com/stepstone/stepper/test/assertion/StepperLayoutAssert.kt @@ -1,11 +1,8 @@ package com.stepstone.stepper.test.assertion import android.support.annotation.IdRes -import android.view.View - import com.stepstone.stepper.R import com.stepstone.stepper.StepperLayout - import org.assertj.android.api.Assertions import org.assertj.android.api.view.ViewAssert import org.assertj.android.api.widget.AbstractLinearLayoutAssert @@ -53,6 +50,16 @@ class StepperLayoutAssert constructor(actual: StepperLayout) : AbstractLinearLay return this } + fun hasBottomNavigationShown(): StepperLayoutAssert { + hasNotNullChildView(R.id.ms_bottomNavigation).isVisible + return this + } + + fun hasBottomNavigationHidden(): StepperLayoutAssert { + hasNotNullChildView(R.id.ms_bottomNavigation).isGone + return this + } + private fun hasNotNullChildView(@IdRes childId: Int): ViewAssert { val progressBar = actual.findViewById(childId) return Assertions.assertThat(progressBar).isNotNull diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 360f90d..2b35c9e 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -40,6 +40,7 @@ + diff --git a/sample/src/main/java/com/stepstone/stepper/sample/HiddenBottomNavigationActivity.kt b/sample/src/main/java/com/stepstone/stepper/sample/HiddenBottomNavigationActivity.kt new file mode 100644 index 0000000..c96eaa8 --- /dev/null +++ b/sample/src/main/java/com/stepstone/stepper/sample/HiddenBottomNavigationActivity.kt @@ -0,0 +1,24 @@ +/* +Copyright 2017 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 + +class HiddenBottomNavigationActivity : AbstractStepperActivity() { + + override val layoutResId: Int + get() = R.layout.activity_hidden_bottom_navigation + +} diff --git a/sample/src/main/java/com/stepstone/stepper/sample/MainActivity.kt b/sample/src/main/java/com/stepstone/stepper/sample/MainActivity.kt index 1dda97c..b400974 100644 --- a/sample/src/main/java/com/stepstone/stepper/sample/MainActivity.kt +++ b/sample/src/main/java/com/stepstone/stepper/sample/MainActivity.kt @@ -73,6 +73,7 @@ class MainActivity : AppCompatActivity() { SampleItem(getString(R.string.proceed_programmatically), getString(R.string.proceed_programmatically_description), ProceedProgrammaticallyActivity::class.java), SampleItem(getString(R.string.passing_data_between_steps), getString(R.string.passing_data_between_steps_description), PassDataBetweenStepsActivity::class.java), SampleItem(getString(R.string.disabled_tab_navigation), getString(R.string.disabled_tab_navigation_description), DisabledTabNavigationActivity::class.java), + SampleItem(getString(R.string.hidden_bottom_navigation), getString(R.string.hidden_bottom_navigation_description), HiddenBottomNavigationActivity::class.java), SampleItem(getString(R.string.custom_stepperlayout_theme), getString(R.string.custom_stepperlayout_theme_description), CustomStepperLayoutThemeActivity::class.java) ) diff --git a/sample/src/main/res/layout/activity_hidden_bottom_navigation.xml b/sample/src/main/res/layout/activity_hidden_bottom_navigation.xml new file mode 100644 index 0000000..6e4702a --- /dev/null +++ b/sample/src/main/res/layout/activity_hidden_bottom_navigation.xml @@ -0,0 +1,8 @@ + + \ No newline at end of file diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 3540f7d..a8197fd 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -21,6 +21,7 @@ Proceed programmatically Passing data between steps Disabled tab navigation + Hidden bottom navigation Custom StepperLayout theme The default implementation of a dotted stepper @@ -43,6 +44,7 @@ Shows how to navigate to the next steps without clicking on the bottom navigation buttons Shows how to pass data from one fragment to the next by using parent Activity Shows how to disable clicking on tabs in a tabbed stepper + Shows how to hide bottom navigation Shows a styled stepper layout with custom fonts & colors Tab title