static
This commit is contained in:
parent
c1849585be
commit
4833c12364
|
|
@ -24,4 +24,9 @@ package ru.touchin.templates.validation;
|
|||
* TODO: fill
|
||||
*/
|
||||
public class ConversionException extends Exception {
|
||||
|
||||
public ConversionException(final Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
package ru.touchin.templates.validation.validationcontrollers;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -42,26 +43,11 @@ public class EditTextValidationController<TModel extends Serializable>
|
|||
|
||||
@NonNull
|
||||
public Observable<?> validation(@NonNull final Observable<Boolean> focusOutObservable, @NonNull final Observable<Boolean> activatedObservable) {
|
||||
return Observable
|
||||
.<Boolean, String, Boolean, Boolean, NonNullPair<Boolean, Observable<ValidationState>>>combineLatest(activatedObservable,
|
||||
getValidator().getWrapperModel().observe(),
|
||||
focusOutObservable,
|
||||
getValidator().getShowFullCheck().observe(),
|
||||
(activated, text, focusIn, showError) -> {
|
||||
if (focusIn == null && TextUtils.isEmpty(text) && !activated && !showError) {
|
||||
return null;
|
||||
}
|
||||
final boolean focus = focusIn == null ? false : focusIn;
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
return new NonNullPair<>(focus, (activated || showError)
|
||||
? getValidator().getValidationStateWhenEmpty().observe()
|
||||
: Observable.just(ValidationState.INITIAL));
|
||||
}
|
||||
if (!showError && focus) {
|
||||
return new NonNullPair<>(true, getValidator().primaryValidate(text));
|
||||
}
|
||||
return new NonNullPair<>(focus, getValidator().fullValidate(text));
|
||||
})
|
||||
return Observable.combineLatest(activatedObservable,
|
||||
getValidator().getWrapperModel().observe(),
|
||||
focusOutObservable,
|
||||
getValidator().getShowFullCheck().observe(),
|
||||
this::getValidationPair)
|
||||
.switchMap(validationPair -> {
|
||||
if (validationPair == null) {
|
||||
return Observable.empty();
|
||||
|
|
@ -76,4 +62,25 @@ public class EditTextValidationController<TModel extends Serializable>
|
|||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
|
||||
private NonNullPair<Boolean, Observable<ValidationState>> getValidationPair(final boolean activated,
|
||||
@Nullable final String text,
|
||||
@Nullable final Boolean focusIn,
|
||||
final boolean showError) {
|
||||
if (focusIn == null && TextUtils.isEmpty(text) && !activated && !showError) {
|
||||
return null;
|
||||
}
|
||||
final boolean focus = focusIn == null ? false : focusIn;
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
return new NonNullPair<>(focus, (activated || showError)
|
||||
? getValidator().getValidationStateWhenEmpty().observe()
|
||||
: Observable.just(ValidationState.INITIAL));
|
||||
}
|
||||
if (!showError && focus) {
|
||||
return new NonNullPair<>(true, getValidator().primaryValidate(text));
|
||||
}
|
||||
return new NonNullPair<>(focus, getValidator().fullValidate(text));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -27,7 +27,7 @@ import ru.touchin.templates.validation.validators.Validator;
|
|||
* Created by Ilia Kurtov on 24/01/2017.
|
||||
* TODO: fill
|
||||
*/
|
||||
public abstract class ValidationController<TValidator extends Validator> {
|
||||
public class ValidationController<TValidator extends Validator> {
|
||||
|
||||
@NonNull
|
||||
private final TValidator validator;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ import ru.touchin.templates.validation.ValidationFunc;
|
|||
import ru.touchin.templates.validation.ValidationState;
|
||||
import rx.Observable;
|
||||
import rx.exceptions.OnErrorThrowable;
|
||||
import rx.functions.Func1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue