Skip to content

Commit

Permalink
Added callbacks for changes on step completion status and created new…
Browse files Browse the repository at this point in the history
… version of the library
  • Loading branch information
ernestoyaquello committed Nov 22, 2018
1 parent 6aa1690 commit bad5d59
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 9 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Add the library to your project via Gradle:

```
dependencies {
implementation 'com.ernestoyaquello.stepperform:vertical-stepper-form:2.0.1'
implementation 'com.ernestoyaquello.stepperform:vertical-stepper-form:2.1.0'
}
```

Expand Down Expand Up @@ -74,6 +74,7 @@ public class UserNameStep extends Step<String> {
protected IsDataValid isStepDataValid(String stepData) {
// The step's data (i.e., the user name) will be considered valid only if it is longer than
// three characters. In case it is not, we will display an error message for feedback.
// In an optional step, you should implement this method to always return a valid value.
boolean isNameValid = stepData.length() >= 3;
String errorMessage = !isNameValid ? "3 characters minimum" : "";

Expand Down Expand Up @@ -103,7 +104,17 @@ public class UserNameStep extends Step<String> {

@Override
protected void onStepClosed(boolean animated) {
// This will be closed automatically whenever the step gets closed.
// This will be called automatically whenever the step gets closed.
}

@Override
protected void onStepMarkedAsCompleted(boolean animated) {
// This will be called automatically whenever the step is marked as completed.
}

@Override
protected void onStepMarkedAsUncompleted(boolean animated) {
// This will be called automatically whenever the step is marked as uncompleted.
}

@Override
Expand All @@ -114,7 +125,9 @@ public class UserNameStep extends Step<String> {
}
```

Most of the methods showed above will be called automatically by the library. For example, every time the user opens a step, the open step will be marked as completed or uncompleted depending on the value returned by `isStepDataValid()` (you can implement it to always return a valid value in case the step is optional).
Most of the methods showed above will be called automatically by the library. For example, every time the user opens a step, the callback `onStepOpened()` will be invoked and the open step will be marked as completed or uncompleted automatically depending on the value returned by `isStepDataValid()`. Then, the callback `onStepMarkedAsCompleted()`, if applicable, will also be invoked.

It is worth noting that each step has a reference to the context accessible through `getContext()` and a reference to the form accessible through `getFormView()`, as well as several other useful methods.

### 4. Set Up The Form And Initialize It
Once you have defined all your steps, you will need to find the view of the form to set it up and initialize it:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ protected void onStepClosed(boolean animated) {
// No need to do anything here
}

@Override
protected void onStepMarkedAsCompleted(boolean animated) {
// No need to do anything here
}

@Override
protected void onStepMarkedAsUncompleted(boolean animated) {
// No need to do anything here
}

@Override
public boolean[] getStepData() {
return alarmDays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ protected void onStepClosed(boolean animated) {
// No need to do anything here
}

@Override
protected void onStepMarkedAsCompleted(boolean animated) {
// No need to do anything here
}

@Override
protected void onStepMarkedAsUncompleted(boolean animated) {
// No need to do anything here
}

@Override
public String getStepData() {
Editable text = alarmDescriptionEditText.getText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ protected void onStepClosed(boolean animated) {
// No need to do anything here
}

@Override
protected void onStepMarkedAsCompleted(boolean animated) {
// No need to do anything here
}

@Override
protected void onStepMarkedAsUncompleted(boolean animated) {
// No need to do anything here
}

@Override
public String getStepData() {
Editable text = alarmNameEditText.getText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ protected void onStepClosed(boolean animated) {
// No need to do anything here
}

@Override
protected void onStepMarkedAsCompleted(boolean animated) {
// No need to do anything here
}

@Override
protected void onStepMarkedAsUncompleted(boolean animated) {
// No need to do anything here
}

@Override
public TimeHolder getStepData() {
return new TimeHolder(alarmTimeHour, alarmTimeMinutes);
Expand Down
8 changes: 4 additions & 4 deletions vertical-stepper-form/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ ext {

libraryDescription = 'A highly customizable vertical stepper form for Android.'

siteUrl = 'https://github.com/ernestoyaquello/vertical-stepper-form'
gitUrl = 'https://github.com/ernestoyaquello/vertical-stepper-form.git'
siteUrl = 'https://github.com/ernestoyaquello/VerticalStepperForm'
gitUrl = 'https://github.com/ernestoyaquello/VerticalStepperForm.git'

libraryVersion = '2.0.1'
libraryVersion = '2.1.0'

developerId = 'ernestoyaquello'
developerName = 'Julio Ernesto Rodríguez Cabañas'
Expand All @@ -32,7 +32,7 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 11
versionCode 12
versionName libraryVersion
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,38 @@ protected Step(String title, String subtitle, String nextButtonText) {
* This method will be called every time the step is opened.
*
* @param animated True if the step was opened using animations; false otherwise.
* It will only be false if the step was opened on loading or on restoration.
* Generally, it will only be false if the step was opened on loading or on
* restoration.
*/
protected abstract void onStepOpened(boolean animated);

/**
* This method will be called every time the step is closed.
*
* @param animated True if the step was closed using animations; false otherwise.
* It will only be false if the step was closed on loading or on restoration.
* Generally, it will only be false if the step was closed on loading or on
* restoration.
*/
protected abstract void onStepClosed(boolean animated);

/**
* This method will be called every time the step is marked as completed.
*
* @param animated True if the step was marked as completed using animations; false otherwise.
* Generally, it will only be false if the step was marked as completed on
* loading or on restoration.
*/
protected abstract void onStepMarkedAsCompleted(boolean animated);

/**
* This method will be called every time the step is marked as uncompleted.
*
* @param animated True if the step was marked as uncompleted using animations; false otherwise.
* Generally, it will only be false if the step was marked as uncompleted on
* loading or on restoration.
*/
protected abstract void onStepMarkedAsUncompleted(boolean animated);

/**
* Gets the title of this step.
*
Expand Down Expand Up @@ -303,6 +323,11 @@ private void updateStepCompletionState(boolean completed, String errorMessage, b

updateErrorMessage(errorMessage, useAnimations);
onUpdatedStepCompletionState(useAnimations);
if (completed) {
onStepMarkedAsCompleted(useAnimations);
} else {
onStepMarkedAsUncompleted(useAnimations);
}
}

private void updateStepVisibility(boolean visibility, boolean useAnimations) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,5 +507,15 @@ protected void onStepOpened(boolean animated) {
protected void onStepClosed(boolean animated) {
markAsUncompleted("", animated);
}

@Override
protected void onStepMarkedAsCompleted(boolean animated) {
// No need to do anything here
}

@Override
protected void onStepMarkedAsUncompleted(boolean animated) {
// No need to do anything here
}
}
}

0 comments on commit bad5d59

Please sign in to comment.