11 |
12 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 |
3 | jdk: oraclejdk8
4 |
5 | android:
6 | components:
7 | - tools
8 | - platform-tools
9 | - build-tools-28.0.3
10 | - android-28
11 | - extra-android-m2repository
12 | - extra-google-m2repository
13 |
14 | sudo: required
15 |
16 | licenses:
17 | - android-sdk-preview-license-.+
18 | - android-sdk-license-.+
19 |
20 | before_install:
21 | - chmod +x gradlew
22 |
23 | script:
24 | - ./gradlew clean build jacocoTestReport check
25 |
26 | after_success:
27 | - bash <(curl -s https://codecov.io/bash)
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | CHANGELOG
2 | =========
3 |
4 | 2.0.0
5 | --------
6 | 02.05.2019
7 | **Released**
8 |
9 | 01.05.2019
10 | **library:**
11 | - migrate to new gradle
12 | - migrate to androidx
13 | - change min sdk to 14
14 |
15 | **sample application:**
16 | - migrate to new gradle
17 | - migrate to androidx
18 |
19 | 1.0.2
20 | --------
21 | 26.03.2017
22 | **Released**
23 |
24 | 25.03.2017
25 |
26 | **library:**
27 | - added `setErrorMessage` to `ValidatedObservableField`
28 | - added call `notifyChange` into: `validate`, `hideErrorMessage`
29 | - updated `validate`, now it return true if there was an rule to validate
30 | - added more tests
31 |
32 | 19.03.2017
33 |
34 | - added travis
35 | - added code cov
36 | - fix some configurator for travis
37 |
38 | 1.0.1
39 | --------
40 | 13.03.2017
41 | **Released**
42 |
43 | **library:**
44 | - FIXED BUG: `android:allowBackup="false"` in `AndroidManifest.xml`
45 | - fixed building errors while making aar file
46 | - added `Valid` imterface
47 | - added `ValidatorRule` class - now we can create `Rule` with lambda
48 | - added method `withRule` to `RuleCommand.Builder` to add `Rule` created with lambda
49 |
50 | **sample application:**
51 | - added example with rule using OR expression
52 | - fix lint warnings
53 | - added example to show how create `Rule` with lambda
54 |
55 | 12.03.2017
56 |
57 | - added this changelog
58 |
59 | **library:**
60 | - start adding test
61 | - FIXED BUG in `ValidatedObservableField` in `setValue`
62 | - made `ValidatedObservableField.validate()` public
63 | - added new constructor to `ValidatedObservableField`
64 | - added javadocs to some classes
65 | - added tests for `ValidatedObservableField`
66 | - added tests coverage tool: jacoco-android
67 |
68 | **sample application:**
69 | - reorganize the application
70 | - main view is a list of all exemples
71 | - each sub view have seperated example
72 | - added example: single rule, multi rules, rules that validate values from others fields
73 |
74 |
75 | 1.0.0
76 | --------
77 | 04.03.2017
78 |
79 | - created base core of this library
80 | - created sample app
81 |
82 | **library:**
83 | - added `Rule`
84 | - added `ValidatedObservableField`
85 | - added `RuleCommand`
86 | - added `AbstractRule` as base for `Rule` implementations
87 | - added implementations for Rules: `RegexRule`, `MinimumLengthRule`, `MaximumLengthRule`
88 |
89 | **sample application:**
90 | - added Main Activity with View Model
91 | - added ValidatedObservableField to View Model
92 |
--------------------------------------------------------------------------------
/DroidMVVMValidator.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2017 Maciej Motak
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DroidMVVMValidator
2 | [](https://bintray.com/mmotak/snipcorp/droid-mvvm-validator/_latestVersion)
3 | [](https://travis-ci.org/mmotak/DroidMVVMValidator)
4 | [](https://codecov.io/gh/mmotak/DroidMVVMValidator)
5 |
6 | Simple and light library to do validate observable fields with MVVM for android
7 |
8 | Usage
9 | -----
10 |
11 | Each **ValidatedObservableField** work like **ObservableField**, but it have 3 observables properties:
12 | - **value** - contains the value of type T
13 | - **valid** - boolean true if ALL Rules are valid
14 | - **errorMessage** - contains NULL or errorMessage from first invalid Rule
15 |
16 | Rules are validated one by one (the order is important), the first invalid Rule will break the chain and set errorMessage.
17 | Rules are validated onPropertyChange.
18 | You can create your own rules using Rule interface.
19 | You can use single Rule or many by RuleCommand.
20 |
21 | ```java
22 | public ValidatedObservableField userName = new ValidatedObservableField<>("",
23 | new RuleCommand.Builder()
24 | .withRule(new RegexRule("[a-z]+", "Only small letters")) // THE ORDER IS IMPORTANT!
25 | .withRule(new MinimumLengthRule(3, "Three or more characters"))
26 | .withRule(new MaximumLengthRule(12, "No more then twelve characters"))
27 | .build());
28 | ```
29 |
30 | or using lambdas:
31 |
32 | ```java
33 | public ValidatedObservableField userName = new ValidatedObservableField<>("",
34 | new RuleCommand.Builder()
35 | .withRule(s -> s != null && s.matches("[\\S]+"), "Whitespace characters not allowed") // THE ORDER IS IMPORTANT!
36 | .withRule(s -> s != null && s.length() >= 3, "Three or more characters")
37 | .withRule(s -> s != null && s.length() <= 12, "No more then twelve characters")
38 | .build());
39 | ```
40 |
41 | ```xml
42 |
44 |
45 |
47 |
48 |
49 |
50 |
52 | ```
53 |
54 | Download
55 | --------
56 |
57 | You can depend on the library through Gradle:
58 |
59 | The new version androidx
60 | ```groovy
61 | repositories {
62 | jcenter()
63 | }
64 |
65 |
66 | dataBinding {
67 | enabled = true
68 | }
69 |
70 |
71 | dependencies {
72 | compile 'pl.com.mmotak.validator:droid-mvvm-validator:2.0.0'
73 | }
74 | ```
75 |
76 | The old version
77 | ```groovy
78 | repositories {
79 | jcenter()
80 | }
81 |
82 |
83 | dataBinding {
84 | enabled = true
85 | }
86 |
87 |
88 | dependencies {
89 | compile 'pl.com.mmotak.validator:droid-mvvm-validator:1.0.2'
90 | }
91 | ```
92 |
93 | Changelog
94 | ---------
95 |
96 | See [CHANGELOG.md](CHANGELOG.md) file.
97 |
98 |
99 | License
100 | -------
101 |
102 | Copyright 2017 Maciej Motak
103 |
104 | Licensed under the Apache License, Version 2.0 (the "License");
105 | you may not use this file except in compliance with the License.
106 | You may obtain a copy of the License at
107 |
108 | http://www.apache.org/licenses/LICENSE-2.0
109 |
110 | Unless required by applicable law or agreed to in writing, software
111 | distributed under the License is distributed on an "AS IS" BASIS,
112 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
113 | See the License for the specific language governing permissions and
114 | limitations under the License.
115 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | mavenCentral()
7 | google()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.4.0'
11 | classpath 'com.dicedmelon.gradle:jacoco-android:0.1.4'
12 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
13 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
14 |
15 | // NOTE: Do not place your application dependencies here; they belong
16 | // in the individual module build.gradle files
17 | }
18 | }
19 |
20 | allprojects {
21 | repositories {
22 | jcenter()
23 | google()
24 | }
25 | }
26 |
27 | task clean(type: Delete) {
28 | delete rootProject.buildDir
29 | }
30 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 | android.useAndroidX=true
19 | android.enableJetifier=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmotak/DroidMVVMValidator/b51051bf29417aa798f632ed6a70f7d135476db7/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu May 02 10:35:37 CEST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/sampleapp/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sampleapp/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | buildToolsVersion "28.0.3"
6 | defaultConfig {
7 | applicationId "pl.com.mmotak.sample"
8 | minSdkVersion 15
9 | targetSdkVersion 28
10 | versionCode 1
11 | versionName "2.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | dataBinding {
15 | enabled = true
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | compileOptions {
24 | targetCompatibility 1.8
25 | sourceCompatibility 1.8
26 | }
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 | implementation project(path: ':validator')
32 | implementation 'androidx.appcompat:appcompat:1.0.2'
33 | implementation 'androidx.cardview:cardview:1.0.0'
34 | implementation 'com.google.android.material:material:1.0.0'
35 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
36 |
37 | testImplementation 'junit:junit:4.12'
38 | }
39 |
--------------------------------------------------------------------------------
/sampleapp/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\_android\Android\android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/sampleapp/sampleapp.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateDebugSources
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
--------------------------------------------------------------------------------
/sampleapp/src/androidTest/java/pl/com/mmotak/sample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("pl.com.mmotak.sample", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/sampleapp/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
20 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
37 |
38 |
43 |
44 |
49 |
50 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/sampleapp/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmotak/DroidMVVMValidator/b51051bf29417aa798f632ed6a70f7d135476db7/sampleapp/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/Bindings.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample;
2 |
3 | import androidx.databinding.BindingAdapter;
4 | import androidx.databinding.InverseBindingAdapter;
5 | import android.text.method.HideReturnsTransformationMethod;
6 | import android.text.method.PasswordTransformationMethod;
7 | import android.widget.TextView;
8 |
9 | import com.google.android.material.textfield.TextInputEditText;
10 |
11 | /**
12 | * Created by Maciej on 2017-03-11.
13 | */
14 |
15 | public class Bindings {
16 |
17 | @BindingAdapter("android:text")
18 | public static void setIntegerText(TextView view, Integer value) {
19 | CharSequence old = view.getText();
20 | if (old != null && old.length() > 0 && value != null) {
21 | if (Integer.valueOf(old.toString()).intValue() != value.intValue()) {
22 | view.setText(String.valueOf(value));
23 | }
24 | } else if (value != null) {
25 | view.setText(String.valueOf(value));
26 | }
27 | }
28 |
29 | @InverseBindingAdapter(attribute = "android:text", event = "android:textAttrChanged")
30 | public static Integer getIntegerText(TextView view) {
31 | CharSequence text = view.getText();
32 | if (text != null && text.length() > 0) {
33 | return Integer.valueOf(text.toString());
34 | }
35 | return null;
36 | }
37 |
38 | @BindingAdapter(value = {"passwordChangeVisibility"})
39 | public static void passwordChangeVisibility(TextInputEditText inputEditText, boolean isVisible) {
40 | inputEditText.setTransformationMethod(isVisible ? HideReturnsTransformationMethod.getInstance() : PasswordTransformationMethod.getInstance());
41 | inputEditText.setSelection(inputEditText.getText().length());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/activities/BackActivity.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.activities;
2 |
3 | import androidx.databinding.DataBindingUtil;
4 | import androidx.databinding.ViewDataBinding;
5 | import android.os.Bundle;
6 | import android.view.MenuItem;
7 |
8 | import androidx.appcompat.app.AppCompatActivity;
9 | import androidx.appcompat.widget.Toolbar;
10 |
11 | /**
12 | * Created by Maciej on 2017-03-12.
13 | */
14 |
15 | public abstract class BackActivity extends AppCompatActivity {
16 |
17 |
18 | protected DATABINDING binding;
19 | protected VIEWMODEL viewModel;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | binding = DataBindingUtil.setContentView(this, getLayout());
25 | viewModel = createViewModel();
26 | setViewModel(binding, viewModel);
27 |
28 | Toolbar toolbar = getToolbar();
29 | setSupportActionBar(toolbar);
30 | if (getSupportActionBar() != null){
31 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
32 | getSupportActionBar().setDisplayShowHomeEnabled(true);
33 | }
34 | }
35 |
36 | @Override
37 | public boolean onOptionsItemSelected(MenuItem item) {
38 | if (item.getItemId() == android.R.id.home) {
39 | finish();
40 | }
41 |
42 | return super.onOptionsItemSelected(item);
43 | }
44 |
45 | protected abstract int getLayout();
46 |
47 | protected abstract VIEWMODEL createViewModel();
48 |
49 | protected abstract void setViewModel(DATABINDING binding, VIEWMODEL viewModel);
50 |
51 | protected abstract Toolbar getToolbar();
52 | }
53 |
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/activities/ChangePasswordExampleActivity.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.activities;
2 |
3 | import androidx.appcompat.widget.Toolbar;
4 |
5 | import pl.com.mmotak.sample.R;
6 | import pl.com.mmotak.sample.databinding.ActivityChangePasswordBinding;
7 | import pl.com.mmotak.sample.viewModels.ChangePasswordViewModel;
8 |
9 | /**
10 | * Created by Maciej on 2017-03-12.
11 | */
12 |
13 | public class ChangePasswordExampleActivity extends BackActivity {
14 | @Override
15 | protected int getLayout() {
16 | return R.layout.activity_change_password;
17 | }
18 |
19 | @Override
20 | protected ChangePasswordViewModel createViewModel() {
21 | return new ChangePasswordViewModel();
22 | }
23 |
24 | @Override
25 | protected void setViewModel(ActivityChangePasswordBinding binding, ChangePasswordViewModel viewModel) {
26 | binding.setViewModel(viewModel);
27 | }
28 |
29 | @Override
30 | protected Toolbar getToolbar() {
31 | return binding.toolbar;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/activities/LambdaRulesExampleActivity.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.activities;
2 |
3 |
4 | import androidx.appcompat.widget.Toolbar;
5 |
6 | import pl.com.mmotak.sample.R;
7 | import pl.com.mmotak.sample.databinding.ActivityLambdaExampleBinding;
8 | import pl.com.mmotak.sample.viewModels.LambdaRulesExampleViewModel;
9 |
10 | /**
11 | * Created by Maciej on 2017-03-13.
12 | */
13 |
14 | public class LambdaRulesExampleActivity extends BackActivity {
15 | @Override
16 | protected int getLayout() {
17 | return R.layout.activity_lambda_example;
18 | }
19 |
20 | @Override
21 | protected LambdaRulesExampleViewModel createViewModel() {
22 | return new LambdaRulesExampleViewModel();
23 | }
24 |
25 | @Override
26 | protected void setViewModel(ActivityLambdaExampleBinding binding, LambdaRulesExampleViewModel viewModel) {
27 | binding.setViewModel(viewModel);
28 | }
29 |
30 | @Override
31 | protected Toolbar getToolbar() {
32 | return binding.toolbar;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/activities/LoginExampleActivity.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.activities;
2 |
3 |
4 |
5 | import androidx.appcompat.widget.Toolbar;
6 |
7 | import pl.com.mmotak.sample.R;
8 | import pl.com.mmotak.sample.databinding.ActivityLoginExampleBinding;
9 | import pl.com.mmotak.sample.viewModels.LoginExampleViewModel;
10 |
11 | /**
12 | * Created by Maciej on 2017-03-13.
13 | */
14 |
15 | public class LoginExampleActivity extends BackActivity {
16 | @Override
17 | protected int getLayout() {
18 | return R.layout.activity_login_example;
19 | }
20 |
21 | @Override
22 | protected LoginExampleViewModel createViewModel() {
23 | return new LoginExampleViewModel();
24 | }
25 |
26 | @Override
27 | protected void setViewModel(ActivityLoginExampleBinding binding, LoginExampleViewModel viewModel) {
28 | binding.setViewModel(viewModel);
29 | }
30 |
31 | @Override
32 | protected Toolbar getToolbar() {
33 | return binding.toolbar;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/activities/MainListActivity.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.activities;
2 |
3 | import androidx.databinding.DataBindingUtil;
4 | import android.os.Bundle;
5 |
6 |
7 | import androidx.appcompat.app.AppCompatActivity;
8 | import androidx.appcompat.widget.Toolbar;
9 |
10 | import pl.com.mmotak.sample.R;
11 | import pl.com.mmotak.sample.databinding.ActivityMainListBinding;
12 | import pl.com.mmotak.sample.viewModels.MainListViewModel;
13 |
14 | public class MainListActivity extends AppCompatActivity {
15 |
16 | private ActivityMainListBinding binding;
17 | private MainListViewModel viewModel;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | binding = DataBindingUtil.setContentView(this, R.layout.activity_main_list);
23 | viewModel = new MainListViewModel(this);
24 | binding.setViewModel(viewModel);
25 |
26 | Toolbar toolbar = binding.toolbar;
27 | setSupportActionBar(toolbar);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/activities/MultiRulesExampleActivity.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.activities;
2 |
3 |
4 |
5 | import androidx.appcompat.widget.Toolbar;
6 |
7 | import pl.com.mmotak.sample.R;
8 | import pl.com.mmotak.sample.databinding.ActivityMultiRulesExampleBinding;
9 | import pl.com.mmotak.sample.viewModels.MultiRulesExampleViewModel;
10 |
11 | public class MultiRulesExampleActivity extends BackActivity {
12 |
13 | @Override
14 | protected int getLayout() {
15 | return R.layout.activity_multi_rules_example;
16 | }
17 |
18 | @Override
19 | protected MultiRulesExampleViewModel createViewModel() {
20 | return new MultiRulesExampleViewModel();
21 | }
22 |
23 | @Override
24 | protected void setViewModel(ActivityMultiRulesExampleBinding binding, MultiRulesExampleViewModel viewModel) {
25 | binding.setViewModel(viewModel);
26 | }
27 |
28 | @Override
29 | protected Toolbar getToolbar() {
30 | return binding.toolbar;
31 | }
32 | }
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/activities/SingleRuleExampleActivity.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.activities;
2 |
3 |
4 | import androidx.appcompat.widget.Toolbar;
5 |
6 | import pl.com.mmotak.sample.R;
7 | import pl.com.mmotak.sample.databinding.ActivitySingleRuleExampleBinding;
8 | import pl.com.mmotak.sample.viewModels.SingleRuleExampleViewModel;
9 |
10 | /**
11 | * Created by Maciej on 2017-03-11.
12 | */
13 |
14 | public class SingleRuleExampleActivity extends BackActivity {
15 |
16 | @Override
17 | protected int getLayout() {
18 | return R.layout.activity_single_rule_example;
19 | }
20 |
21 | @Override
22 | protected SingleRuleExampleViewModel createViewModel() {
23 | return new SingleRuleExampleViewModel();
24 | }
25 |
26 | @Override
27 | protected void setViewModel(ActivitySingleRuleExampleBinding binding, SingleRuleExampleViewModel viewModel) {
28 | binding.setViewModel(viewModel);
29 | }
30 |
31 | @Override
32 | protected Toolbar getToolbar() {
33 | return binding.toolbar;
34 | }
35 | }
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/adapters/ExampleRecycleViewAdapter.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.adapters;
2 |
3 |
4 | import androidx.annotation.LayoutRes;
5 |
6 | import pl.com.mmotak.sample.databinding.ItemExampleBinding;
7 | import pl.com.mmotak.sample.models.ItemExample;
8 | import pl.com.mmotak.sample.viewModels.ItemExampleViewModel;
9 |
10 | /**
11 | * Created by Maciej on 2017-03-11.
12 | */
13 |
14 | public class ExampleRecycleViewAdapter extends ListRecyclerViewAdapter {
15 |
16 | public ExampleRecycleViewAdapter(@LayoutRes int layoutId) {
17 | super(layoutId);
18 | }
19 |
20 | @Override
21 | public void onBindViewHolder(ViewHolder holder, int position) {
22 | holder.binding.setViewModel(new ItemExampleViewModel(get(position)));
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/adapters/ListRecyclerViewAdapter.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.adapters;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.ViewGroup;
5 |
6 | import androidx.annotation.LayoutRes;
7 | import androidx.databinding.DataBindingUtil;
8 | import androidx.databinding.ViewDataBinding;
9 | import androidx.recyclerview.widget.RecyclerView;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | /**
15 | * Created by mmotak on 03.01.2017.
16 | */
17 |
18 | public abstract class ListRecyclerViewAdapter
19 | extends RecyclerView.Adapter>{
20 |
21 | private List list = new ArrayList();
22 | private int layoutId;
23 |
24 | public ListRecyclerViewAdapter(@LayoutRes int layoutId) {
25 | this.layoutId = layoutId;
26 | }
27 |
28 | @Override
29 | public ListRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
30 | return new ListRecyclerViewAdapter.ViewHolder(DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), layoutId, parent, false));
31 | }
32 |
33 | @Override
34 | public int getItemCount() {
35 | return list.size();
36 | }
37 |
38 | public void setList(List list) {
39 | this.list.clear();
40 | this.list.addAll(list);
41 | notifyDataSetChanged();
42 | }
43 |
44 | public void addItem(ITEM item) {
45 | if (item != null) {
46 | list.add(item);
47 | notifyDataSetChanged();
48 | }
49 | }
50 |
51 | protected ITEM get(int position) {
52 | return list.get(position);
53 | }
54 |
55 | static class ViewHolder extends RecyclerView.ViewHolder {
56 | final BINDING binding;
57 |
58 | ViewHolder(BINDING binding) {
59 | super(binding.getRoot());
60 | this.binding = binding;
61 | }
62 | }
63 | }
64 |
65 |
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/models/ItemExample.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.models;
2 |
3 | import android.content.Intent;
4 |
5 | /**
6 | * Created by Maciej on 2017-03-11.
7 | */
8 |
9 | public class ItemExample {
10 | public final String message;
11 | public final Intent intent;
12 | public final String title;
13 |
14 | public ItemExample(String title, String message, Intent intent) {
15 | this.title = title;
16 | this.message = message;
17 | this.intent = intent;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/viewModels/ChangePasswordViewModel.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.viewModels;
2 |
3 | import android.view.View;
4 | import android.widget.Toast;
5 |
6 | import androidx.databinding.ObservableBoolean;
7 |
8 | import pl.com.mmotak.validator.FormValidatedObservableBoolean;
9 | import pl.com.mmotak.validator.Rule;
10 | import pl.com.mmotak.validator.RuleCommand;
11 | import pl.com.mmotak.validator.ValidatedObservableField;
12 | import pl.com.mmotak.validator.rules.MaximumLengthRule;
13 | import pl.com.mmotak.validator.rules.MinimumLengthRule;
14 | import pl.com.mmotak.validator.rules.RegexRule;
15 |
16 | /**
17 | * Created by Maciej on 2017-03-12.
18 | */
19 |
20 | public class ChangePasswordViewModel {
21 |
22 | private RuleCommand.Builder passwordRule = new RuleCommand.Builder()
23 | .withRule(new RegexRule("[\\S]+", "Whitespace characters not allowed")) // THE ORDER IS IMPORTANT!
24 | .withRule(new RegexRule(".*[A-Z]+.*", "Must contain capital letters"))
25 | .withRule(new RegexRule(".*[0-9]+.*", "Must contain digits"))
26 | .withRule(new RegexRule(".*[a-z]+.*", "Must contain small letters"))
27 | .withRule(new MinimumLengthRule(8, "Eight or more characters"))
28 | .withRule(new MaximumLengthRule(16, "No more then sixteen characters"));
29 | //.build();
30 |
31 | public final ObservableBoolean passwordVisible = new ObservableBoolean(false);
32 |
33 | public final ValidatedObservableField oldPassword = new ValidatedObservableField<>(
34 | "ThiIsMyOldPass09",
35 | passwordRule.build(),
36 | true);
37 |
38 | public final ValidatedObservableField newPassword = new ValidatedObservableField<>("",
39 | passwordRule
40 | .withRule(new Rule() {
41 | @Override
42 | public boolean isValid(String s) {
43 | return s != null && !s.equals(oldPassword.getValue());
44 | }
45 |
46 | @Override
47 | public String getErrorMessage() {
48 | return "Cannot be the same as old password";
49 | }
50 | })
51 | .build());
52 |
53 | public final ValidatedObservableField newPasswordRepeated = new ValidatedObservableField<>("",
54 | passwordRule
55 | .withRule(new Rule() {
56 | @Override
57 | public boolean isValid(String s) {
58 | return s != null && s.equals(newPassword.getValue());
59 | }
60 |
61 | @Override
62 | public String getErrorMessage() {
63 | return "Have to be the same as new password";
64 | }
65 | })
66 | .build());
67 |
68 | public final FormValidatedObservableBoolean validForm = new FormValidatedObservableBoolean(oldPassword, newPassword, newPasswordRepeated);
69 |
70 | public void onViewClick(View view) {
71 |
72 | oldPassword.setValue(newPassword.getValue());
73 | newPassword.setValue("");
74 | newPasswordRepeated.setValue("");
75 |
76 | newPassword.hideErrorMessage();
77 | newPasswordRepeated.hideErrorMessage();
78 |
79 | Toast.makeText(view.getContext(), "Password changed!", Toast.LENGTH_LONG).show();
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/viewModels/ItemExampleViewModel.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.viewModels;
2 |
3 | import android.content.Intent;
4 | import android.view.View;
5 |
6 | import androidx.databinding.ObservableField;
7 |
8 | import pl.com.mmotak.sample.models.ItemExample;
9 |
10 | /**
11 | * Created by Maciej on 2017-03-11.
12 | */
13 |
14 | public class ItemExampleViewModel {
15 |
16 | public final ObservableField message = new ObservableField<>("some message");
17 | public final ObservableField title = new ObservableField<>("title");
18 | private final Intent intent;
19 |
20 | public ItemExampleViewModel(ItemExample itemExample) {
21 | message.set(itemExample.message);
22 | title.set(itemExample.title);
23 | intent = itemExample.intent;
24 | }
25 |
26 | public void onClick(View view) {
27 | if (intent != null) {
28 | view.getContext().startActivity(intent);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/viewModels/LambdaRulesExampleViewModel.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.viewModels;
2 |
3 | import androidx.databinding.ObservableBoolean;
4 | import android.view.View;
5 | import android.widget.Toast;
6 |
7 | import pl.com.mmotak.validator.RuleCommand;
8 | import pl.com.mmotak.validator.ValidatedObservableField;
9 | import pl.com.mmotak.validator.rules.ValidatorRule;
10 |
11 | /**
12 | * Created by Maciej on 2017-03-13.
13 | */
14 |
15 | public class LambdaRulesExampleViewModel {
16 |
17 | public final ObservableBoolean passwordVisible = new ObservableBoolean(false);
18 |
19 | public final ValidatedObservableField userName = new ValidatedObservableField<>("",
20 | new RuleCommand.Builder()
21 | .withRule(s -> s != null && s.matches("[\\S]+"), "Whitespace characters not allowed") // THE ORDER IS IMPORTANT!
22 | .withRule(s -> s != null && s.length() >= 3, "Three or more characters")
23 | .withRule(s -> s != null && s.length() <= 12, "No more then twelve characters")
24 | .build());
25 |
26 | public final ValidatedObservableField password = new ValidatedObservableField<>("",
27 | new RuleCommand.Builder()
28 | .withRule(new ValidatorRule<>(s -> s != null && s.matches("[\\S]+"), "Whitespace characters not allowed")) // THE ORDER IS IMPORTANT!
29 | .withRule(new ValidatorRule<>(s -> s != null && s.matches(".*[A-Z]+.*"), "Must contain capital letters"))
30 | .withRule(new ValidatorRule<>(s -> s != null && s.matches(".*[0-9]+.*"), "Must contain digits"))
31 | .withRule(new ValidatorRule<>(s -> s != null && s.matches(".*[a-z]+.*"), "Must contain small letters"))
32 | .withRule(s -> s != null && s.length() >= 3, "Three or more characters")
33 | .withRule(s -> s != null && s.length() <= 12, "No more then twelve characters")
34 | .build());
35 |
36 | public void onViewClick(View view) {
37 | if (userName.isValid() && password.isValid()) {
38 | Toast.makeText(view.getContext(), "ALL OK !", Toast.LENGTH_LONG).show();
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/viewModels/LoginExampleViewModel.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.viewModels;
2 |
3 | import android.view.View;
4 | import android.widget.Toast;
5 |
6 | import androidx.databinding.ObservableBoolean;
7 |
8 | import pl.com.mmotak.validator.Rule;
9 | import pl.com.mmotak.validator.RuleCommand;
10 | import pl.com.mmotak.validator.ValidatedObservableField;
11 | import pl.com.mmotak.validator.rules.MaximumLengthRule;
12 | import pl.com.mmotak.validator.rules.MinimumLengthRule;
13 | import pl.com.mmotak.validator.rules.RegexRule;
14 |
15 | /**
16 | * Created by Maciej on 2017-03-13.
17 | */
18 |
19 | public class LoginExampleViewModel {
20 |
21 | private static final String EMAIL_PATTERN =
22 | "^[_A-Za-z0-9-+]+(\\.[_A-Za-z0-9-]+)*@"
23 | + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
24 |
25 | private static final String LOGIN_PATTERN = "^[A-Za-z_][A-Za-z0-9_.]{2,29}$";
26 |
27 | private Rule orRule = new Rule() {
28 | @Override
29 | public boolean isValid(String s) {
30 | return s != null && (s.matches(EMAIL_PATTERN) || s.matches(LOGIN_PATTERN));
31 | }
32 |
33 | @Override
34 | public String getErrorMessage() {
35 | return "Please enter email or login";
36 | }
37 | };
38 |
39 | public final ObservableBoolean passwordVisible = new ObservableBoolean(false);
40 |
41 | public final ValidatedObservableField userName = new ValidatedObservableField<>("",
42 | new RuleCommand.Builder()
43 | .withRule(new RegexRule("[\\S]+", "Whitespace characters not allowed")) // THE ORDER IS IMPORTANT!
44 | .withRule(new MinimumLengthRule(3, "Three or more characters"))
45 | .withRule(new MaximumLengthRule(30, "No more then 30 characters"))
46 | .withRule(orRule)
47 | .build());
48 |
49 | public final ValidatedObservableField password = new ValidatedObservableField<>("",
50 | new RuleCommand.Builder()
51 | .withRule(new RegexRule("[\\S]+", "Whitespace characters not allowed")) // THE ORDER IS IMPORTANT!
52 | .withRule(new RegexRule(".*[A-Z]+.*", "Must contain capital letters"))
53 | .withRule(new RegexRule(".*[0-9]+.*", "Must contain digits"))
54 | .withRule(new RegexRule(".*[a-z]+.*", "Must contain small letters"))
55 | .withRule(new MinimumLengthRule(8, "Eight or more characters"))
56 | .withRule(new MaximumLengthRule(16, "No more then sixteen characters"))
57 | .build());
58 |
59 | public void onViewClick(View view) {
60 | if (userName.isValid() && password.isValid()) {
61 | Toast.makeText(view.getContext(), "ALL OK !", Toast.LENGTH_LONG).show();
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/viewModels/MainListViewModel.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.viewModels;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 |
6 | import androidx.recyclerview.widget.RecyclerView;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | import pl.com.mmotak.sample.R;
12 | import pl.com.mmotak.sample.activities.ChangePasswordExampleActivity;
13 | import pl.com.mmotak.sample.activities.LambdaRulesExampleActivity;
14 | import pl.com.mmotak.sample.activities.LoginExampleActivity;
15 | import pl.com.mmotak.sample.activities.MultiRulesExampleActivity;
16 | import pl.com.mmotak.sample.activities.SingleRuleExampleActivity;
17 | import pl.com.mmotak.sample.adapters.ExampleRecycleViewAdapter;
18 | import pl.com.mmotak.sample.models.ItemExample;
19 |
20 | /**
21 | * Created by Maciej on 2017-03-11.
22 | */
23 |
24 | public class MainListViewModel {
25 |
26 | private final Context context;
27 | private final ExampleRecycleViewAdapter adapter = new ExampleRecycleViewAdapter(R.layout.item_example);
28 |
29 | public MainListViewModel(Context context) {
30 | this.context = context;
31 | adapter.setList(getList());
32 | }
33 |
34 | public RecyclerView.Adapter getAdapter() {
35 | return adapter;
36 | }
37 |
38 | private List getList() {
39 | List list = new ArrayList<>();
40 |
41 | list.add(new ItemExample("Multi Rules",
42 | "[MultiRulesExampleActivity] Show multi rules example",
43 | new Intent(context, MultiRulesExampleActivity.class)));
44 |
45 | list.add(new ItemExample("Single Rules",
46 | "[SingleRuleExampleActivity] Show single rules example",
47 | new Intent(context, SingleRuleExampleActivity.class)));
48 |
49 | list.add(new ItemExample("Other fields validate",
50 | "[ChangePasswordExampleActivity] Show example to validate other fields",
51 | new Intent(context, ChangePasswordExampleActivity.class)));
52 |
53 | list.add(new ItemExample("OR rules validate",
54 | "[LoginExampleActivity] Show example with OR rules",
55 | new Intent(context, LoginExampleActivity.class)));
56 |
57 | list.add(new ItemExample("Show how use lambda",
58 | "[LambdaRulesExampleActivity] Show creating rules with lambda",
59 | new Intent(context, LambdaRulesExampleActivity.class)));
60 |
61 | return list;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/viewModels/MultiRulesExampleViewModel.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.viewModels;
2 |
3 | import androidx.databinding.ObservableBoolean;
4 | import android.view.View;
5 | import android.widget.Toast;
6 |
7 | import pl.com.mmotak.validator.RuleCommand;
8 | import pl.com.mmotak.validator.ValidatedObservableField;
9 | import pl.com.mmotak.validator.rules.MaximumLengthRule;
10 | import pl.com.mmotak.validator.rules.MinimumLengthRule;
11 | import pl.com.mmotak.validator.rules.RegexRule;
12 |
13 | public class MultiRulesExampleViewModel {
14 |
15 | public final ObservableBoolean passwordVisible = new ObservableBoolean(false);
16 |
17 | public final ValidatedObservableField userName = new ValidatedObservableField<>("",
18 | new RuleCommand.Builder()
19 | .withRule(new RegexRule("[a-z]+", "Only small letters")) // THE ORDER IS IMPORTANT!
20 | .withRule(new MinimumLengthRule(3, "Three or more characters"))
21 | .withRule(new MaximumLengthRule(12, "No more then twelve characters"))
22 | .build());
23 |
24 | public final ValidatedObservableField password = new ValidatedObservableField<>("",
25 | new RuleCommand.Builder()
26 | .withRule(new RegexRule("[\\S]+", "Whitespace characters not allowed")) // THE ORDER IS IMPORTANT!
27 | .withRule(new RegexRule(".*[A-Z]+.*", "Must contain capital letters"))
28 | .withRule(new RegexRule(".*[0-9]+.*", "Must contain digits"))
29 | .withRule(new RegexRule(".*[a-z]+.*", "Must contain small letters"))
30 | .withRule(new MinimumLengthRule(8, "Eight or more characters"))
31 | .withRule(new MaximumLengthRule(16, "No more then sixteen characters"))
32 | .build());
33 |
34 | public void onViewClick(View view) {
35 | if (userName.isValid() && password.isValid()) {
36 | Toast.makeText(view.getContext(), "ALL OK !", Toast.LENGTH_LONG).show();
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/sampleapp/src/main/java/pl/com/mmotak/sample/viewModels/SingleRuleExampleViewModel.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample.viewModels;
2 |
3 | import pl.com.mmotak.validator.Rule;
4 | import pl.com.mmotak.validator.ValidatedObservableField;
5 | import pl.com.mmotak.validator.rules.MinimumLengthRule;
6 |
7 | /**
8 | * Created by Maciej on 2017-03-11.
9 | */
10 |
11 | public class SingleRuleExampleViewModel {
12 |
13 | public ValidatedObservableField age = new ValidatedObservableField<>(null,
14 | new Rule() {
15 | @Override
16 | public boolean isValid(Integer integer) {
17 | return integer != null && integer >= 18;
18 | }
19 |
20 | @Override
21 | public String getErrorMessage() {
22 | return "You have to be adult";
23 | }
24 | });
25 |
26 | public ValidatedObservableField name = new ValidatedObservableField<>(null, new MinimumLengthRule(1, "Name cannot be empty"));
27 | }
28 |
--------------------------------------------------------------------------------
/sampleapp/src/main/res/layout/activity_change_password.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
11 |
12 |
13 |
18 |
19 |
23 |
24 |
30 |
31 |
32 |
33 |
44 |
45 |
50 |
51 |
58 |
59 |
60 |
61 |
66 |
67 |
74 |
75 |
76 |
77 |
78 |
83 |
84 |
91 |
92 |
93 |
94 |
95 |
100 |
101 |
110 |
111 |
112 |
113 |
114 |
--------------------------------------------------------------------------------
/sampleapp/src/main/res/layout/activity_lambda_example.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
11 |
12 |
13 |
18 |
19 |
23 |
24 |
30 |
31 |
32 |
33 |
45 |
46 |
50 |
51 |
56 |
57 |
58 |
59 |
60 |
65 |
66 |
73 |
74 |
75 |
76 |
81 |
82 |
83 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/sampleapp/src/main/res/layout/activity_login_example.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
11 |
12 |
13 |
17 |
18 |
22 |
23 |
29 |
30 |
31 |
32 |
43 |
44 |
48 |
49 |
54 |
55 |
56 |
57 |
58 |
63 |
64 |
71 |
72 |
73 |
74 |
79 |
80 |
81 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/sampleapp/src/main/res/layout/activity_main_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
12 |
13 |
14 |
18 |
19 |
23 |
24 |
28 |
29 |
35 |
36 |
37 |
38 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/sampleapp/src/main/res/layout/activity_multi_rules_example.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
11 |
12 |
13 |
18 |
19 |
23 |
24 |
30 |
31 |
32 |
33 |
44 |
45 |
49 |
50 |
55 |
56 |
57 |
58 |
59 |
64 |
65 |
72 |
73 |
74 |
75 |
80 |
81 |
82 |
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/sampleapp/src/main/res/layout/activity_single_rule_example.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
15 |
20 |
21 |
25 |
26 |
32 |
33 |
34 |
35 |
46 |
47 |
51 |
52 |
57 |
58 |
59 |
60 |
64 |
65 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/sampleapp/src/main/res/layout/item_example.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
11 |
12 |
13 |
23 |
24 |
28 |
29 |
36 |
37 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/sampleapp/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmotak/DroidMVVMValidator/b51051bf29417aa798f632ed6a70f7d135476db7/sampleapp/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sampleapp/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmotak/DroidMVVMValidator/b51051bf29417aa798f632ed6a70f7d135476db7/sampleapp/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sampleapp/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmotak/DroidMVVMValidator/b51051bf29417aa798f632ed6a70f7d135476db7/sampleapp/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sampleapp/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmotak/DroidMVVMValidator/b51051bf29417aa798f632ed6a70f7d135476db7/sampleapp/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sampleapp/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmotak/DroidMVVMValidator/b51051bf29417aa798f632ed6a70f7d135476db7/sampleapp/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sampleapp/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmotak/DroidMVVMValidator/b51051bf29417aa798f632ed6a70f7d135476db7/sampleapp/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sampleapp/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmotak/DroidMVVMValidator/b51051bf29417aa798f632ed6a70f7d135476db7/sampleapp/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sampleapp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmotak/DroidMVVMValidator/b51051bf29417aa798f632ed6a70f7d135476db7/sampleapp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sampleapp/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmotak/DroidMVVMValidator/b51051bf29417aa798f632ed6a70f7d135476db7/sampleapp/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sampleapp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmotak/DroidMVVMValidator/b51051bf29417aa798f632ed6a70f7d135476db7/sampleapp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sampleapp/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/sampleapp/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/sampleapp/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/sampleapp/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 20dp
6 | 4dp
7 | 20sp
8 |
9 |
--------------------------------------------------------------------------------
/sampleapp/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Validator
3 | Validator Examples
4 | User password
5 | Show password
6 | User login or email
7 | User name
8 | Your name
9 | Your age
10 |
11 |
--------------------------------------------------------------------------------
/sampleapp/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sampleapp/src/test/java/pl/com/mmotak/sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.sample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sampleapp', ':validator'
2 |
--------------------------------------------------------------------------------
/validator/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/validator/android-release-aar.gradle:
--------------------------------------------------------------------------------
1 | // ./gradlew clean build generateRelease
2 | apply plugin: 'maven'
3 |
4 | def groupId = project.PUBLISH_GROUP_ID
5 | def artifactId = project.PUBLISH_ARTIFACT_ID
6 | def version = project.PUBLISH_VERSION
7 |
8 | def localReleaseDest = "${buildDir}/release/${version}"
9 |
10 | task androidJavadocs(type: Javadoc) {
11 | failOnError = false
12 | source = android.sourceSets.main.java.srcDirs
13 | ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
14 | classpath += files(ext.androidJar)
15 | }
16 |
17 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
18 | classifier = 'javadoc'
19 | from androidJavadocs.destinationDir
20 | }
21 |
22 | task androidSourcesJar(type: Jar) {
23 | classifier = 'sources'
24 | from android.sourceSets.main.java.srcDirs
25 | }
26 |
27 | uploadArchives {
28 | repositories.mavenDeployer {
29 | pom.groupId = groupId
30 | pom.artifactId = artifactId
31 | pom.version = version
32 | // Add other pom properties here if you want (developer details / licenses)
33 | repository(url: "file://${localReleaseDest}")
34 | }
35 | }
36 |
37 | task zipRelease(type: Zip) {
38 | from localReleaseDest
39 | destinationDir buildDir
40 | archiveName "release-${version}.zip"
41 | }
42 |
43 | task generateRelease {
44 | doLast {
45 | println "Release ${version} can be found at ${localReleaseDest}/"
46 | println "Release ${version} zipped can be found ${buildDir}/release-${version}.zip"
47 | }
48 | }
49 |
50 | generateRelease.dependsOn(uploadArchives)
51 | generateRelease.dependsOn(zipRelease)
52 |
53 |
54 | artifacts {
55 | archives androidSourcesJar
56 | archives androidJavadocsJar
57 | }
--------------------------------------------------------------------------------
/validator/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'jacoco-android'
3 |
4 | ext {
5 | PUBLISH_GROUP_ID = 'pl.com.mmotak.validator'
6 | PUBLISH_ARTIFACT_ID = 'droid-mvvm-validator'
7 | PUBLISH_VERSION = '2.0.0'
8 | }
9 |
10 | android {
11 | compileSdkVersion 28
12 | buildToolsVersion "28.0.3"
13 |
14 | defaultConfig {
15 | minSdkVersion 14
16 | targetSdkVersion 28
17 | versionCode 3
18 | versionName "2.0.0"
19 |
20 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
21 |
22 | }
23 | dataBinding {
24 | enabled = true
25 | }
26 | buildTypes {
27 | debug {
28 | testCoverageEnabled = true
29 | }
30 | release {
31 | minifyEnabled false
32 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33 | }
34 | }
35 | }
36 |
37 | dependencies {
38 | implementation fileTree(dir: 'libs', include: ['*.jar'])
39 | testImplementation 'junit:junit:4.12'
40 | }
41 |
42 | apply from: 'android-release-aar.gradle'
43 | //apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle'
44 |
45 |
--------------------------------------------------------------------------------
/validator/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\_android\Android\android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 | -dontobfuscate
27 | # See https://speakerdeck.com/chalup/proguard
28 | -optimizations !code/allocation/variable
29 |
30 | -keep public class * {
31 | public protected *;
32 | }
33 |
--------------------------------------------------------------------------------
/validator/src/androidTest/java/pl/com/mmotak/validator/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.validator;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("pl.com.mmotak.validator.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/validator/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/validator/src/main/java/pl/com/mmotak/validator/FormValidatedObservableBoolean.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.validator;
2 |
3 |
4 | import androidx.databinding.Observable;
5 | import androidx.databinding.ObservableBoolean;
6 |
7 | /**
8 | * Created by Maciej on 2017-03-12.
9 | */
10 |
11 | public class FormValidatedObservableBoolean extends ObservableBoolean {
12 |
13 | private final ValidatedObservableField>[] fields;
14 |
15 | public FormValidatedObservableBoolean(final ValidatedObservableField>... fields) {
16 | if (fields == null) {
17 | this.fields = new ValidatedObservableField[]{};
18 | } else {
19 | this.fields = fields;
20 | }
21 | init();
22 | }
23 |
24 | private void init() {
25 | for (final ValidatedObservableField field : this.fields) {
26 | field.addOnPropertyChangedCallback(new OnPropertyChangedCallback() {
27 | @Override
28 | public void onPropertyChanged(Observable observable, int i) {
29 | set(areAllFieldsValid());
30 | }
31 | });
32 | }
33 |
34 | set(areAllFieldsValid());
35 | }
36 |
37 | private boolean areAllFieldsValid() {
38 | boolean isValid = fields.length > 0;
39 | for (ValidatedObservableField field : fields) {
40 | isValid &= field.isValid();
41 | if (!isValid) {
42 | break;
43 | }
44 | }
45 | return isValid;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/validator/src/main/java/pl/com/mmotak/validator/Rule.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.validator;
2 |
3 |
4 | public interface Rule {
5 |
6 | /***
7 | * check if given value t is valid
8 | * @param t - the value to valid
9 | * @return - true if valid
10 | */
11 | boolean isValid(T t);
12 |
13 | /***
14 | * Return the error message if rule is not valid
15 | * @return - null (if valid) or error message (if not valid)
16 | */
17 | String getErrorMessage();
18 | }
19 |
--------------------------------------------------------------------------------
/validator/src/main/java/pl/com/mmotak/validator/RuleCommand.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.validator;
2 |
3 |
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import pl.com.mmotak.validator.rules.ValidatorRule;
8 |
9 | public class RuleCommand implements Rule {
10 |
11 | private List> rules = new ArrayList<>();
12 | private String error;
13 |
14 | private RuleCommand(List> rules) {
15 | this.rules.addAll(rules);
16 | }
17 |
18 | @Override
19 | public boolean isValid(T t) {
20 | for (Rule rule: rules) {
21 | if (!rule.isValid(t)) {
22 | error = rule.getErrorMessage();
23 | return false;
24 | }
25 | }
26 | return true;
27 | }
28 |
29 | @Override
30 | public String getErrorMessage() {
31 | return error;
32 | }
33 |
34 | public static class Builder {
35 | private List> rules = new ArrayList<>();
36 |
37 | public RuleCommand build() {
38 | return new RuleCommand(rules);
39 | }
40 |
41 | public Builder withRule(Rule rule) {
42 | rules.add(rule);
43 | return this;
44 | }
45 |
46 | public Builder withRule(Valid validator, final String error) {
47 | rules.add(new ValidatorRule(validator, error));
48 | return this;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/validator/src/main/java/pl/com/mmotak/validator/Valid.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.validator;
2 |
3 | /**
4 | * Created by Maciej on 2017-03-13.
5 | */
6 |
7 | public interface Valid {
8 | /***
9 | * check if given value t is valid
10 | * @param t - the value to valid
11 | * @return - true if valid
12 | */
13 | boolean isValid(T t);
14 | }
15 |
--------------------------------------------------------------------------------
/validator/src/main/java/pl/com/mmotak/validator/ValidatedObservableField.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.validator;
2 |
3 |
4 | import androidx.databinding.BaseObservable;
5 |
6 | public class ValidatedObservableField extends BaseObservable {
7 | private Rule rule;
8 | private T value;
9 | private boolean isValid;
10 | private String errorMessage;
11 |
12 | /***
13 | * Create new ValidatedObservableField, can be validate in constructor
14 | * @param value - starting value
15 | * @param rule - rule to validate the value
16 | * @param validate - if set true the constructor will {@link #validate() validate} the value immediately, by given rule.
17 | */
18 | public ValidatedObservableField(T value, Rule rule, boolean validate) {
19 | this.value = value;
20 | this.rule = rule;
21 | if (validate) {
22 | validate();
23 | }
24 | }
25 |
26 | /***
27 | * Create new ValidatedObservableField, will not be validate in constructor
28 | * @param value - starting value
29 | * @param rule - rule to validate the value
30 | */
31 | public ValidatedObservableField(T value, Rule rule) {
32 | this(value, rule, false);
33 | }
34 |
35 | /***
36 | * Create new ValidatedObservableField, will not be validate in constructor
37 | * use {@link #setRule(Rule) setRule} to set the rule later
38 | * @param value - starting value
39 | */
40 | public ValidatedObservableField(T value) {
41 | this(value, null, false);
42 | }
43 |
44 | /***
45 | * Create new ValidatedObservableField, will not be validate in constructor
46 | * use {@link #setRule(Rule) setRule} to set the rule later
47 | * use {@link #setValue(Object) setValue} to set the value later
48 | */
49 | public ValidatedObservableField() {
50 | }
51 |
52 | /***
53 | * Set the new value, if new value is different from previous one, the will be changed and validated immediately.
54 | * @param value - the new value
55 | */
56 | public void setValue(T value) {
57 | if (value != null && !value.equals(this.value)) {
58 | this.value = value;
59 | if (!validate()) {
60 | notifyChange();
61 | }
62 | }
63 | }
64 |
65 | /***
66 | * Set new rule, the current one will be replaced
67 | * @param rule - the new rule
68 | */
69 | public void setRule(Rule rule) {
70 | this.rule = rule;
71 | }
72 |
73 | /***
74 | * Get the current value
75 | * @return - the current value
76 | */
77 | public T getValue() {
78 | return value;
79 | }
80 |
81 | /***
82 | * Tells if field is valid.
83 | * return the saved value
84 | * have to call {@link #validate() validate} before to get correct value
85 | * @return - the saved information about is this field valid
86 | */
87 | public boolean isValid() {
88 | return isValid;
89 | }
90 |
91 | /***
92 | * Return the error message.
93 | * call {@link #validate() validate} before to get correct value
94 | * @return - null if no message or error massage returned by {@link Rule#getErrorMessage()}.
95 | */
96 | public String getErrorMessage() {
97 | return errorMessage;
98 | }
99 |
100 | /***
101 | * Set the new error message.
102 | * If the new error message is not the same as current one it will be changed.
103 | * Also call {@link BaseObservable#notifyChange}
104 | * @param errorMessage - the new error message
105 | */
106 | public void setErrorMessage(String errorMessage) {
107 | if (errorMessage == null) {
108 | hideErrorMessage();
109 | } else if (!errorMessage.equals(this.errorMessage)) {
110 | this.errorMessage = errorMessage;
111 | notifyChange();
112 | }
113 | }
114 |
115 | /***
116 | * Validate the field it there is a rule {@link Rule} to valid it.
117 | * Set the error message from {@link Rule#getErrorMessage()}
118 | * This method is called by: {@link #setValue(Object)} and in constructor {@link #ValidatedObservableField(Object, Rule, boolean)}
119 | * Also call {@link BaseObservable#notifyChange}
120 | * @return - true if there is a rule {@link Rule} and {@link BaseObservable#notifyChange} was called
121 | */
122 | public boolean validate() {
123 | if (rule != null) {
124 | isValid = rule.isValid(getValue());
125 | errorMessage = isValid ? null : rule.getErrorMessage();
126 | notifyChange();
127 | return true;
128 | }
129 | return false;
130 | }
131 |
132 | /***
133 | * Hide the error message.
134 | * Also call {@link BaseObservable#notifyChange}
135 | * the field still can be not valid!
136 | */
137 | public void hideErrorMessage() {
138 | if (errorMessage != null) {
139 | errorMessage = null;
140 | notifyChange();
141 | }
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/validator/src/main/java/pl/com/mmotak/validator/rules/AbstractRule.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.validator.rules;
2 |
3 | import pl.com.mmotak.validator.Rule;
4 |
5 | public abstract class AbstractRule implements Rule {
6 |
7 | private final String error;
8 |
9 | protected AbstractRule(String error) {
10 | this.error = error;
11 | }
12 |
13 | @Override
14 | public String getErrorMessage() {
15 | return error;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/validator/src/main/java/pl/com/mmotak/validator/rules/MaximumLengthRule.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.validator.rules;
2 |
3 | public class MaximumLengthRule extends AbstractRule {
4 | private int max;
5 |
6 | public MaximumLengthRule(int max, String error) {
7 | super(error);
8 | this.max = max;
9 | }
10 |
11 | @Override
12 | public boolean isValid(String s) {
13 | return s != null && s.length() <= max;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/validator/src/main/java/pl/com/mmotak/validator/rules/MinimumLengthRule.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.validator.rules;
2 |
3 | public class MinimumLengthRule extends AbstractRule {
4 | private int min;
5 |
6 | public MinimumLengthRule(int min, String error) {
7 | super(error);
8 | this.min = min;
9 | }
10 |
11 | @Override
12 | public boolean isValid(String s) {
13 | return s != null && s.length() >= min;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/validator/src/main/java/pl/com/mmotak/validator/rules/RegexRule.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.validator.rules;
2 |
3 | public class RegexRule extends AbstractRule {
4 | private String regex;
5 |
6 | /***
7 | * Rule that validate if entered String is matches by given regex.
8 | * @param regex - the given regex @see regex
9 | * @param error - the error message if not matches
10 | */
11 | public RegexRule(String regex, String error) {
12 | super(error);
13 | this.regex = regex;
14 | }
15 |
16 | @Override
17 | public boolean isValid(String s) {
18 | return s != null && s.matches(regex);
19 | }
20 | }
--------------------------------------------------------------------------------
/validator/src/main/java/pl/com/mmotak/validator/rules/ValidatorRule.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.validator.rules;
2 |
3 | import pl.com.mmotak.validator.Valid;
4 |
5 | /**
6 | * Created by Maciej on 2017-03-13.
7 | */
8 |
9 | public class ValidatorRule extends AbstractRule {
10 |
11 | private final Valid validator;
12 |
13 | public ValidatorRule(Valid validator, String error) {
14 | super(error);
15 | this.validator = validator;
16 | }
17 |
18 | @Override
19 | public boolean isValid(T t) {
20 | return validator.isValid(t);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/validator/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/validator/src/test/java/pl/com/mmotak/validator/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.validator;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | public class ExampleUnitTest {
8 | @Test
9 | public void addition_isCorrect() throws Exception {
10 | assertEquals(4, 2 + 2);
11 | }
12 | }
--------------------------------------------------------------------------------
/validator/src/test/java/pl/com/mmotak/validator/FormValidatedObservableBooleanShould.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.validator;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertFalse;
6 | import static org.junit.Assert.assertTrue;
7 |
8 | /**
9 | * Created by Maciej on 2017-03-19.
10 | */
11 |
12 | public class FormValidatedObservableBooleanShould {
13 |
14 | private FormValidatedObservableBoolean form;
15 | private Rule ageRule = new Rule() {
16 | @Override
17 | public boolean isValid(Integer integer) {
18 | return integer > 17;
19 | }
20 |
21 | @Override
22 | public String getErrorMessage() {
23 | return "Not adult";
24 | }
25 | };
26 |
27 | @Test
28 | public void notBeValidIfCreatedWithNoParameters() {
29 | form = new FormValidatedObservableBoolean();
30 | assertFalse(form.get());
31 | }
32 |
33 | @Test
34 | public void notBeValidIfCreatedWithNullParameter() {
35 | form = new FormValidatedObservableBoolean(null);
36 | assertFalse(form.get());
37 | }
38 |
39 | @Test
40 | public void notBeValidIfCreatedWithOneInvalidParameter() {
41 | ValidatedObservableField age = new ValidatedObservableField(1, ageRule, true);
42 | form = new FormValidatedObservableBoolean(age);
43 | assertFalse(form.get());
44 | }
45 |
46 | @Test
47 | public void beValidIfCreatedWithOneValidParameter() {
48 | ValidatedObservableField age = new ValidatedObservableField(23, ageRule, true);
49 | form = new FormValidatedObservableBoolean(age);
50 | assertTrue(form.get());
51 | }
52 |
53 | @Test
54 | public void becomeValidIfCreatedWithOneInvalidParameterAndParameterBecomeValid() {
55 | ValidatedObservableField age = new ValidatedObservableField(1, ageRule, true);
56 | form = new FormValidatedObservableBoolean(age);
57 |
58 | age.setValue(new Integer(22));
59 | assertTrue(form.get());
60 | }
61 |
62 | @Test
63 | public void notBeValidIfCreatedWithOtLeastOneInvalidParameter() {
64 | ValidatedObservableField age1 = new ValidatedObservableField(1, ageRule, true);
65 | ValidatedObservableField age2 = new ValidatedObservableField(23, ageRule, true);
66 | ValidatedObservableField age3 = new ValidatedObservableField(45, ageRule, true);
67 | form = new FormValidatedObservableBoolean(age3, age1, age2);
68 | assertFalse(form.get());
69 | }
70 |
71 | @Test
72 | public void becomeValidWhenAllParametersBecomeValid() {
73 | ValidatedObservableField age1 = new ValidatedObservableField(1, ageRule, true);
74 | ValidatedObservableField age2 = new ValidatedObservableField(23, ageRule, true);
75 | ValidatedObservableField age3 = new ValidatedObservableField(45, ageRule, true);
76 | form = new FormValidatedObservableBoolean(age3, age1, age2);
77 |
78 | age1.setValue(24);
79 |
80 | assertTrue(form.get());
81 | }
82 |
83 | @Test
84 | public void notBecomeValidWhenAtLeastOneParameterIsInvalid() {
85 | ValidatedObservableField age1 = new ValidatedObservableField(1, ageRule, true);
86 | ValidatedObservableField age2 = new ValidatedObservableField(23, ageRule, true);
87 | ValidatedObservableField age3 = new ValidatedObservableField(45, ageRule, true);
88 | form = new FormValidatedObservableBoolean(age3, age1, age2);
89 |
90 | age1.setValue(24);
91 | age2.setValue(1);
92 |
93 | assertFalse(form.get());
94 | }
95 |
96 | @Test
97 | public void stillBeValidIfTheErrorMessageWasSetManually() {
98 | ValidatedObservableField age = new ValidatedObservableField(45, ageRule, true);
99 | form = new FormValidatedObservableBoolean(age);
100 |
101 | age.setErrorMessage("Something went wrong !");
102 |
103 | assertTrue(form.get());
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/validator/src/test/java/pl/com/mmotak/validator/RuleCommandShould.java:
--------------------------------------------------------------------------------
1 | package pl.com.mmotak.validator;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 |
6 | import static junit.framework.Assert.assertNotNull;
7 | import static org.junit.Assert.assertEquals;
8 | import static org.junit.Assert.assertFalse;
9 | import static org.junit.Assert.assertNull;
10 | import static org.junit.Assert.assertTrue;
11 |
12 | /**
13 | * Created by Maciej on 2017-03-19.
14 | */
15 |
16 | public class RuleCommandShould {
17 |
18 | private Rule