diff --git a/app/src/main/java/verticalstepperform/ernestoyaquello/com/verticalstepperform/NewAlarmFormActivity.java b/app/src/main/java/verticalstepperform/ernestoyaquello/com/verticalstepperform/NewAlarmFormActivity.java index e91a4fc..91cf3ab 100644 --- a/app/src/main/java/verticalstepperform/ernestoyaquello/com/verticalstepperform/NewAlarmFormActivity.java +++ b/app/src/main/java/verticalstepperform/ernestoyaquello/com/verticalstepperform/NewAlarmFormActivity.java @@ -2,7 +2,6 @@ import android.app.Dialog; import android.app.ProgressDialog; -import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; diff --git a/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/Builder.java b/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/Builder.java index be60234..b86d788 100644 --- a/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/Builder.java +++ b/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/Builder.java @@ -422,6 +422,19 @@ public Builder allowStepOpeningOnHeaderClick(boolean allowStepOpeningOnHeaderCli return this; } + /** + * Specifies whether or not the last step will be closed when the form is completed. + * + * @param closeLastStepOnCompletion True to make the last step close automatically on completion; + * false to not. + * @return The builder instance. + */ + public Builder closeLastStepOnCompletion(boolean closeLastStepOnCompletion) { + formView.style.closeLastStepOnCompletion = closeLastStepOnCompletion; + + return this; + } + /** * Sets up the form and initializes it. */ diff --git a/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/StepHelper.java b/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/StepHelper.java index 62afe9d..662f843 100644 --- a/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/StepHelper.java +++ b/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/StepHelper.java @@ -525,7 +525,9 @@ protected void onStepOpened(boolean animated) { @Override protected void onStepClosed(boolean animated) { - markAsUncompleted("", animated); + if (!getFormView().isFormCompleted()) { + markAsUncompleted("", animated); + } } @Override diff --git a/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/VerticalStepperFormView.java b/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/VerticalStepperFormView.java index 35fbc03..4f025ec 100644 --- a/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/VerticalStepperFormView.java +++ b/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/VerticalStepperFormView.java @@ -222,6 +222,17 @@ public boolean areAllStepsCompleted() { return areAllPreviousStepsCompleted(stepHelpers.size()); } + /** + * Determines whether the form has already been completed or cancelled. + * Please note that this could return false even if all the steps are completed (for example, + * if the user has filled in all the required data but hasn't submitted the form yet). + * + * @return True if the form has been completed or cancelled; false otherwise. + */ + public boolean isFormCompleted() { + return formCompleted; + } + /** * If possible, goes to the step that is positioned after the currently open one, closing the * current one and opening the next one. @@ -413,17 +424,24 @@ public synchronized void cancelFormCompletionOrCancellationAttempt() { } int openedStepPosition = getOpenStepPosition(); - if (openedStepPosition >= 0 && openedStepPosition < stepHelpers.size()) { - StepHelper stepHelper = stepHelpers.get(openedStepPosition); - if ((openedStepPosition + 1) < stepHelpers.size() || areAllStepsCompleted()) { - stepHelper.enableAllButtons(); - } else { - stepHelper.enableCancelButton(); + openedStepPosition = openedStepPosition == -1 ? stepHelpers.size() - 1 : openedStepPosition; + StepHelper stepHelper = stepHelpers.get(openedStepPosition); + + if (style.closeLastStepOnCompletion) { + Step step = stepHelper.getStepInstance(); + if (!step.isOpen()) { + step.openInternal(true); } + } - formCompleted = false; - updateBottomNavigationButtons(); + if ((openedStepPosition + 1) < stepHelpers.size() || areAllStepsCompleted()) { + stepHelper.enableAllButtons(); + } else { + stepHelper.enableCancelButton(); } + + formCompleted = false; + updateBottomNavigationButtons(); } /** @@ -523,6 +541,7 @@ private void onConstructed(Context context, AttributeSet attrs, int defStyleAttr style.includeConfirmationStep = true; style.allowNonLinearNavigation = false; style.allowStepOpeningOnHeaderClick = true; + style.closeLastStepOnCompletion = false; style.alphaOfDisabledElements = 0.3f; // Try to get the user values for the style properties to replace the default ones @@ -644,6 +663,9 @@ private void onConstructed(Context context, AttributeSet attrs, int defStyleAttr style.allowStepOpeningOnHeaderClick = vars.getBoolean( R.styleable.VerticalStepperFormView_form_allow_step_opening_on_header_click, style.allowStepOpeningOnHeaderClick); + style.closeLastStepOnCompletion = vars.getBoolean( + R.styleable.VerticalStepperFormView_form_close_last_step_on_completion, + style.closeLastStepOnCompletion); style.alphaOfDisabledElements = vars.getFloat( R.styleable.VerticalStepperFormView_form_alpha_of_disabled_elements, style.alphaOfDisabledElements); @@ -804,6 +826,10 @@ private synchronized void attemptToCompleteForm(boolean isCancellation) { // If the completion attempt fails, we restore the confirmation step to its previous state lastStep.markAsUncompleted(confirmationStepErrorMessage, true); } + + if (!isCancellation && style.closeLastStepOnCompletion) { + lastStep.closeInternal(true); + } } @Override @@ -1029,6 +1055,7 @@ class FormStyle { boolean includeConfirmationStep; boolean allowNonLinearNavigation; boolean allowStepOpeningOnHeaderClick; + boolean closeLastStepOnCompletion; float alphaOfDisabledElements; } diff --git a/vertical-stepper-form/src/main/res/values/attrs.xml b/vertical-stepper-form/src/main/res/values/attrs.xml index 773f117..a579e7a 100644 --- a/vertical-stepper-form/src/main/res/values/attrs.xml +++ b/vertical-stepper-form/src/main/res/values/attrs.xml @@ -37,6 +37,7 @@ +