Skip to content

Setting error state programmatically #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
import android.widget.LinearLayout;

import com.stepstone.stepper.adapter.StepAdapter;
import com.stepstone.stepper.internal.ColorableProgressBar;
import com.stepstone.stepper.internal.DottedProgressBar;
import com.stepstone.stepper.internal.RightNavigationButton;
import com.stepstone.stepper.internal.TabsContainer;
import com.stepstone.stepper.type.AbstractStepperType;
import com.stepstone.stepper.type.StepperTypeFactory;
import com.stepstone.stepper.util.AnimationUtil;
import com.stepstone.stepper.util.TintUtil;
import com.stepstone.stepper.internal.widget.ColorableProgressBar;
import com.stepstone.stepper.internal.widget.DottedProgressBar;
import com.stepstone.stepper.internal.widget.RightNavigationButton;
import com.stepstone.stepper.internal.widget.TabsContainer;
import com.stepstone.stepper.internal.type.AbstractStepperType;
import com.stepstone.stepper.internal.type.StepperTypeFactory;
import com.stepstone.stepper.internal.util.AnimationUtil;
import com.stepstone.stepper.internal.util.TintUtil;
import com.stepstone.stepper.viewmodel.StepViewModel;

/**
Expand Down Expand Up @@ -117,10 +117,18 @@ public void onReturn() {
};
}

public final class OnNextClickedCallback {
public abstract class AbstractOnButtonClickedCallback {

public StepperLayout getStepperLayout() {
return StepperLayout.this;
}

}

public class OnNextClickedCallback extends AbstractOnButtonClickedCallback {

@UiThread
public final void goToNextStep() {
public void goToNextStep() {
final int totalStepCount = mStepAdapter.getCount();

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

}

public final class OnBackClickedCallback {
public class OnBackClickedCallback extends AbstractOnButtonClickedCallback {

@UiThread
public final void goToPrevStep() {
public void goToPrevStep() {
if (mCurrentStepPosition <= 0) {
if (mShowBackButtonOnFirstStep) {
mListener.onReturn();
Expand Down Expand Up @@ -372,19 +380,32 @@ public void setCompleteButtonVerificationFailed(boolean verificationFailed) {
/**
* Set whether when going backwards should clear the error state from the Tab. Default is <code>false</code>.
*
* @param mShowErrorStateOnBack true if navigating backwards should keep the error state, false otherwise
* @param showErrorStateOnBack true if navigating backwards should keep the error state, false otherwise
*/
public void setShowErrorStateOnBack(boolean mShowErrorStateOnBack) {
this.mShowErrorStateOnBack = mShowErrorStateOnBack;
public void setShowErrorStateOnBack(boolean showErrorStateOnBack) {
this.mShowErrorStateOnBack = showErrorStateOnBack;
}

/**
* Set whether the errors should be displayed when they occur or not. Default is <code>false</code>.
*
* @param mShowErrorState true if the errors should be displayed when they occur, false otherwise
* @param showErrorState true if the errors should be displayed when they occur, false otherwise
*/
public void setShowErrorState(boolean mShowErrorState) {
this.mShowErrorState = mShowErrorState;
public void setShowErrorState(boolean showErrorState) {
this.mShowErrorState = showErrorState;
}

/**
* Updates the error state in the UI.
* It does nothing if showing error state is disabled.
* This is used internally to show the error on tabs.
* @param hasError true if error should be shown, false otherwise
* @see #setShowErrorState(boolean)
*/
public void updateErrorState(boolean hasError) {
if (mShowErrorState) {
mStepperType.setErrorState(mCurrentStepPosition, hasError);
}
}

/**
Expand Down Expand Up @@ -597,9 +618,7 @@ private void onNext() {
}

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

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

//if moving forward and got errors, set hasError to true, showing the error drawable.
if (mShowErrorState) {
mStepperType.setErrorStep(mCurrentStepPosition, true);
}
updateErrorState(true);

}
mListener.onError(verificationError);
}
Expand All @@ -636,7 +654,7 @@ private void onComplete() {
if (verifyCurrentStep(step)) {
return;
}
mStepperType.setErrorStep(mCurrentStepPosition, false);
updateErrorState(false);
mListener.onCompleted(mCompleteNavigationButton);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@
limitations under the License.
*/

package com.stepstone.stepper.type;
package com.stepstone.stepper.internal.type;

import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.RestrictTo;

import com.stepstone.stepper.StepperLayout;
import com.stepstone.stepper.adapter.StepAdapter;

import static android.support.annotation.RestrictTo.Scope.LIBRARY;

/**
* A base stepper type all stepper types must extend.
*/
@RestrictTo(LIBRARY)
public abstract class AbstractStepperType {

/**
Expand Down Expand Up @@ -59,7 +63,7 @@ public AbstractStepperType(StepperLayout stepperLayout) {
* @param stepPosition the step to set the error
* @param hasError whether it has error or not
*/
public void setErrorStep(int stepPosition, boolean hasError){ }
public void setErrorState(int stepPosition, boolean hasError){ }

/**
* Called to set whether navigating backwards should keep the error state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@
limitations under the License.
*/

package com.stepstone.stepper.type;
package com.stepstone.stepper.internal.type;

import android.support.annotation.NonNull;
import android.support.annotation.RestrictTo;
import android.view.View;

import com.stepstone.stepper.R;
import com.stepstone.stepper.StepperLayout;
import com.stepstone.stepper.adapter.StepAdapter;
import com.stepstone.stepper.internal.DottedProgressBar;
import com.stepstone.stepper.internal.widget.DottedProgressBar;

import static android.support.annotation.RestrictTo.Scope.LIBRARY;

/**
* Stepper type which displays mobile step dots.
*/
@RestrictTo(LIBRARY)
public class DotsStepperType extends AbstractStepperType {

private static final int EDIT_MODE_DOT_COUNT = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@
limitations under the License.
*/

package com.stepstone.stepper.type;
package com.stepstone.stepper.internal.type;

import android.support.annotation.NonNull;
import android.support.annotation.RestrictTo;
import android.view.View;

import com.stepstone.stepper.R;
import com.stepstone.stepper.StepperLayout;
import com.stepstone.stepper.adapter.StepAdapter;
import com.stepstone.stepper.internal.ColorableProgressBar;
import com.stepstone.stepper.internal.widget.ColorableProgressBar;

import static android.support.annotation.RestrictTo.Scope.LIBRARY;

/**
* Stepper type which displays a mobile step progress bar.
*/
@RestrictTo(LIBRARY)
public class ProgressBarStepperType extends AbstractStepperType {

private final ColorableProgressBar mProgressBar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@
limitations under the License.
*/

package com.stepstone.stepper.type;
package com.stepstone.stepper.internal.type;

import android.support.annotation.RestrictTo;
import android.util.Log;

import com.stepstone.stepper.StepperLayout;

import static android.support.annotation.RestrictTo.Scope.LIBRARY;

/**
* Factory class for creating stepper types.
*/
@RestrictTo(LIBRARY)
public class StepperTypeFactory {

private static final String TAG = StepperTypeFactory.class.getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,28 @@
limitations under the License.
*/

package com.stepstone.stepper.type;
package com.stepstone.stepper.internal.type;

import android.support.annotation.NonNull;
import android.support.annotation.RestrictTo;
import android.view.View;

import com.stepstone.stepper.R;
import com.stepstone.stepper.StepperLayout;
import com.stepstone.stepper.adapter.StepAdapter;
import com.stepstone.stepper.internal.TabsContainer;
import com.stepstone.stepper.internal.widget.TabsContainer;
import com.stepstone.stepper.viewmodel.StepViewModel;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static android.support.annotation.RestrictTo.Scope.LIBRARY;

/**
* Stepper type which displays horizontal stepper with tabs.
*/
@RestrictTo(LIBRARY)
public class TabsStepperType extends AbstractStepperType {

private static final List<CharSequence> EDIT_MODE_STEP_TITLES = Arrays.<CharSequence>asList("Step 1", "Step 2");
Expand Down Expand Up @@ -66,7 +70,7 @@ public void onStepSelected(int newStepPosition) {
* {@inheritDoc}
*/
@Override
public void setErrorStep(int stepPosition, boolean hasError) {
public void setErrorState(int stepPosition, boolean hasError) {
mTabsContainer.setErrorStep(stepPosition, hasError);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package com.stepstone.stepper.util;
package com.stepstone.stepper.internal.util;

import android.animation.Animator;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.RestrictTo;
import android.view.View;
import android.view.ViewPropertyAnimator;

import java.lang.annotation.Retention;

import static android.support.annotation.RestrictTo.Scope.LIBRARY;
import static java.lang.annotation.RetentionPolicy.SOURCE;

/**
* Util class containing static methods to simplify animation.
*/
@RestrictTo(LIBRARY)
public final class AnimationUtil {

@Retention(SOURCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package com.stepstone.stepper.util;
package com.stepstone.stepper.internal.util;

import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
Expand All @@ -24,13 +24,17 @@
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RestrictTo;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.util.Log;
import android.widget.TextView;

import static android.support.annotation.RestrictTo.Scope.LIBRARY;

/**
* Utility class for tinting drawables/widgets.
*/
@RestrictTo(LIBRARY)
public class TintUtil {

private static final String TAG = TintUtil.class.getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,27 @@
limitations under the License.
*/

package com.stepstone.stepper.internal;
package com.stepstone.stepper.internal.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.support.annotation.ColorInt;
import android.support.annotation.RestrictTo;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.widget.ProgressBar;

import com.stepstone.stepper.R;
import com.stepstone.stepper.util.TintUtil;
import com.stepstone.stepper.internal.util.TintUtil;

import static android.support.annotation.RestrictTo.Scope.LIBRARY;

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

@ColorInt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
limitations under the License.
*/

package com.stepstone.stepper.internal;
package com.stepstone.stepper.internal.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.RestrictTo;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.LayoutInflater;
Expand All @@ -28,11 +29,14 @@
import android.widget.LinearLayout;

import com.stepstone.stepper.R;
import com.stepstone.stepper.util.TintUtil;
import com.stepstone.stepper.internal.util.TintUtil;

import static android.support.annotation.RestrictTo.Scope.LIBRARY;

/**
* An indicator displaying the current position in a list of items with dots.
*/
@RestrictTo(LIBRARY)
public class DottedProgressBar extends LinearLayout {

private static final float FULL_SCALE = 1f;
Expand Down
Loading