This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface TextValidator { | |
| /*Outputs null for no errors, or else the error in a user friendly text*/ | |
| String validate(String content); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface SimpleCallback<T> { | |
| void call(T payload); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface TextViewHelper { | |
| default String getTextAsString(TextView textView){ | |
| return textView.getText().toString(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AutoValidatedTextInputEditText extends TextInputEditText implements AutoValidatedUserInputComponent, TextViewHelper { | |
| List<TextValidator> validatorList = new ArrayList<>(); | |
| boolean isValid = false; | |
| public AutoValidatedTextInputEditText(Context context) { | |
| super(context); | |
| SimpleCallback callback = payload -> validate(); | |
| setOnFocusChangeListener(new OnFocusChangeListener(callback)); | |
| addTextChangedListener(new OnTextChangeListener(callback)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface AutoValidatedUserInputComponent { | |
| boolean hasValidInput(); | |
| boolean requestFocus();/* This one is usually already implemented on View objects*/ | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Retention(RetentionPolicy.RUNTIME) | |
| @Target(ElementType.FIELD) | |
| public @interface ValidComponent {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ComponentValidator { | |
| private static final ComponentValidator _instance; | |
| static { | |
| _instance = new ComponentValidator(); | |
| } | |
| private ComponentValidator() { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @ValidComponent | |
| AutoValidatedTextInputEditText usernameEditText; | |
| @ValidComponent | |
| AutoValidatedTextInputEditText birthdateEditText; | |
| Button submit; | |
| /* ... snip ... */ | |
| final static String userFriendlyBirthdayDateFormat = "MM/dd/yy"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface Callback<T> { | |
| default void onSuccessfulResponse(ResponseBody<T> responseBody) { | |
| } | |
| default void onBadRequest(List<ErrorModel> errors) { | |
| } | |
| default void onServerError(Response response) { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ApiResponseCallbackAdapter<T> implements Callback<ApiResponse<T>> { | |
| Callback<T> callback; | |
| public ApiResponseCallbackAdapter(Callback<T> callback) { | |
| this.callback = callback; | |
| } | |
| @Override | |
| public void onResponse(Call<ApiResponse<T>> call, Response<ApiResponse<T>> response) { |