Giter Site home page Giter Site logo

wellingtoncosta / convalida Goto Github PK

View Code? Open in Web Editor NEW
204.0 204.0 19.0 605 KB

A simple, lightweight and powerful field validation library for Android.

Home Page: https://wellingtoncosta.github.io/convalida

License: Apache License 2.0

Java 96.76% Kotlin 3.02% Shell 0.21%
android android-databinding android-library annotations code-generation compile-time field-validation java

convalida's People

Contributors

emanuelet avatar wellingtoncosta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

convalida's Issues

Build issues on api 27

First the project compiles with the following dependencies.

compile 'com.github.WellingtonCosta:convalida:1.3.4'
annotationProcessor 'com.github.WellingtonCosta.convalida:convalida-compiler:1.3.4'

Second of all, when I try to run the project I get the errors:

Error:java.lang.IllegalAccessException: no such method: convalida.compiler.ConvalidaProcessor.lambda$parseValidateOnClick$0(Element)boolean/invokeStatic
Error:java.lang.NoClassDefFoundError: com/sun/tools/javac/tree/JCTree$Visitor
Error:java.lang.ClassNotFoundException: Class com.sun.tools.javac.tree.JCTree$Visitor not found

Auto dismiss in validations

Add autoDismiss parameter in annotations.

Example:

@NotEmptyValidation(errorMessage=R.string.field_required, autoDismiss=true)
EditText nameField;

Custom validations

This feature will provide a mechanism for developers to create their own custom validations. A developer must write custom annotations and its validator classes.

Just thanks

Just wanted to say thanks for your project. It's actually helpful and modern.
You can close this issue right away.

CPF validation

Hello @wellingtoncosta,

Does your library support CPF(Brazil personal number) validation?
If not, it would be awesome to have this available in your library.

Thanks,

Validate difference between fields

Hello @wellingtoncosta,
Another improvement could be the validation of difference between two fields.
Ex.:
difference = incial distance - final distance, where incial distance can not be bigger than final distance.

Regards,

Add ability to unregister validation set

clearValidations() just clears errors on text inputs, but if user adds/removes any letter the error appears again, which is not always wanted behaviour.

There should be way to fully unregister validation set so text input won't trigger any error on edit.

Databinding support

This feature will provides support to use the validations by databinding.

validation on fragment is not working after back pressed

I am using kotlin DSL for validation. I have multiple fragments opening after one another for user input. Each fragment has validation using code:

Sample code

private val validations by lazy {
	validationSet(
		validations = listOf(
			binding.txtSomething.isRequired(errorMessage = getString(R.string.field_required))
		),
		actions = actions
				validateByClickingOn binding.btnNext
				whenOnSuccess ::onValidationSuccess
	)
}

If I press the back button in between, validation stops working.

Observations:

  1. apply { validations } gets called once again once user comes back on fragment
  2. validateByClickingOn binding.btnNext
    whenOnSuccess ::onValidationSucces does not get called second time

Add ability for delayed validation

Another option for validation is delayed one. Say, if I write 10 letters and suddenly stop writing them, the validation can chime in and mark field to be invalid.

Support to apply validations using a Kotlin DSL

This feature will able Convalida to apply the validations using a Kotlin DSL that will be must defined. This will generate an artifact called convalida-ktx.

Maybe this will turn possible to use Convalida with Anko #23.

Kotlin compiler Null Pointer exception

I got the following compile error when I tried to update to the version 3.2.0 of the library.

I don't use data-binding and I tried with both version 1.3.41 and 1.3.50 of the kotlin plugin. I tried also to set android.databinding.enableV2=false in gradle.properties to no avail

[kapt] An exception occurred: java.lang.NullPointerException
	at convalida.compiler.ProcessingOptions.isDatabindingEnabled(ProcessingOptions.java:34)
	at convalida.compiler.util.JavaFiler.cookJava(JavaFiler.java:104)
	at convalida.compiler.ConvalidaProcessor.process(ConvalidaProcessor.java:184)
	at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.process(incrementalProcessors.kt)
	at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:147)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
	at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
	at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1068)
	at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:79)
	at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:35)
	at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:224)
	at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:187)
	at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:98)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:97)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:107)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:82)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:557)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:82)
	at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:107)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:548)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:177)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:165)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:55)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:84)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:42)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:104)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1558)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
	at sun.rmi.transport.Transport$1.run(Transport.java:200)
	at sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

New way to execute the validations

This feature will improve the way that developers execute and manipulate validations, making the code cleaner through annotations.

New annotations:

@ValidateOnClick

@ClearValidationsOnClick

@OnValidationSuccess

@OnValidationError 
  • The ValidateOnClick annotation must be mapped to a Button element, that will add a OnClickListener event to the button and will execute validateFields() method of ConvalidaValiddator class.

  • The ClearValidationsOnClick annotation must be mapped to a Button element, that will add a OnClickListener event to the button and will execute clearValidations() method of ConvalidaValiddator class.

  • The OnValidationSuccess annotation must be mapped to a method that will be executed if the all validations will be passed.

  • The OnValidationError annotation must be mapped to a method that will be executed if some field is not valid.

Example:

public class SampleActivity extends AppCompatActivity {

    @NotEmptyValidation(R.string.field_required)
    TextInputLayout nameLayout;

    @EmailValidation(R.string.invalid_email)
    TextInputLayout emailLayout;

    @OnlyNumberValidation(R.string.only_numbers)
    TextInputLayout ageLayout;

    @ValidateOnClick
    Button validateButton;

    @ClearValidationsOnClick
    Button clearValidationsButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sample);
        Convalida.init(this);
    }

    @OnValidationSuccess
    public void onValidationSuccess() {
        // Code ...
    }

    @OnValidationError
    public void onValidationError() {
        // Code ...
    }
}

Anko support

Hi,

Any ideas on how to plug it with Kotlin Anko library? I tend to use it and skip data binding, so not sure how I'd put the annotations.

Eliminate reflection code in the search for generated classes

This issue aims to eliminate the reflection code to find and instantiate the generated classes.

Currently, when the Convalida.init(this) is called, internally the library uses reflection to find and instantiate the generated classes for fields validation. It's not a good practice in Android.

After this implementation, probably the Convalida.init(this) will no longer be necessary.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.