Skip to content

Commit 46ba710

Browse files
Piotr Zawadzkizawadz88
authored andcommitted
- Reorganized packages to hide internal classes
- Added an option to update the error state programmatically from StepperLayout (issue #68)
1 parent 6f34be3 commit 46ba710

30 files changed

+268
-139
lines changed

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

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@
4343
import android.widget.LinearLayout;
4444

4545
import com.stepstone.stepper.adapter.StepAdapter;
46-
import com.stepstone.stepper.internal.ColorableProgressBar;
47-
import com.stepstone.stepper.internal.DottedProgressBar;
48-
import com.stepstone.stepper.internal.RightNavigationButton;
49-
import com.stepstone.stepper.internal.TabsContainer;
50-
import com.stepstone.stepper.type.AbstractStepperType;
51-
import com.stepstone.stepper.type.StepperTypeFactory;
52-
import com.stepstone.stepper.util.AnimationUtil;
53-
import com.stepstone.stepper.util.TintUtil;
46+
import com.stepstone.stepper.internal.widget.ColorableProgressBar;
47+
import com.stepstone.stepper.internal.widget.DottedProgressBar;
48+
import com.stepstone.stepper.internal.widget.RightNavigationButton;
49+
import com.stepstone.stepper.internal.widget.TabsContainer;
50+
import com.stepstone.stepper.internal.type.AbstractStepperType;
51+
import com.stepstone.stepper.internal.type.StepperTypeFactory;
52+
import com.stepstone.stepper.internal.util.AnimationUtil;
53+
import com.stepstone.stepper.internal.util.TintUtil;
5454
import com.stepstone.stepper.viewmodel.StepViewModel;
5555

5656
/**
@@ -117,10 +117,18 @@ public void onReturn() {
117117
};
118118
}
119119

120-
public final class OnNextClickedCallback {
120+
public abstract class AbstractOnButtonClickedCallback {
121+
122+
public StepperLayout getStepperLayout() {
123+
return StepperLayout.this;
124+
}
125+
126+
}
127+
128+
public class OnNextClickedCallback extends AbstractOnButtonClickedCallback {
121129

122130
@UiThread
123-
public final void goToNextStep() {
131+
public void goToNextStep() {
124132
final int totalStepCount = mStepAdapter.getCount();
125133

126134
if (mCurrentStepPosition >= totalStepCount - 1) {
@@ -133,10 +141,10 @@ public final void goToNextStep() {
133141

134142
}
135143

136-
public final class OnBackClickedCallback {
144+
public class OnBackClickedCallback extends AbstractOnButtonClickedCallback {
137145

138146
@UiThread
139-
public final void goToPrevStep() {
147+
public void goToPrevStep() {
140148
if (mCurrentStepPosition <= 0) {
141149
if (mShowBackButtonOnFirstStep) {
142150
mListener.onReturn();
@@ -372,19 +380,32 @@ public void setCompleteButtonVerificationFailed(boolean verificationFailed) {
372380
/**
373381
* Set whether when going backwards should clear the error state from the Tab. Default is <code>false</code>.
374382
*
375-
* @param mShowErrorStateOnBack true if navigating backwards should keep the error state, false otherwise
383+
* @param showErrorStateOnBack true if navigating backwards should keep the error state, false otherwise
376384
*/
377-
public void setShowErrorStateOnBack(boolean mShowErrorStateOnBack) {
378-
this.mShowErrorStateOnBack = mShowErrorStateOnBack;
385+
public void setShowErrorStateOnBack(boolean showErrorStateOnBack) {
386+
this.mShowErrorStateOnBack = showErrorStateOnBack;
379387
}
380388

381389
/**
382390
* Set whether the errors should be displayed when they occur or not. Default is <code>false</code>.
383391
*
384-
* @param mShowErrorState true if the errors should be displayed when they occur, false otherwise
392+
* @param showErrorState true if the errors should be displayed when they occur, false otherwise
385393
*/
386-
public void setShowErrorState(boolean mShowErrorState) {
387-
this.mShowErrorState = mShowErrorState;
394+
public void setShowErrorState(boolean showErrorState) {
395+
this.mShowErrorState = showErrorState;
396+
}
397+
398+
/**
399+
* Updates the error state in the UI.
400+
* It does nothing if showing error state is disabled.
401+
* This is used internally to show the error on tabs.
402+
* @param hasError true if error should be shown, false otherwise
403+
* @see #setShowErrorState(boolean)
404+
*/
405+
public void updateErrorState(boolean hasError) {
406+
if (mShowErrorState) {
407+
mStepperType.setErrorStep(mCurrentStepPosition, hasError);
408+
}
388409
}
389410

390411
/**
@@ -597,9 +618,7 @@ private void onNext() {
597618
}
598619

599620
//if moving forward and got no errors, set hasError to false, so we can have the tab with the check mark.
600-
if (mShowErrorState) {
601-
mStepperType.setErrorStep(mCurrentStepPosition, false);
602-
}
621+
updateErrorState(false);
603622

604623
OnNextClickedCallback onNextClickedCallback = new OnNextClickedCallback();
605624
if (step instanceof BlockingStep) {
@@ -624,9 +643,8 @@ private void onError(@NonNull VerificationError verificationError) {
624643
step.onError(verificationError);
625644

626645
//if moving forward and got errors, set hasError to true, showing the error drawable.
627-
if (mShowErrorState) {
628-
mStepperType.setErrorStep(mCurrentStepPosition, true);
629-
}
646+
updateErrorState(true);
647+
630648
}
631649
mListener.onError(verificationError);
632650
}
@@ -636,7 +654,7 @@ private void onComplete() {
636654
if (verifyCurrentStep(step)) {
637655
return;
638656
}
639-
mStepperType.setErrorStep(mCurrentStepPosition, false);
657+
updateErrorState(false);
640658
mListener.onCompleted(mCompleteNavigationButton);
641659
}
642660

material-stepper/src/main/java/com/stepstone/stepper/type/AbstractStepperType.java renamed to material-stepper/src/main/java/com/stepstone/stepper/internal/type/AbstractStepperType.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@
1414
limitations under the License.
1515
*/
1616

17-
package com.stepstone.stepper.type;
17+
package com.stepstone.stepper.internal.type;
1818

1919
import android.support.annotation.ColorInt;
2020
import android.support.annotation.NonNull;
21+
import android.support.annotation.RestrictTo;
2122

2223
import com.stepstone.stepper.StepperLayout;
2324
import com.stepstone.stepper.adapter.StepAdapter;
2425

26+
import static android.support.annotation.RestrictTo.Scope.LIBRARY;
27+
2528
/**
2629
* A base stepper type all stepper types must extend.
2730
*/
31+
@RestrictTo(LIBRARY)
2832
public abstract class AbstractStepperType {
2933

3034
/**

material-stepper/src/main/java/com/stepstone/stepper/type/DotsStepperType.java renamed to material-stepper/src/main/java/com/stepstone/stepper/internal/type/DotsStepperType.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@
1414
limitations under the License.
1515
*/
1616

17-
package com.stepstone.stepper.type;
17+
package com.stepstone.stepper.internal.type;
1818

1919
import android.support.annotation.NonNull;
20+
import android.support.annotation.RestrictTo;
2021
import android.view.View;
2122

2223
import com.stepstone.stepper.R;
2324
import com.stepstone.stepper.StepperLayout;
2425
import com.stepstone.stepper.adapter.StepAdapter;
25-
import com.stepstone.stepper.internal.DottedProgressBar;
26+
import com.stepstone.stepper.internal.widget.DottedProgressBar;
27+
28+
import static android.support.annotation.RestrictTo.Scope.LIBRARY;
2629

2730
/**
2831
* Stepper type which displays mobile step dots.
2932
*/
33+
@RestrictTo(LIBRARY)
3034
public class DotsStepperType extends AbstractStepperType {
3135

3236
private static final int EDIT_MODE_DOT_COUNT = 3;

material-stepper/src/main/java/com/stepstone/stepper/type/ProgressBarStepperType.java renamed to material-stepper/src/main/java/com/stepstone/stepper/internal/type/ProgressBarStepperType.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@
1414
limitations under the License.
1515
*/
1616

17-
package com.stepstone.stepper.type;
17+
package com.stepstone.stepper.internal.type;
1818

1919
import android.support.annotation.NonNull;
20+
import android.support.annotation.RestrictTo;
2021
import android.view.View;
2122

2223
import com.stepstone.stepper.R;
2324
import com.stepstone.stepper.StepperLayout;
2425
import com.stepstone.stepper.adapter.StepAdapter;
25-
import com.stepstone.stepper.internal.ColorableProgressBar;
26+
import com.stepstone.stepper.internal.widget.ColorableProgressBar;
27+
28+
import static android.support.annotation.RestrictTo.Scope.LIBRARY;
2629

2730
/**
2831
* Stepper type which displays a mobile step progress bar.
2932
*/
33+
@RestrictTo(LIBRARY)
3034
public class ProgressBarStepperType extends AbstractStepperType {
3135

3236
private final ColorableProgressBar mProgressBar;

material-stepper/src/main/java/com/stepstone/stepper/type/StepperTypeFactory.java renamed to material-stepper/src/main/java/com/stepstone/stepper/internal/type/StepperTypeFactory.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@
1414
limitations under the License.
1515
*/
1616

17-
package com.stepstone.stepper.type;
17+
package com.stepstone.stepper.internal.type;
1818

19+
import android.support.annotation.RestrictTo;
1920
import android.util.Log;
2021

2122
import com.stepstone.stepper.StepperLayout;
2223

24+
import static android.support.annotation.RestrictTo.Scope.LIBRARY;
25+
2326
/**
2427
* Factory class for creating stepper types.
2528
*/
29+
@RestrictTo(LIBRARY)
2630
public class StepperTypeFactory {
2731

2832
private static final String TAG = StepperTypeFactory.class.getSimpleName();

material-stepper/src/main/java/com/stepstone/stepper/type/TabsStepperType.java renamed to material-stepper/src/main/java/com/stepstone/stepper/internal/type/TabsStepperType.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,28 @@
1414
limitations under the License.
1515
*/
1616

17-
package com.stepstone.stepper.type;
17+
package com.stepstone.stepper.internal.type;
1818

1919
import android.support.annotation.NonNull;
20+
import android.support.annotation.RestrictTo;
2021
import android.view.View;
2122

2223
import com.stepstone.stepper.R;
2324
import com.stepstone.stepper.StepperLayout;
2425
import com.stepstone.stepper.adapter.StepAdapter;
25-
import com.stepstone.stepper.internal.TabsContainer;
26+
import com.stepstone.stepper.internal.widget.TabsContainer;
2627
import com.stepstone.stepper.viewmodel.StepViewModel;
2728

2829
import java.util.ArrayList;
2930
import java.util.Arrays;
3031
import java.util.List;
3132

33+
import static android.support.annotation.RestrictTo.Scope.LIBRARY;
34+
3235
/**
3336
* Stepper type which displays horizontal stepper with tabs.
3437
*/
38+
@RestrictTo(LIBRARY)
3539
public class TabsStepperType extends AbstractStepperType {
3640

3741
private static final List<CharSequence> EDIT_MODE_STEP_TITLES = Arrays.<CharSequence>asList("Step 1", "Step 2");

material-stepper/src/main/java/com/stepstone/stepper/util/AnimationUtil.java renamed to material-stepper/src/main/java/com/stepstone/stepper/internal/util/AnimationUtil.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
package com.stepstone.stepper.util;
1+
package com.stepstone.stepper.internal.util;
22

33
import android.animation.Animator;
44
import android.support.annotation.IntDef;
55
import android.support.annotation.NonNull;
6+
import android.support.annotation.RestrictTo;
67
import android.view.View;
78
import android.view.ViewPropertyAnimator;
89

910
import java.lang.annotation.Retention;
1011

12+
import static android.support.annotation.RestrictTo.Scope.LIBRARY;
1113
import static java.lang.annotation.RetentionPolicy.SOURCE;
1214

1315
/**
1416
* Util class containing static methods to simplify animation.
1517
*/
18+
@RestrictTo(LIBRARY)
1619
public final class AnimationUtil {
1720

1821
@Retention(SOURCE)

material-stepper/src/main/java/com/stepstone/stepper/util/TintUtil.java renamed to material-stepper/src/main/java/com/stepstone/stepper/internal/util/TintUtil.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package com.stepstone.stepper.util;
17+
package com.stepstone.stepper.internal.util;
1818

1919
import android.content.res.ColorStateList;
2020
import android.graphics.PorterDuff;
@@ -24,13 +24,17 @@
2424
import android.support.annotation.ColorInt;
2525
import android.support.annotation.NonNull;
2626
import android.support.annotation.Nullable;
27+
import android.support.annotation.RestrictTo;
2728
import android.support.v4.graphics.drawable.DrawableCompat;
2829
import android.util.Log;
2930
import android.widget.TextView;
3031

32+
import static android.support.annotation.RestrictTo.Scope.LIBRARY;
33+
3134
/**
3235
* Utility class for tinting drawables/widgets.
3336
*/
37+
@RestrictTo(LIBRARY)
3438
public class TintUtil {
3539

3640
private static final String TAG = TintUtil.class.getSimpleName();

material-stepper/src/main/java/com/stepstone/stepper/internal/ColorableProgressBar.java renamed to material-stepper/src/main/java/com/stepstone/stepper/internal/widget/ColorableProgressBar.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,27 @@
1414
limitations under the License.
1515
*/
1616

17-
package com.stepstone.stepper.internal;
17+
package com.stepstone.stepper.internal.widget;
1818

1919
import android.content.Context;
2020
import android.content.res.TypedArray;
2121
import android.graphics.drawable.Drawable;
2222
import android.graphics.drawable.LayerDrawable;
2323
import android.support.annotation.ColorInt;
24+
import android.support.annotation.RestrictTo;
2425
import android.support.v4.content.ContextCompat;
2526
import android.util.AttributeSet;
2627
import android.widget.ProgressBar;
2728

2829
import com.stepstone.stepper.R;
29-
import com.stepstone.stepper.util.TintUtil;
30+
import com.stepstone.stepper.internal.util.TintUtil;
31+
32+
import static android.support.annotation.RestrictTo.Scope.LIBRARY;
3033

3134
/**
3235
* A {@link ProgressBar} which exposes methods for coloring primary progress and progress background colors individually.
3336
*/
37+
@RestrictTo(LIBRARY)
3438
public class ColorableProgressBar extends ProgressBar {
3539

3640
@ColorInt

material-stepper/src/main/java/com/stepstone/stepper/internal/DottedProgressBar.java renamed to material-stepper/src/main/java/com/stepstone/stepper/internal/widget/DottedProgressBar.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
limitations under the License.
1515
*/
1616

17-
package com.stepstone.stepper.internal;
17+
package com.stepstone.stepper.internal.widget;
1818

1919
import android.content.Context;
2020
import android.content.res.TypedArray;
2121
import android.graphics.drawable.Drawable;
2222
import android.support.annotation.ColorInt;
23+
import android.support.annotation.RestrictTo;
2324
import android.support.v4.content.ContextCompat;
2425
import android.util.AttributeSet;
2526
import android.view.LayoutInflater;
@@ -28,11 +29,14 @@
2829
import android.widget.LinearLayout;
2930

3031
import com.stepstone.stepper.R;
31-
import com.stepstone.stepper.util.TintUtil;
32+
import com.stepstone.stepper.internal.util.TintUtil;
33+
34+
import static android.support.annotation.RestrictTo.Scope.LIBRARY;
3235

3336
/**
3437
* An indicator displaying the current position in a list of items with dots.
3538
*/
39+
@RestrictTo(LIBRARY)
3640
public class DottedProgressBar extends LinearLayout {
3741

3842
private static final float FULL_SCALE = 1f;

0 commit comments

Comments
 (0)