Skip to content

Instantly share code, notes, and snippets.

View ntakouris's full-sized avatar
🤖
Building robots

Theodoros Ntakouris ntakouris

🤖
Building robots
View GitHub Profile
public interface TextValidator {
/*Outputs null for no errors, or else the error in a user friendly text*/
String validate(String content);
}
public interface SimpleCallback<T> {
void call(T payload);
}
public interface TextViewHelper {
default String getTextAsString(TextView textView){
return textView.getText().toString();
}
}
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));
public interface AutoValidatedUserInputComponent {
boolean hasValidInput();
boolean requestFocus();/* This one is usually already implemented on View objects*/
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ValidComponent {}
public class ComponentValidator {
private static final ComponentValidator _instance;
static {
_instance = new ComponentValidator();
}
private ComponentValidator() {
}
@ValidComponent
AutoValidatedTextInputEditText usernameEditText;
@ValidComponent
AutoValidatedTextInputEditText birthdateEditText;
Button submit;
/* ... snip ... */
final static String userFriendlyBirthdayDateFormat = "MM/dd/yy";
public interface Callback<T> {
default void onSuccessfulResponse(ResponseBody<T> responseBody) {
}
default void onBadRequest(List<ErrorModel> errors) {
}
default void onServerError(Response response) {
}
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) {