├── .circleci
└── config.yml
├── .github
├── ISSUE_TEMPLATE.md
└── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── LICENSE
├── README.md
├── art
├── ascii_validator.gif
├── custom_validator.gif
├── email_validator.gif
└── required_validator.gif
├── build.gradle
├── buildSrc
├── .gitignore
├── build.gradle.kts
└── src
│ └── main
│ └── java
│ └── dependencies
│ ├── Depends.kt
│ └── Versions.kt
├── example
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── co
│ │ └── kyash
│ │ └── vtl
│ │ └── MainActivityTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── co
│ │ │ └── kyash
│ │ │ └── vtl
│ │ │ └── example
│ │ │ ├── App.kt
│ │ │ ├── MainActivity.kt
│ │ │ ├── api
│ │ │ └── MaterialDesignColorsApi.kt
│ │ │ └── validators
│ │ │ └── MaterialDesignColorsValidator.kt
│ └── res
│ │ ├── drawable
│ │ ├── btn_accent.xml
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ ├── styles.xml
│ │ └── themes.xml
│ └── test
│ └── java
│ └── co
│ └── kyash
│ └── vtl
│ └── example
│ ├── testing
│ └── RxImmediateSchedulerRule.kt
│ └── validators
│ └── MaterialDesignColorsValidatorTest.kt
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── jitpack.yml
├── json
└── colors.json
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── co
│ │ │ └── kyash
│ │ │ └── vtl
│ │ │ ├── ValidatableTextInputLayout.kt
│ │ │ ├── ValidatableView.kt
│ │ │ ├── VtlValidationFailureException.kt
│ │ │ └── validators
│ │ │ ├── AlphabetOnlyValidator.kt
│ │ │ ├── AsciiOnlyValidator.kt
│ │ │ ├── EmailValidator.kt
│ │ │ ├── HiraganaOnlyValidator.kt
│ │ │ ├── KatakanaOnlyValidator.kt
│ │ │ ├── MinLengthValidator.kt
│ │ │ ├── NoSpecialCharacterValidator.kt
│ │ │ ├── NumberOnlyValidator.kt
│ │ │ ├── RequiredValidator.kt
│ │ │ └── VtlValidator.kt
│ └── res
│ │ └── values
│ │ ├── attrs.xml
│ │ └── strings.xml
│ └── test
│ ├── java
│ └── co
│ │ └── kyash
│ │ └── vtl
│ │ ├── testing
│ │ └── RxImmediateSchedulerRule.kt
│ │ └── validators
│ │ ├── AlphabetOnlyValidatorTest.kt
│ │ ├── AsciiOnlyValidatorTest.kt
│ │ ├── EmailValidatorTest.kt
│ │ ├── HiraganaOnlyValidatorTest.kt
│ │ ├── KatakanaOnlyValidatorTest.kt
│ │ ├── MinLengthValidatorTest.kt
│ │ ├── NoSpecialCharacterValidatorTest.kt
│ │ ├── NumberOnlyValidatorTest.kt
│ │ └── RequiredValidatorTest.kt
│ └── resources
│ └── robolectric.properties
├── settings.gradle
└── versions.gradle
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2.1
2 | jobs:
3 | build:
4 | docker:
5 | - image: circleci/android:api-30
6 |
7 | working_directory: ~/repo
8 |
9 | environment:
10 | JVM_OPTS: -Xmx3200m
11 | GRADLE_OPTS: '-Dorg.gradle.parallel=false -Dorg.gradle.daemon=false'
12 | resource_class: large
13 |
14 | steps:
15 | - checkout
16 | - restore_cache:
17 | key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
18 |
19 | - run:
20 | name: Download Dependencies
21 | command: ./gradlew androidDependencies
22 |
23 | - save_cache:
24 | paths:
25 | - ~/.gradle
26 | key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
27 |
28 | - run:
29 | name: Run Tests
30 | command: ./gradlew testDebug
31 |
32 | - store_artifacts:
33 | path: app/build/outputs
34 | destination: outputs
35 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | # Overview
2 | -
3 |
4 | # Links
5 | -
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | close #ISSUE_NUMBER
2 |
3 | # Overview
4 | -
5 |
6 | # Links
7 | -
8 |
9 | # Screenshots
10 |
11 | Before | After
12 | :--: | :--:
13 |
|
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .idea/*
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
10 | # not ignore
11 | !.idea/codeStyleSettings.xml
12 |
13 | fabric.properties
--------------------------------------------------------------------------------
/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 [yyyy] [name of copyright owner]
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 | # ValidatableTextInputLayout
2 |
3 | [](https://circleci.com/gh/Kyash/validatable-textinput-layout/tree/master)
4 | [](https://jitpack.io/#Kyash/validatable-textinput-layout)
5 |
6 | ValidatableTextInputLayout is the view which extended TextInputLayout to validate the input text easily.
7 |
8 | ## Download
9 |
10 | ### Project build.gradle
11 |
12 | ```groovy
13 | allprojects {
14 | repositories {
15 | ...
16 | maven { url "https://jitpack.io" }
17 | }
18 | }
19 | ```
20 |
21 | ### App build.gradle
22 |
23 | ```groovy
24 | dependencies {
25 | ...
26 | compile 'com.github.Kyash:validatable-textinput-layout:LATEST_VERSION'
27 | }
28 | ```
29 |
30 | `LATEST_VERSION` is [](https://jitpack.io/#Kyash/validatable-textinput-layout) which supports AndroidX.
31 | If you still use Support Library, please use version `0.3.0`.
32 |
33 | ## Basic usage
34 | You can use as same as `TextInputLayout` in layout xml.
35 |
36 | ### Layout
37 | `trigger` attribute defines the timing of the text field validation.
38 |
39 | ```xml
40 |
45 |
46 |
51 |
52 |
53 | ```
54 |
55 | ### Kotlin
56 | Register Validator class to `ValidatableTextInputLayout`
57 | For example, `RequiredValidator` shows error when the field is empty.
58 |
59 | ```kotlin
60 | private fun initValidator() {
61 | binding.firstName.register(RequiredValidator(getString(R.string.validation_error_required)))
62 | }
63 | ```
64 |
65 | That's it. It works as below.
66 |
67 | 
68 |
69 | ## Triggers
70 | There are 2 types of the validation trigger attributes.
71 |
72 | Attribute | Description
73 | :--: | :--
74 | text_changed | Validate immediately when the text is changed.
75 | focus_changed | Validate when the focus is changed
76 |
77 | ## Validators
78 | This library provides some common validators
79 |
80 | Validator | Description
81 | :--: | :--:
82 | RequiredValidator | 
83 | EmailValidator | 
84 | NumberOnlyValidator | Number only
85 | AsciiOnlyValidator | 
86 | AlphabetOnlyValidator | Alphabet character only
87 | HiraganaOnlyValidator | Jananese Hieragana character only
88 | KatakanaOnlyValidator | Japanese Katakana character only
89 |
90 |
91 |
92 | ## Custom validator
93 | You can create the custom validator by using `VtlValidator`.
94 | Since `VtlValidator` uses RxJava2, it can handle async logic like API as well!
95 |
96 | [MaterialDesignColorsValidator](https://github.com/Kyash/validatable-textinput-layout/blob/master/example/src/main/java/co/kyash/vtl/example/validators/MaterialDesignColorsValidator.kt) is example to get data via API and validate the input value.
97 |
98 | ```kotlin
99 | class MaterialDesignColorsValidator(
100 | private val api: MaterialDesignColorsApi,
101 | private val context: Context
102 | ) : VtlValidator {
103 |
104 | override fun validateAsCompletable(context: Context, text: String?): Completable {
105 | return api.all()
106 | .onErrorResumeNext { Single.error(VtlValidationFailureException(context.getString(R.string.validation_error_server))) }
107 | .flatMapCompletable { list ->
108 | if (text?.trim() != null) {
109 | list.filter { it == text.trim().toLowerCase() }
110 | .forEach { return@flatMapCompletable Completable.complete() }
111 | }
112 | return@flatMapCompletable Completable.error(VtlValidationFailureException(getErrorMessage()))
113 | }
114 | }
115 |
116 | override fun validate(text: String?): Boolean {
117 | throw UnsupportedOperationException("Sync method is not arrowed because this validation uses async API response.")
118 | }
119 |
120 | override fun getErrorMessage(): String {
121 | return context.getString(R.string.validation_error_colors)
122 | }
123 | }
124 | ```
125 |
126 | 
127 |
128 | ## Contributing
129 | We are always welcome your contribution!
130 | If you find a bug or want to add new feature, please raise issue.
131 |
132 | ## License
133 |
134 | ```
135 | Copyright 2018 Kyash
136 |
137 | Licensed under the Apache License, Version 2.0 (the "License");
138 | you may not use this file except in compliance with the License.
139 | You may obtain a copy of the License at
140 |
141 | http://www.apache.org/licenses/LICENSE-2.0
142 |
143 | Unless required by applicable law or agreed to in writing, software
144 | distributed under the License is distributed on an "AS IS" BASIS,
145 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
146 | See the License for the specific language governing permissions and
147 | limitations under the License.
148 | ```
149 |
--------------------------------------------------------------------------------
/art/ascii_validator.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kyash/validatable-textinput-layout/85bd0715df374ba1c0a7adf7505169fd4faa5556/art/ascii_validator.gif
--------------------------------------------------------------------------------
/art/custom_validator.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kyash/validatable-textinput-layout/85bd0715df374ba1c0a7adf7505169fd4faa5556/art/custom_validator.gif
--------------------------------------------------------------------------------
/art/email_validator.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kyash/validatable-textinput-layout/85bd0715df374ba1c0a7adf7505169fd4faa5556/art/email_validator.gif
--------------------------------------------------------------------------------
/art/required_validator.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kyash/validatable-textinput-layout/85bd0715df374ba1c0a7adf7505169fd4faa5556/art/required_validator.gif
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | import dependencies.Depends
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | mavenCentral()
7 | gradlePluginPortal()
8 | maven { url "https://jitpack.io" }
9 | }
10 | dependencies {
11 | classpath Depends.GradlePlugin.android
12 | classpath Depends.GradlePlugin.kotlin
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | google()
19 | mavenCentral()
20 | maven { url "https://jitpack.io" }
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/buildSrc/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/buildSrc/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `kotlin-dsl`
3 | }
4 | repositories {
5 | mavenCentral()
6 | }
7 |
--------------------------------------------------------------------------------
/buildSrc/src/main/java/dependencies/Depends.kt:
--------------------------------------------------------------------------------
1 | package dependencies
2 |
3 | @Suppress("unused")
4 | object Depends {
5 | object GradlePlugin {
6 | const val android = "com.android.tools.build:gradle:7.0.0"
7 | const val kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Kotlin.version}"
8 | }
9 |
10 | object Test {
11 | const val junit = "junit:junit:4.13.2"
12 | const val testRunner = "androidx.test:runner:1.4.0"
13 | const val mockitoKotlin = "com.nhaarman.mockitokotlin2:mockito-kotlin:2.0.0"
14 | const val robolectric = "org.robolectric:robolectric:4.6.1"
15 |
16 | object Espresso {
17 | const val core = "androidx.test.espresso:espresso-core:3.1.0-alpha4"
18 | const val intents = "androidx.test.espresso:espresso-intents:3.1.0-alpha4"
19 | }
20 | }
21 |
22 | object AndroidX {
23 | const val appCompat = "androidx.appcompat:appcompat:1.0.0"
24 | const val recyclerView = "androidx.recyclerview:recyclerview:1.0.0"
25 | const val cardView = "androidx.cardview:cardview:1.0.0"
26 | const val design = "com.google.android.material:material:1.1.0-alpha01"
27 | }
28 |
29 | object Kotlin {
30 | const val version = "1.5.21"
31 | }
32 |
33 | object Stetho {
34 | const val version = "1.5.0"
35 | const val core = "com.facebook.stetho:stetho:$version"
36 | const val okhttp = "com.facebook.stetho:stetho-okhttp3:$version"
37 | }
38 |
39 | object Crashlytics {
40 | const val core = "com.crashlytics.sdk.android:crashlytics:2.8.0@aar"
41 | }
42 |
43 | object Retrofit {
44 | private const val version = "2.9.0"
45 | const val core = "com.squareup.retrofit2:retrofit:$version"
46 | const val converterMoshi = "com.squareup.retrofit2:converter-moshi:$version"
47 | const val adapterRxJava3 = "com.squareup.retrofit2:adapter-rxjava3:$version"
48 | }
49 |
50 | object Kotshi {
51 | private const val version = "1.0.6"
52 | const val api = "se.ansman.kotshi:api:$version"
53 | const val compiler = "se.ansman.kotshi:compiler:$version"
54 | }
55 |
56 | object Rx {
57 | const val RxJava = "io.reactivex.rxjava3:rxjava:3.0.13"
58 | const val RxAndroid = "io.reactivex.rxjava3:rxandroid:3.0.0"
59 | const val RxKotlin = "io.reactivex.rxjava3:rxkotlin:3.0.1"
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/buildSrc/src/main/java/dependencies/Versions.kt:
--------------------------------------------------------------------------------
1 | package dependencies
2 |
3 | private object Versions {
4 | val androidCompileSdkVersion = 30
5 | val androidTargetSdkVersion = 30
6 | val androidMinSdkVersion = 19
7 | }
8 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/example/build.gradle:
--------------------------------------------------------------------------------
1 | import dependencies.Depends
2 | import dependencies.Versions
3 |
4 | apply plugin: 'com.android.application'
5 | apply plugin: 'kotlin-android'
6 | apply plugin: 'kotlin-kapt'
7 | apply from: "${rootDir.absolutePath}/versions.gradle"
8 |
9 | def versionMajor = 1
10 | def versionMinor = 0
11 | def versionPatch = 0
12 |
13 | android {
14 | compileSdkVersion Versions.androidCompileSdkVersion
15 | dataBinding.enabled = true
16 |
17 | defaultConfig {
18 | applicationId "co.kyash.vtl.sample"
19 | minSdkVersion Versions.androidMinSdkVersion
20 | targetSdkVersion Versions.androidTargetSdkVersion
21 | versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch
22 | versionName "$versionMajor.$versionMinor.$versionPatch"
23 | }
24 | buildTypes {
25 | debug {
26 | applicationIdSuffix '.debug'
27 | versionNameSuffix "-debug"
28 | }
29 | release {
30 | debuggable false
31 | zipAlignEnabled true
32 | minifyEnabled false
33 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34 | signingConfig signingConfigs.debug
35 | }
36 | }
37 | testOptions {
38 | unitTests.returnDefaultValues = true
39 | }
40 | lintOptions {
41 | lintConfig file('lint.xml')
42 | textReport true
43 | textOutput 'stdout'
44 | }
45 | }
46 |
47 | dependencies {
48 | implementation project(':library')
49 |
50 | //==================== Support Library ====================
51 | implementation Depends.AndroidX.appCompat
52 | implementation Depends.AndroidX.design
53 | implementation Depends.AndroidX.cardView
54 |
55 | //==================== Network ====================
56 | implementation Depends.Retrofit.core
57 | implementation Depends.Retrofit.converterMoshi
58 | implementation Depends.Retrofit.adapterRxJava3
59 |
60 | //==================== Structure ====================
61 | implementation Depends.Kotshi.api
62 | kapt Depends.Kotshi.compiler
63 |
64 | implementation Depends.Rx.RxJava
65 | implementation Depends.Rx.RxAndroid
66 | implementation Depends.Rx.RxKotlin
67 |
68 | //==================== Debug ====================
69 | implementation(Depends.Crashlytics.core) {
70 | transitive = true
71 | }
72 |
73 | //==================== Debug ====================
74 | implementation Depends.Stetho.core
75 | implementation Depends.Stetho.okhttp
76 |
77 | //==================== Test ====================
78 | testImplementation Depends.Test.junit
79 | testImplementation Depends.Test.mockitoKotlin
80 | testImplementation Depends.Test.robolectric
81 | androidTestImplementation Depends.Test.testRunner
82 | androidTestImplementation Depends.Test.Espresso.core
83 | androidTestImplementation Depends.Test.Espresso.intents
84 | }
85 |
--------------------------------------------------------------------------------
/example/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/example/src/androidTest/java/co/kyash/vtl/MainActivityTest.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl
2 |
3 | import android.content.Intent
4 | import android.support.test.espresso.intent.Intents
5 | import android.support.test.espresso.intent.matcher.IntentMatchers
6 | import android.support.test.espresso.intent.rule.IntentsTestRule
7 | import android.support.test.filters.LargeTest
8 | import co.kyash.vtl.example.MainActivity
9 | import org.junit.Rule
10 | import org.junit.Test
11 |
12 | @LargeTest
13 | class MainActivityTest {
14 |
15 | @get:Rule
16 | private val activityTestRule = IntentsTestRule(MainActivity::class.java, true, false)
17 |
18 | @Test
19 | fun launch() {
20 | // when
21 | activityTestRule.launchActivity(Intent())
22 |
23 | // then
24 | Intents.intended(IntentMatchers.hasComponent(MainActivity::class.java.name))
25 | }
26 |
27 | }
--------------------------------------------------------------------------------
/example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/example/src/main/java/co/kyash/vtl/example/App.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.example
2 |
3 | import android.app.Application
4 | import com.facebook.stetho.Stetho
5 |
6 | class App : Application() {
7 |
8 | override fun onCreate() {
9 | super.onCreate()
10 | setUpStetho()
11 | }
12 |
13 | private fun setUpStetho() {
14 | Stetho.initializeWithDefaults(this)
15 | }
16 | }
--------------------------------------------------------------------------------
/example/src/main/java/co/kyash/vtl/example/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.example
2 |
3 | import android.os.Bundle
4 | import android.util.Log
5 | import android.view.View
6 | import android.widget.Toast
7 | import androidx.appcompat.app.AppCompatActivity
8 | import androidx.databinding.DataBindingUtil
9 | import co.kyash.vtl.ValidatableView
10 | import co.kyash.vtl.example.api.MaterialDesignColorsApi
11 | import co.kyash.vtl.example.databinding.ActivityMainBinding
12 | import co.kyash.vtl.example.validators.MaterialDesignColorsValidator
13 | import co.kyash.vtl.validators.AsciiOnlyValidator
14 | import co.kyash.vtl.validators.EmailValidator
15 | import co.kyash.vtl.validators.NumberOnlyValidator
16 | import co.kyash.vtl.validators.RequiredValidator
17 | import com.crashlytics.android.Crashlytics
18 | import com.facebook.stetho.okhttp3.StethoInterceptor
19 | import com.squareup.moshi.Moshi
20 | import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
21 | import io.reactivex.rxjava3.core.Completable
22 | import io.reactivex.rxjava3.core.Flowable
23 | import io.reactivex.rxjava3.disposables.CompositeDisposable
24 | import io.reactivex.rxjava3.schedulers.Schedulers
25 | import okhttp3.OkHttpClient
26 | import retrofit2.Retrofit
27 | import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory
28 | import retrofit2.converter.moshi.MoshiConverterFactory
29 |
30 |
31 | class MainActivity : AppCompatActivity() {
32 |
33 | private lateinit var binding: ActivityMainBinding
34 |
35 | private val validatableViewsForTriggerTextChanged: ArrayList = ArrayList()
36 |
37 | private val validatableViewsForTriggerFocusChanged: ArrayList = ArrayList()
38 |
39 | private val validatableViewsForButtonEnable: ArrayList = ArrayList()
40 |
41 | private val compositeDisposable = CompositeDisposable()
42 |
43 | private val api = Retrofit.Builder()
44 | .baseUrl("https://raw.githubusercontent.com")
45 | .addConverterFactory(MoshiConverterFactory.create(Moshi.Builder().build()))
46 | .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
47 | .client(OkHttpClient.Builder().addNetworkInterceptor(StethoInterceptor()).build())
48 | .build()
49 | .create(MaterialDesignColorsApi::class.java)
50 |
51 | override fun onCreate(savedInstanceState: Bundle?) {
52 | super.onCreate(savedInstanceState)
53 |
54 | binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
55 |
56 | initValidators()
57 |
58 | binding.submit.setOnClickListener(this::onSubmitClick)
59 | binding.submit2.setOnClickListener(this::onSubmit2Click)
60 | binding.submit3.setOnClickListener(this::onSubmit3Click)
61 | }
62 |
63 | private fun initValidators() {
64 | // Example 1
65 | validatableViewsForTriggerTextChanged.addAll(arrayOf(
66 | binding.firstName.register(RequiredValidator(getString(R.string.validation_error_required))),
67 | binding.lastName.register(RequiredValidator(getString(R.string.validation_error_required))),
68 | binding.email.register(EmailValidator(getString(R.string.validation_error_email))),
69 | binding.numberOnly.register(NumberOnlyValidator(getString(R.string.validation_error_number_only))),
70 | binding.asciiOnly.register(AsciiOnlyValidator(getString(R.string.validation_error_ascii_only)))
71 | ))
72 |
73 | // Example 2
74 | validatableViewsForTriggerFocusChanged.addAll(arrayOf(
75 | binding.email2.register(EmailValidator(getString(R.string.validation_error_email)))
76 | ))
77 |
78 | // Example 3
79 | binding.colors.register(MaterialDesignColorsValidator(api, this))
80 |
81 | // Example 4
82 | validatableViewsForButtonEnable.addAll(arrayOf(
83 | binding.firstName2.register(RequiredValidator(getString(R.string.validation_error_required))),
84 | binding.lastName2.register(RequiredValidator(getString(R.string.validation_error_required)))
85 | ))
86 | val validations: List> = validatableViewsForButtonEnable.flatMap { it.validationFlowables }
87 | Flowable.zip(validations) { Any() }
88 | .subscribeOn(Schedulers.computation())
89 | .observeOn(AndroidSchedulers.mainThread())
90 | .doOnError({ binding.submit3.isEnabled = false })
91 | .retry() // non-terminated stream
92 | .subscribe({ binding.submit3.isEnabled = true }, { })
93 | }
94 |
95 |
96 | private fun onSubmitClick(@Suppress("UNUSED_PARAMETER") view: View) {
97 | val validations: List = validatableViewsForTriggerTextChanged.map { it.validateAsCompletable() }
98 | validate(validations)
99 | }
100 |
101 | private fun onSubmit2Click(@Suppress("UNUSED_PARAMETER") view: View) {
102 | val validations: List = validatableViewsForTriggerFocusChanged.map { it.validateAsCompletable() }
103 | validate(validations)
104 | }
105 |
106 | private fun onSubmit3Click(@Suppress("UNUSED_PARAMETER") view: View) {
107 | Toast.makeText(this, R.string.validation_success, Toast.LENGTH_SHORT).show()
108 | }
109 |
110 | private fun validate(validations: List) {
111 | compositeDisposable.clear()
112 |
113 | compositeDisposable.add(
114 | Completable.mergeDelayError(validations)
115 | .subscribeOn(Schedulers.computation())
116 | .observeOn(AndroidSchedulers.mainThread())
117 | .subscribe({
118 | Log.d("MainActivity", "Validation cleared.")
119 | Toast.makeText(this, R.string.validation_success, Toast.LENGTH_SHORT).show()
120 | }, { throwable ->
121 | Log.e("MainActivity", "Validation error occurred.", throwable)
122 | Toast.makeText(this, R.string.validation_error_occurred, Toast.LENGTH_SHORT).show()
123 | })
124 | )
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/example/src/main/java/co/kyash/vtl/example/api/MaterialDesignColorsApi.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.example.api
2 |
3 | import io.reactivex.rxjava3.core.Single
4 | import retrofit2.http.GET
5 |
6 | interface MaterialDesignColorsApi {
7 |
8 | @GET("/Kyash/validatable-textinput-layout/master/json/colors.json")
9 | fun all(): Single>
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/example/src/main/java/co/kyash/vtl/example/validators/MaterialDesignColorsValidator.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.example.validators
2 |
3 | import android.content.Context
4 | import co.kyash.vtl.VtlValidationFailureException
5 | import co.kyash.vtl.example.R
6 | import co.kyash.vtl.example.api.MaterialDesignColorsApi
7 | import co.kyash.vtl.validators.VtlValidator
8 | import io.reactivex.rxjava3.core.Completable
9 | import io.reactivex.rxjava3.core.Single
10 |
11 | class MaterialDesignColorsValidator(
12 | private val api: MaterialDesignColorsApi,
13 | private val context: Context
14 | ) : VtlValidator {
15 |
16 | override fun validateAsCompletable(context: Context, text: String?): Completable {
17 | return api.all()
18 | .onErrorResumeNext { Single.error(VtlValidationFailureException(context.getString(R.string.validation_error_server))) }
19 | .flatMapCompletable { list ->
20 | if (text?.trim() != null) {
21 | list.filter { it == text.trim().toLowerCase() }
22 | .forEach { return@flatMapCompletable Completable.complete() }
23 | }
24 | return@flatMapCompletable Completable.error(VtlValidationFailureException(getErrorMessage()))
25 | }
26 | }
27 |
28 | override fun validate(text: String?): Boolean {
29 | throw UnsupportedOperationException("sync method is not arrowed because this validation uses async API response.")
30 | }
31 |
32 | override fun getErrorMessage(): String {
33 | return context.getString(R.string.validation_error_colors)
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/example/src/main/res/drawable/btn_accent.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/example/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
12 |
13 |
22 |
23 |
26 |
27 |
32 |
33 |
36 |
37 |
41 |
42 |
52 |
53 |
54 |
58 |
59 |
63 |
64 |
65 |
66 |
67 |
71 |
72 |
76 |
77 |
78 |
79 |
80 |
85 |
86 |
90 |
91 |
92 |
93 |
94 |
98 |
99 |
103 |
104 |
105 |
106 |
107 |
111 |
112 |
116 |
117 |
118 |
119 |
126 |
127 |
128 |
129 |
130 |
131 |
135 |
136 |
140 |
141 |
151 |
152 |
153 |
157 |
158 |
162 |
163 |
164 |
165 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
182 |
183 |
187 |
188 |
192 |
193 |
203 |
204 |
208 |
209 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
224 |
225 |
229 |
230 |
234 |
235 |
245 |
246 |
247 |
251 |
252 |
256 |
257 |
258 |
259 |
260 |
264 |
265 |
269 |
270 |
271 |
272 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kyash/validatable-textinput-layout/85bd0715df374ba1c0a7adf7505169fd4faa5556/example/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kyash/validatable-textinput-layout/85bd0715df374ba1c0a7adf7505169fd4faa5556/example/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kyash/validatable-textinput-layout/85bd0715df374ba1c0a7adf7505169fd4faa5556/example/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kyash/validatable-textinput-layout/85bd0715df374ba1c0a7adf7505169fd4faa5556/example/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kyash/validatable-textinput-layout/85bd0715df374ba1c0a7adf7505169fd4faa5556/example/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kyash/validatable-textinput-layout/85bd0715df374ba1c0a7adf7505169fd4faa5556/example/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kyash/validatable-textinput-layout/85bd0715df374ba1c0a7adf7505169fd4faa5556/example/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kyash/validatable-textinput-layout/85bd0715df374ba1c0a7adf7505169fd4faa5556/example/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kyash/validatable-textinput-layout/85bd0715df374ba1c0a7adf7505169fd4faa5556/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kyash/validatable-textinput-layout/85bd0715df374ba1c0a7adf7505169fd4faa5556/example/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/example/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #1BA9E1
4 | #007AAF
5 | #6EB53B
6 | #D0011B
7 |
8 | #000000
9 | #EEEEEE
10 | #9E9E9E
11 | #FFFFFF
12 |
13 |
--------------------------------------------------------------------------------
/example/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 8dp
4 | 16dp
5 | 32dp
6 |
7 |
--------------------------------------------------------------------------------
/example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ValidatableTextInputView
3 |
4 | Text change trigger
5 | Focus change trigger
6 | Material design colors validator
7 | Ex) blue, red, yellow
8 |
9 | First name (Required)
10 | Last name (Required)
11 | Email (Not required)
12 | Number Only
13 | Ascii Only
14 | Submit
15 |
16 | Material design colors
17 |
18 | Required
19 | Invalid email
20 | Input only number
21 | Input only ascii characters
22 |
23 | Failed to validate by network error
24 | Color name is not match
25 |
26 | Error occurred
27 | Success
28 |
29 | Change button enable
30 | Validation with changing button enable
31 |
32 |
--------------------------------------------------------------------------------
/example/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
16 |
17 |
23 |
24 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/example/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/example/src/test/java/co/kyash/vtl/example/testing/RxImmediateSchedulerRule.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.example.testing
2 |
3 | import io.reactivex.rxjava3.plugins.RxJavaPlugins
4 | import io.reactivex.rxjava3.schedulers.Schedulers
5 | import org.junit.rules.TestRule
6 | import org.junit.runner.Description
7 | import org.junit.runners.model.Statement
8 |
9 | class RxImmediateSchedulerRule : TestRule {
10 |
11 | override fun apply(base: Statement, description: Description): Statement {
12 | return object : Statement() {
13 | @Throws(Throwable::class)
14 | override fun evaluate() {
15 | RxJavaPlugins.setIoSchedulerHandler { _ -> Schedulers.trampoline() }
16 | RxJavaPlugins.setNewThreadSchedulerHandler { _ -> Schedulers.trampoline() }
17 | RxJavaPlugins.setComputationSchedulerHandler { _ -> Schedulers.trampoline() }
18 | RxJavaPlugins.setSingleSchedulerHandler { _ -> Schedulers.trampoline() }
19 |
20 | try {
21 | base.evaluate()
22 | } finally {
23 | RxJavaPlugins.reset()
24 | }
25 | }
26 | }
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/example/src/test/java/co/kyash/vtl/example/validators/MaterialDesignColorsValidatorTest.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.example.validators
2 |
3 | import android.content.Context
4 | import co.kyash.vtl.example.api.MaterialDesignColorsApi
5 | import co.kyash.vtl.example.testing.RxImmediateSchedulerRule
6 | import co.kyash.vtl.validators.VtlValidator
7 | import com.nhaarman.mockitokotlin2.doReturn
8 | import com.nhaarman.mockitokotlin2.mock
9 | import io.reactivex.rxjava3.core.Single
10 | import org.junit.Before
11 | import org.junit.Ignore
12 | import org.junit.Rule
13 | import org.junit.Test
14 | import org.junit.runner.RunWith
15 | import org.robolectric.ParameterizedRobolectricTestRunner
16 | import org.robolectric.RuntimeEnvironment
17 |
18 | @Suppress("unused")
19 | @RunWith(ParameterizedRobolectricTestRunner::class)
20 | class MaterialDesignColorsValidatorTest(
21 | private val text: String?,
22 | private val errorMessage: String?
23 | ) {
24 |
25 | companion object {
26 | private const val ERROR_MESSAGE = "This is not Material design color"
27 |
28 | @JvmStatic
29 | @ParameterizedRobolectricTestRunner.Parameters
30 | fun data(): List> {
31 | return listOf(
32 | arrayOf("Gold", ERROR_MESSAGE),
33 | arrayOf("Blue Red", ERROR_MESSAGE),
34 | arrayOf("Blue ", null),
35 | arrayOf(" Blue", null),
36 | arrayOf("Blue", null),
37 | arrayOf("Red", null)
38 | )
39 | }
40 | }
41 |
42 | @get:Rule
43 | val rxImmediateSchedulerRule = RxImmediateSchedulerRule()
44 |
45 | private lateinit var subject: VtlValidator
46 |
47 | private val context: Context = RuntimeEnvironment.application
48 |
49 | private val api: MaterialDesignColorsApi = mock {
50 | on { all() } doReturn Single.just(listOf("red, pink, blue"))
51 | }
52 |
53 | @Before
54 | @Throws(Exception::class)
55 | fun setUp() {
56 | subject = MaterialDesignColorsValidator(api, context)
57 | }
58 |
59 | @Test(expected = UnsupportedOperationException::class)
60 | fun validate() {
61 | subject.validate(text)
62 | }
63 |
64 | @Ignore
65 | @Test
66 | fun validateAsCompletable() {
67 | if (errorMessage == null) {
68 | subject.validateAsCompletable(context, text).test().assertNoErrors().assertComplete()
69 | } else {
70 | subject.validateAsCompletable(context, text).test().assertError {
71 | it.message == errorMessage
72 | }
73 | }
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536m
2 | android.useAndroidX=true
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kyash/validatable-textinput-layout/85bd0715df374ba1c0a7adf7505169fd4faa5556/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MSYS* | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/jitpack.yml:
--------------------------------------------------------------------------------
1 | jdk:
2 | - openjdk11
3 |
--------------------------------------------------------------------------------
/json/colors.json:
--------------------------------------------------------------------------------
1 | [
2 | "red",
3 | "pink",
4 | "purple",
5 | "deeppurple",
6 | "indigo",
7 | "blue",
8 | "lightblue",
9 | "cyan",
10 | "teal",
11 | "green",
12 | "light Green",
13 | "lime",
14 | "yellow",
15 | "amber",
16 | "orange",
17 | "deeporange",
18 | "brown",
19 | "grey",
20 | "blue Grey",
21 | "black",
22 | "white"
23 | ]
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | import dependencies.Depends
2 | import dependencies.Versions
3 |
4 | apply plugin: 'com.android.library'
5 | apply plugin: 'kotlin-android'
6 | apply plugin: 'maven-publish'
7 |
8 | def versionMajor = 1
9 | def versionMinor = 1
10 | def versionPatch = 0
11 |
12 | group = 'co.kyash'
13 | version = "$versionMajor.$versionMinor.$versionPatch"
14 |
15 | android {
16 | compileSdkVersion Versions.androidCompileSdkVersion
17 |
18 | defaultConfig {
19 | minSdkVersion Versions.androidMinSdkVersion
20 | targetSdkVersion Versions.androidTargetSdkVersion
21 | versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch
22 | versionName "$versionMajor.$versionMinor.$versionPatch"
23 | }
24 |
25 | buildTypes {
26 | release {
27 | debuggable false
28 | zipAlignEnabled true
29 | minifyEnabled false
30 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
31 | }
32 | }
33 |
34 | testOptions {
35 | unitTests.includeAndroidResources = true
36 | }
37 | }
38 |
39 | afterEvaluate {
40 | publishing {
41 | publications {
42 | release(MavenPublication) {
43 | from components.release
44 | artifactId = "validatable-textinput-layout"
45 | artifact(sourcesJar)
46 | }
47 | }
48 | }
49 | }
50 |
51 | dependencies {
52 | //==================== Support Library ====================
53 | implementation Depends.AndroidX.appCompat
54 | implementation Depends.AndroidX.design
55 |
56 | //==================== Structure ====================
57 | implementation Depends.Rx.RxJava
58 |
59 | //==================== Test ====================
60 | testImplementation Depends.Test.junit
61 | testImplementation Depends.Test.mockitoKotlin
62 | testImplementation Depends.Test.robolectric
63 | }
64 |
65 | task sourcesJar(type: Jar) {
66 | from android.sourceSets.main.java.srcDirs
67 | classifier = 'sources'
68 | }
69 |
70 | artifacts {
71 | archives sourcesJar
72 | }
73 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/library/src/main/java/co/kyash/vtl/ValidatableTextInputLayout.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl
2 |
3 | import android.content.Context
4 | import android.os.Handler
5 | import android.os.Looper
6 | import android.text.Editable
7 | import android.text.TextUtils
8 | import android.text.TextWatcher
9 | import android.util.AttributeSet
10 | import android.view.View
11 | import android.view.View.OnFocusChangeListener
12 | import android.view.ViewGroup
13 | import co.kyash.vtl.validators.VtlValidator
14 | import com.google.android.material.textfield.TextInputLayout
15 | import io.reactivex.rxjava3.core.BackpressureStrategy
16 | import io.reactivex.rxjava3.core.Completable
17 | import io.reactivex.rxjava3.core.Flowable
18 | import io.reactivex.rxjava3.disposables.CompositeDisposable
19 | import io.reactivex.rxjava3.functions.Consumer
20 | import io.reactivex.rxjava3.internal.functions.Functions
21 | import io.reactivex.rxjava3.processors.PublishProcessor
22 | import io.reactivex.rxjava3.schedulers.Schedulers
23 | import java.util.concurrent.TimeUnit
24 |
25 | class ValidatableTextInputLayout @JvmOverloads constructor(
26 | context: Context,
27 | attrs: AttributeSet? = null,
28 | defStyleAttr: Int = 0
29 | ) : TextInputLayout(context, attrs, defStyleAttr), ValidatableView {
30 |
31 | override val validationFlowables = ArrayList>()
32 |
33 | companion object {
34 | private val NONE = -1
35 | private val FOCUS_CHANGED = 1
36 | private val TEXT_CHANGED = 1 shl 1
37 | }
38 |
39 | private var shouldValidateOnFocusChanged = false
40 | private var shouldValidateOnTextChanged = false
41 | private var shouldValidateOnTextChangedOnce = false
42 | private var triggerAfterValidation = false
43 | private var validationInterval = 300L
44 |
45 | init {
46 | val a = context.theme.obtainStyledAttributes(attrs, R.styleable.ValidatableTextInputLayout, 0, 0)
47 |
48 | val trigger = a.getInt(R.styleable.ValidatableTextInputLayout_trigger, NONE)
49 | if (trigger > 0) {
50 | shouldValidateOnFocusChanged = trigger and FOCUS_CHANGED != 0
51 | shouldValidateOnTextChanged = trigger and TEXT_CHANGED != 0
52 | }
53 |
54 | triggerAfterValidation = a.getBoolean(R.styleable.ValidatableTextInputLayout_triggerAfterValidation, false)
55 | validationInterval = a.getInteger(R.styleable.ValidatableTextInputLayout_interval, 300).toLong()
56 |
57 | a.recycle()
58 | }
59 |
60 | private val textProcessor = PublishProcessor.create()
61 |
62 | private val compositeDisposable = CompositeDisposable()
63 |
64 | private val validators = ArrayList()
65 |
66 | private val mainHandler = HandlerProvider.createMainHandler()
67 |
68 | private val textWatcher = object : TextWatcher {
69 | override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
70 | //
71 | }
72 |
73 | override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
74 | //
75 | }
76 |
77 | override fun afterTextChanged(s: Editable) {
78 | if (!triggerAfterValidation) {
79 | textProcessor.onNext(s.toString())
80 | }
81 | }
82 | }
83 |
84 | private val onCustomFocusChangeListener = OnFocusChangeListener { _, hasFocus ->
85 | if (!triggerAfterValidation) {
86 |
87 | if (hasFocus) {
88 | if (shouldValidateOnTextChanged || shouldValidateOnTextChangedOnce) {
89 | shouldValidateOnTextChangedOnce = false
90 | compositeDisposable.clear()
91 | compositeDisposable.add(
92 | Flowable.zip(validationFlowables) { Any() }
93 | .doOnError({ this.showErrorMessage(it) })
94 | .retry() // non-terminated stream
95 | .subscribeOn(Schedulers.computation())
96 | .subscribe({ clearErrorMessage() }, {})
97 | )
98 | }
99 | } else {
100 | if (shouldValidateOnFocusChanged) {
101 | compositeDisposable.clear()
102 | compositeDisposable.add(
103 | validateAsCompletable().subscribe(Functions.EMPTY_ACTION, Consumer {})
104 | )
105 | }
106 | }
107 |
108 | }
109 | }
110 |
111 | override fun onDetachedFromWindow() {
112 | compositeDisposable.clear()
113 | super.onDetachedFromWindow()
114 | }
115 |
116 | override fun addView(child: View, index: Int, params: ViewGroup.LayoutParams) {
117 | super.addView(child, index, params)
118 | initListeners()
119 | }
120 |
121 | private fun initListeners() {
122 | val editText = editText ?: return
123 |
124 | if (shouldValidateOnTextChanged || shouldValidateOnTextChangedOnce) {
125 | shouldValidateOnTextChangedOnce = TextUtils.isEmpty(error)
126 | editText.removeTextChangedListener(textWatcher)
127 | editText.addTextChangedListener(textWatcher)
128 | }
129 |
130 | if (shouldValidateOnFocusChanged || shouldValidateOnTextChanged) {
131 | editText.onFocusChangeListener = onCustomFocusChangeListener
132 | }
133 | }
134 |
135 | private fun clearErrorMessage() {
136 | mainHandler.post {
137 | error = null
138 | isErrorEnabled = false
139 | }
140 | }
141 |
142 | override fun validate(): Boolean {
143 | if (visibility != View.VISIBLE) {
144 | return true
145 | }
146 |
147 | validators.forEach {
148 | if (!it.validate(getText())) {
149 | showErrorMessage(it.getErrorMessage())
150 | return false
151 | }
152 | }
153 | clearErrorMessage()
154 | return true
155 | }
156 |
157 | override fun validateAsCompletable(): Completable {
158 | if (visibility != View.VISIBLE) {
159 | return Completable.complete()
160 | }
161 |
162 | val validations: List = validators.map {
163 | it.validateAsCompletable(context, getText())
164 | }
165 |
166 | return Completable.mergeDelayError(validations)
167 | .doOnComplete { clearErrorMessage() }
168 | .doOnError { showErrorMessage(it) }
169 | .subscribeOn(Schedulers.computation())
170 | }
171 |
172 | fun getText(): String {
173 | return if (editText != null) editText!!.text.toString() else ""
174 | }
175 |
176 | fun setText(text: String?) {
177 | if (editText != null) editText!!.setText(text)
178 | }
179 |
180 | override fun setOnClickListener(onClickListener: View.OnClickListener?) {
181 | if (editText != null) {
182 | editText!!.setOnClickListener(onClickListener)
183 | }
184 | }
185 |
186 | override fun register(validator: VtlValidator): ValidatableView {
187 | register(arrayListOf(validator))
188 | return this
189 | }
190 |
191 | override fun register(validators: List): ValidatableView {
192 | this.validators.addAll(validators)
193 |
194 | this.validators.mapTo(validationFlowables) {
195 | textProcessor.onBackpressureDrop()
196 | .throttleLast(validationInterval, TimeUnit.MILLISECONDS)
197 | // hack to emit an event to `onNext` when completable is completed.
198 | .flatMap { x ->
199 | it.validateAsCompletable(context, x)
200 | .toSingleDefault(Any())
201 | .toObservable()
202 | .toFlowable(BackpressureStrategy.BUFFER)
203 | }
204 | }
205 | return this
206 | }
207 |
208 | override fun clearValidators() {
209 | compositeDisposable.clear()
210 | validators.clear()
211 | }
212 |
213 | override fun setErrorEnabled(enabled: Boolean) {
214 | super.setErrorEnabled(enabled)
215 | toggleErrorView(enabled)
216 | }
217 |
218 | // http://stackoverflow.com/questions/33230621/textinputlayout-seterrorenabled-doesnt-create-new-textview-object
219 | private fun toggleErrorView(visible: Boolean) {
220 | val visibility = if (visible) View.VISIBLE else View.GONE
221 | if (childCount == 2) getChildAt(1).visibility = visibility
222 | }
223 |
224 | private fun showErrorMessage(throwable: Throwable) {
225 | val errorMessage = VtlValidationFailureException.getErrorMessage(throwable)
226 | showErrorMessage(errorMessage)
227 | }
228 |
229 | private fun showErrorMessage(errorMessage: String?) {
230 | if (errorMessage != null) {
231 | mainHandler.post {
232 | error = errorMessage
233 | isErrorEnabled = true
234 | triggerAfterValidation = false
235 | }
236 | } else {
237 | clearErrorMessage()
238 | }
239 | }
240 |
241 | private class HandlerProvider {
242 | companion object {
243 | private var mainHandler: Handler? = null
244 |
245 | fun createMainHandler(): Handler {
246 | return if (mainHandler == null) {
247 | Handler(Looper.getMainLooper())
248 | } else {
249 | mainHandler!!
250 | }
251 | }
252 | }
253 | }
254 |
255 | }
256 |
--------------------------------------------------------------------------------
/library/src/main/java/co/kyash/vtl/ValidatableView.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl
2 |
3 | import co.kyash.vtl.validators.VtlValidator
4 | import io.reactivex.rxjava3.core.Completable
5 | import io.reactivex.rxjava3.core.Flowable
6 |
7 | interface ValidatableView {
8 |
9 | val validationFlowables: ArrayList>
10 |
11 | fun validate(): Boolean
12 |
13 | fun validateAsCompletable(): Completable
14 |
15 | fun register(validator: VtlValidator): ValidatableView
16 |
17 | fun register(validators: List): ValidatableView
18 |
19 | fun clearValidators()
20 | }
21 |
--------------------------------------------------------------------------------
/library/src/main/java/co/kyash/vtl/VtlValidationFailureException.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl
2 |
3 | class VtlValidationFailureException(
4 | private val errorMessage: String?
5 | ) : RuntimeException(errorMessage) {
6 |
7 | companion object {
8 | fun getErrorMessage(throwable: Throwable?): String? {
9 | var errorMessage: String? = null
10 | var cause: Throwable? = throwable
11 |
12 | while (cause != null) {
13 | if (cause is VtlValidationFailureException) {
14 | errorMessage = cause.errorMessage
15 | break
16 | }
17 |
18 | cause = cause.cause
19 | }
20 |
21 | return errorMessage
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/library/src/main/java/co/kyash/vtl/validators/AlphabetOnlyValidator.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import android.text.TextUtils
5 | import co.kyash.vtl.VtlValidationFailureException
6 | import io.reactivex.rxjava3.core.Completable
7 | import io.reactivex.rxjava3.schedulers.Schedulers
8 | import java.util.regex.Pattern
9 |
10 | /**
11 | * Validation error when the text is not written by Alphabet
12 | */
13 | class AlphabetOnlyValidator(
14 | private val errorMessage: String
15 | ) : VtlValidator {
16 |
17 | companion object {
18 | private val PATTERN = Pattern.compile("^[a-zA-Z]+\$")
19 | }
20 |
21 | override fun validateAsCompletable(context: Context, text: String?): Completable {
22 | return Completable.fromRunnable {
23 | if (!validate(text)) {
24 | throw VtlValidationFailureException(errorMessage)
25 | }
26 | }.subscribeOn(Schedulers.computation())
27 | }
28 |
29 | override fun validate(text: String?): Boolean {
30 | val trimText = text?.replace(" ", "")?.replace(" ", "")?.trim()
31 | return TextUtils.isEmpty(trimText) || PATTERN.matcher(trimText).matches()
32 | }
33 |
34 | override fun getErrorMessage(): String {
35 | return errorMessage
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/library/src/main/java/co/kyash/vtl/validators/AsciiOnlyValidator.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import android.text.TextUtils
5 | import co.kyash.vtl.VtlValidationFailureException
6 | import io.reactivex.rxjava3.core.Completable
7 | import io.reactivex.rxjava3.schedulers.Schedulers
8 | import java.util.regex.Pattern
9 |
10 | /**
11 | * Validation error when the text contains non-ascii characters
12 | */
13 | class AsciiOnlyValidator(
14 | private val errorMessage: String
15 | ) : VtlValidator {
16 |
17 | companion object {
18 | private val PATTERN = Pattern.compile("\\p{ASCII}+\$")
19 | }
20 |
21 | override fun validateAsCompletable(context: Context, text: String?): Completable {
22 | return Completable.fromRunnable {
23 | if (!validate(text)) {
24 | throw VtlValidationFailureException(errorMessage)
25 | }
26 | }.subscribeOn(Schedulers.computation())
27 | }
28 |
29 | override fun validate(text: String?): Boolean {
30 | return TextUtils.isEmpty(text) || PATTERN.matcher(text).matches()
31 | }
32 |
33 | override fun getErrorMessage(): String {
34 | return errorMessage
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/main/java/co/kyash/vtl/validators/EmailValidator.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import android.text.TextUtils
5 | import co.kyash.vtl.VtlValidationFailureException
6 | import io.reactivex.rxjava3.core.Completable
7 | import io.reactivex.rxjava3.schedulers.Schedulers
8 | import java.util.regex.Pattern
9 |
10 | /**
11 | * Validation error when the text is invalid email address
12 | */
13 | class EmailValidator(
14 | private val errorMessage: String
15 | ) : VtlValidator {
16 |
17 | companion object {
18 | private val PATTERN = Pattern.compile("\\A[\\p{ASCII}&&\\S]+@[\\p{ASCII}&&\\S]+\\z")
19 | }
20 |
21 | override fun validateAsCompletable(context: Context, text: String?): Completable {
22 | return Completable.fromRunnable {
23 | if (!validate(text)) {
24 | throw VtlValidationFailureException(errorMessage)
25 | }
26 | }.subscribeOn(Schedulers.computation())
27 | }
28 |
29 | override fun validate(text: String?): Boolean {
30 | return TextUtils.isEmpty(text) || PATTERN.matcher(text).matches()
31 | }
32 |
33 | override fun getErrorMessage(): String {
34 | return errorMessage
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/main/java/co/kyash/vtl/validators/HiraganaOnlyValidator.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import android.text.TextUtils
5 | import co.kyash.vtl.VtlValidationFailureException
6 | import io.reactivex.rxjava3.core.Completable
7 | import io.reactivex.rxjava3.schedulers.Schedulers
8 | import java.util.regex.Pattern
9 |
10 | /**
11 | * Validation error when the text is not written by Japanese Hiragana
12 | */
13 | class HiraganaOnlyValidator(
14 | private val errorMessage: String
15 | ) : VtlValidator {
16 |
17 | companion object {
18 | private val PATTERN = Pattern.compile("^[ぁ-ん\u2014\u2015\u30fc]+$")
19 | }
20 |
21 | override fun validateAsCompletable(context: Context, text: String?): Completable {
22 | return Completable.fromRunnable {
23 | if (!validate(text)) {
24 | throw VtlValidationFailureException(errorMessage)
25 | }
26 | }.subscribeOn(Schedulers.computation())
27 | }
28 |
29 | override fun validate(text: String?): Boolean {
30 | return TextUtils.isEmpty(text) || PATTERN.matcher(text).matches()
31 | }
32 |
33 | override fun getErrorMessage(): String {
34 | return errorMessage
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/main/java/co/kyash/vtl/validators/KatakanaOnlyValidator.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import android.text.TextUtils
5 | import co.kyash.vtl.VtlValidationFailureException
6 | import io.reactivex.rxjava3.core.Completable
7 | import io.reactivex.rxjava3.schedulers.Schedulers
8 | import java.util.regex.Pattern
9 |
10 | /**
11 | * Validation error when the text is not written by Japanese Katakana
12 | */
13 | class KatakanaOnlyValidator(
14 | private val errorMessage: String
15 | ) : VtlValidator {
16 |
17 | companion object {
18 | private val PATTERN = Pattern.compile("^[ァ-ヶ\u2014\u2015\u30fc]+$")
19 | }
20 |
21 | override fun validateAsCompletable(context: Context, text: String?): Completable {
22 | return Completable.fromRunnable {
23 | if (!validate(text)) {
24 | throw VtlValidationFailureException(errorMessage)
25 | }
26 | }.subscribeOn(Schedulers.computation())
27 | }
28 |
29 | override fun validate(text: String?): Boolean {
30 | return TextUtils.isEmpty(text) || PATTERN.matcher(text).matches()
31 | }
32 |
33 | override fun getErrorMessage(): String {
34 | return errorMessage
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/main/java/co/kyash/vtl/validators/MinLengthValidator.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import co.kyash.vtl.VtlValidationFailureException
5 | import io.reactivex.rxjava3.core.Completable
6 | import io.reactivex.rxjava3.schedulers.Schedulers
7 |
8 | /**
9 | * Validation error when the text length is shorter
10 | */
11 | class MinLengthValidator(
12 | private val errorMessage: String,
13 | private val minLength: Int,
14 | private val trim: Boolean = true
15 | ) : VtlValidator {
16 |
17 | /**
18 | * Validate and return completable
19 | *
20 | * @param context
21 | * @param text
22 | * @return Completable
23 | * @throws Exception which contains the error message
24 | */
25 | override fun validateAsCompletable(context: Context, text: String?): Completable {
26 | return Completable.fromRunnable {
27 | if (!validate(text)) {
28 | throw VtlValidationFailureException(errorMessage)
29 | }
30 | }.subscribeOn(Schedulers.computation())
31 | }
32 |
33 | /**
34 | * Validate immediately
35 | *
36 | * @param text
37 | * @return result
38 | */
39 | override fun validate(text: String?): Boolean {
40 | return text?.let {
41 | if (trim) it.trim() else it
42 | }?.length ?: 0 >= minLength
43 | }
44 |
45 | /**
46 | * @return error message
47 | */
48 | override fun getErrorMessage(): String {
49 | return errorMessage
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/library/src/main/java/co/kyash/vtl/validators/NoSpecialCharacterValidator.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import co.kyash.vtl.VtlValidationFailureException
5 | import io.reactivex.rxjava3.core.Completable
6 | import io.reactivex.rxjava3.schedulers.Schedulers
7 |
8 | /**
9 | * Validation error when the text contains special characters.
10 | */
11 | class NoSpecialCharacterValidator(
12 | private val errorMessage: String
13 | ) : VtlValidator {
14 | companion object {
15 | private const val VS15 = '\uFE0E'
16 | private const val VS16 = '\uFE0F'
17 |
18 | private const val ZERO_WIDTH_JOINER = '\u200D'
19 | private const val ENCLOSING_KEYCAP = '\u20E3'
20 | }
21 |
22 | override fun validateAsCompletable(context: Context, text: String?): Completable =
23 | Completable.fromRunnable {
24 | if (!validate(text)) {
25 | throw VtlValidationFailureException(errorMessage)
26 | }
27 | }.subscribeOn(Schedulers.computation())
28 |
29 | override fun validate(text: String?): Boolean {
30 | if (text.isNullOrBlank()) {
31 | return true
32 | }
33 | return text.none {
34 | val type = Character.getType(it).toByte()
35 | it == VS15
36 | || it == VS16
37 | || it == ZERO_WIDTH_JOINER
38 | || it == ENCLOSING_KEYCAP
39 | || type == Character.SURROGATE
40 | || type == Character.OTHER_SYMBOL
41 | }
42 | }
43 |
44 | override fun getErrorMessage(): String? = errorMessage
45 | }
46 |
--------------------------------------------------------------------------------
/library/src/main/java/co/kyash/vtl/validators/NumberOnlyValidator.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import android.text.TextUtils
5 | import co.kyash.vtl.VtlValidationFailureException
6 | import io.reactivex.rxjava3.core.Completable
7 | import io.reactivex.rxjava3.schedulers.Schedulers
8 | import java.util.regex.Pattern
9 |
10 | /**
11 | * Validation error when the text is not number
12 | */
13 | class NumberOnlyValidator(
14 | private val errorMessage: String
15 | ) : VtlValidator {
16 |
17 | companion object {
18 | private val PATTERN = Pattern.compile("^[0-9]+")
19 | }
20 |
21 | override fun validateAsCompletable(context: Context, text: String?): Completable {
22 | return Completable.fromRunnable {
23 | if (!validate(text)) {
24 | throw VtlValidationFailureException(errorMessage)
25 | }
26 | }.subscribeOn(Schedulers.computation())
27 | }
28 |
29 | override fun validate(text: String?): Boolean {
30 | return TextUtils.isEmpty(text) || PATTERN.matcher(text).matches()
31 | }
32 |
33 | override fun getErrorMessage(): String {
34 | return errorMessage
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/main/java/co/kyash/vtl/validators/RequiredValidator.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import android.text.TextUtils
5 | import co.kyash.vtl.VtlValidationFailureException
6 | import io.reactivex.rxjava3.core.Completable
7 | import io.reactivex.rxjava3.schedulers.Schedulers
8 |
9 | /**
10 | * Validation error when the text is empty.
11 | */
12 | class RequiredValidator(
13 | private val errorMessage: String,
14 | private val trim: Boolean = true
15 | ) : VtlValidator {
16 |
17 | /**
18 | * Validate and return completable
19 | *
20 | * @param context
21 | * @param text
22 | * @return Completable
23 | * @throws Exception which contains the error message
24 | */
25 | override fun validateAsCompletable(context: Context, text: String?): Completable {
26 | return Completable.fromRunnable {
27 | if (!validate(text)) {
28 | throw VtlValidationFailureException(errorMessage)
29 | }
30 | }.subscribeOn(Schedulers.computation())
31 | }
32 |
33 | /**
34 | * Validate immediately
35 | *
36 | * @param text
37 | * @return result
38 | */
39 | override fun validate(text: String?): Boolean {
40 | return !TextUtils.isEmpty(text?.let { if (trim) it.trim() else it })
41 | }
42 |
43 | /**
44 | * @return error message
45 | */
46 | override fun getErrorMessage(): String {
47 | return errorMessage
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/library/src/main/java/co/kyash/vtl/validators/VtlValidator.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import io.reactivex.rxjava3.core.Completable
5 |
6 | interface VtlValidator {
7 |
8 | /**
9 | * @param context Context
10 | * @param text The text which the user inputs
11 | * @return Completable which contains an error message
12 | */
13 | fun validateAsCompletable(context: Context, text: String?): Completable
14 |
15 | /**
16 | * @param text The text which the user inputs
17 | * @return result : error is false
18 | */
19 | fun validate(text: String?): Boolean
20 |
21 | /**
22 | * @return errorMessage
23 | */
24 | fun getErrorMessage(): String?
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | validatable-textinput-layout
3 |
4 |
--------------------------------------------------------------------------------
/library/src/test/java/co/kyash/vtl/testing/RxImmediateSchedulerRule.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.testing
2 |
3 | import io.reactivex.rxjava3.plugins.RxJavaPlugins
4 | import io.reactivex.rxjava3.schedulers.Schedulers
5 | import org.junit.rules.TestRule
6 | import org.junit.runner.Description
7 | import org.junit.runners.model.Statement
8 |
9 | class RxImmediateSchedulerRule : TestRule {
10 |
11 | override fun apply(base: Statement, description: Description): Statement {
12 | return object : Statement() {
13 | @Throws(Throwable::class)
14 | override fun evaluate() {
15 | RxJavaPlugins.setIoSchedulerHandler { _ -> Schedulers.trampoline() }
16 | RxJavaPlugins.setNewThreadSchedulerHandler { _ -> Schedulers.trampoline() }
17 | RxJavaPlugins.setComputationSchedulerHandler { _ -> Schedulers.trampoline() }
18 | RxJavaPlugins.setSingleSchedulerHandler { _ -> Schedulers.trampoline() }
19 |
20 | try {
21 | base.evaluate()
22 | } finally {
23 | RxJavaPlugins.reset()
24 | }
25 | }
26 | }
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/library/src/test/java/co/kyash/vtl/validators/AlphabetOnlyValidatorTest.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import co.kyash.vtl.testing.RxImmediateSchedulerRule
5 | import junit.framework.Assert.assertEquals
6 | import org.junit.Before
7 | import org.junit.Rule
8 | import org.junit.Test
9 | import org.junit.runner.RunWith
10 | import org.robolectric.ParameterizedRobolectricTestRunner
11 | import org.robolectric.RuntimeEnvironment
12 |
13 | @Suppress("unused")
14 | @RunWith(ParameterizedRobolectricTestRunner::class)
15 | class AlphabetOnlyValidatorTest(
16 | private val text: String?,
17 | private val result: Boolean,
18 | private val errorMessage: String?
19 | ) {
20 |
21 | companion object {
22 | private const val ERROR_MESSAGE = "This contains non-hiragana characters"
23 |
24 | @JvmStatic
25 | @ParameterizedRobolectricTestRunner.Parameters
26 | fun data(): List> {
27 | return listOf(
28 | arrayOf("あ", false, ERROR_MESSAGE),
29 | arrayOf("ア", false, ERROR_MESSAGE),
30 | arrayOf("阿", false, ERROR_MESSAGE),
31 | arrayOf("A", false, ERROR_MESSAGE),
32 | arrayOf("****です", false, ERROR_MESSAGE),
33 | arrayOf("-", false, ERROR_MESSAGE),
34 | arrayOf("@", false, ERROR_MESSAGE),
35 | arrayOf("*", false, ERROR_MESSAGE),
36 | arrayOf("1", false, ERROR_MESSAGE),
37 | arrayOf(null, true, null),
38 | arrayOf("", true, null),
39 | arrayOf(" ", true, null),
40 | arrayOf(" ", true, null),
41 | arrayOf("a", true, null),
42 | arrayOf("A", true, null),
43 | arrayOf("YUSUKE KONISHI", true, null)
44 | )
45 | }
46 | }
47 |
48 | @get:Rule
49 | val rxImmediateSchedulerRule = RxImmediateSchedulerRule()
50 |
51 | private lateinit var subject: VtlValidator
52 |
53 | private val context: Context = RuntimeEnvironment.application
54 |
55 | @Before
56 | @Throws(Exception::class)
57 | fun setUp() {
58 | subject = AlphabetOnlyValidator(ERROR_MESSAGE)
59 | }
60 |
61 | @Test
62 | fun validate() {
63 | assertEquals(result, subject.validate(text))
64 | }
65 |
66 | @Test
67 | fun validateAsCompletable() {
68 | if (errorMessage == null) {
69 | subject.validateAsCompletable(context, text).test().assertNoErrors().assertComplete()
70 | } else {
71 | subject.validateAsCompletable(context, text).test().assertError { it ->
72 | it.message == errorMessage
73 | }
74 | }
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/library/src/test/java/co/kyash/vtl/validators/AsciiOnlyValidatorTest.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import co.kyash.vtl.testing.RxImmediateSchedulerRule
5 | import junit.framework.Assert.assertEquals
6 | import org.junit.Before
7 | import org.junit.Rule
8 | import org.junit.Test
9 | import org.junit.runner.RunWith
10 | import org.robolectric.ParameterizedRobolectricTestRunner
11 | import org.robolectric.RuntimeEnvironment
12 |
13 | @Suppress("unused")
14 | @RunWith(ParameterizedRobolectricTestRunner::class)
15 | class AsciiOnlyValidatorTest(
16 | private val text: String?,
17 | private val result: Boolean,
18 | private val errorMessage: String?
19 | ) {
20 |
21 | companion object {
22 | private const val ERROR_MESSAGE = "This contains non-hiragana characters"
23 |
24 | @JvmStatic
25 | @ParameterizedRobolectricTestRunner.Parameters
26 | fun data(): List> {
27 | return listOf(
28 | arrayOf("あ", false, ERROR_MESSAGE),
29 | arrayOf("ア", false, ERROR_MESSAGE),
30 | arrayOf("阿", false, ERROR_MESSAGE),
31 | arrayOf("A", false, ERROR_MESSAGE),
32 | arrayOf("****です", false, ERROR_MESSAGE),
33 | arrayOf(null, true, null),
34 | arrayOf("", true, null),
35 | arrayOf(" ", true, null),
36 | arrayOf("a", true, null),
37 | arrayOf("-", true, null),
38 | arrayOf("@", true, null),
39 | arrayOf("*", true, null),
40 | arrayOf("1", true, null)
41 | )
42 | }
43 | }
44 |
45 | @get:Rule
46 | val rxImmediateSchedulerRule = RxImmediateSchedulerRule()
47 |
48 | private lateinit var subject: VtlValidator
49 |
50 | private val context: Context = RuntimeEnvironment.application
51 |
52 | @Before
53 | @Throws(Exception::class)
54 | fun setUp() {
55 | subject = AsciiOnlyValidator(ERROR_MESSAGE)
56 | }
57 |
58 | @Test
59 | fun validate() {
60 | assertEquals(result, subject.validate(text))
61 | }
62 |
63 | @Test
64 | fun validateAsCompletable() {
65 | if (errorMessage == null) {
66 | subject.validateAsCompletable(context, text).test().assertNoErrors().assertComplete()
67 | } else {
68 | subject.validateAsCompletable(context, text).test().assertError { it ->
69 | it.message == errorMessage
70 | }
71 | }
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/library/src/test/java/co/kyash/vtl/validators/EmailValidatorTest.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import co.kyash.vtl.testing.RxImmediateSchedulerRule
5 | import junit.framework.Assert.assertEquals
6 | import org.junit.Before
7 | import org.junit.Rule
8 | import org.junit.Test
9 | import org.junit.runner.RunWith
10 | import org.robolectric.ParameterizedRobolectricTestRunner
11 | import org.robolectric.RuntimeEnvironment
12 |
13 | @Suppress("unused")
14 | @RunWith(ParameterizedRobolectricTestRunner::class)
15 | class EmailValidatorTest(
16 | private val text: String?,
17 | private val result: Boolean,
18 | private val errorMessage: String?
19 | ) {
20 |
21 | companion object {
22 | private val ERROR_MESSAGE = "This is invalid email"
23 |
24 | @JvmStatic
25 | @ParameterizedRobolectricTestRunner.Parameters
26 | fun data(): List> {
27 | return listOf(
28 | arrayOf("konifar", false, ERROR_MESSAGE),
29 | arrayOf("@", false, ERROR_MESSAGE),
30 | arrayOf("konifar@", false, ERROR_MESSAGE),
31 | arrayOf("@gmail", false, ERROR_MESSAGE),
32 | arrayOf("あ@gmail", false, ERROR_MESSAGE),
33 | arrayOf(null, true, null),
34 | arrayOf("", true, null),
35 | arrayOf("konifar@gmail", true, null),
36 | arrayOf("konifar@gmail.com", true, null)
37 | )
38 | }
39 | }
40 |
41 | @get:Rule
42 | val rxImmediateSchedulerRule = RxImmediateSchedulerRule()
43 |
44 | private lateinit var subject: VtlValidator
45 |
46 | private val context: Context = RuntimeEnvironment.application
47 |
48 | @Before
49 | @Throws(Exception::class)
50 | fun setUp() {
51 | subject = EmailValidator(ERROR_MESSAGE)
52 | }
53 |
54 | @Test
55 | fun validate() {
56 | assertEquals(result, subject.validate(text))
57 | }
58 |
59 | @Test
60 | fun validateAsCompletable() {
61 | if (errorMessage == null) {
62 | subject.validateAsCompletable(context, text).test().assertNoErrors().assertComplete()
63 | } else {
64 | subject.validateAsCompletable(context, text).test().assertError { it ->
65 | it.message == errorMessage
66 | }
67 | }
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/library/src/test/java/co/kyash/vtl/validators/HiraganaOnlyValidatorTest.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import co.kyash.vtl.testing.RxImmediateSchedulerRule
5 | import junit.framework.Assert.assertEquals
6 | import org.junit.Before
7 | import org.junit.Rule
8 | import org.junit.Test
9 | import org.junit.runner.RunWith
10 | import org.robolectric.ParameterizedRobolectricTestRunner
11 | import org.robolectric.RuntimeEnvironment
12 |
13 | @Suppress("unused")
14 | @RunWith(ParameterizedRobolectricTestRunner::class)
15 | class HiraganaOnlyValidatorTest(
16 | private val text: String?,
17 | private val result: Boolean,
18 | private val errorMessage: String?
19 | ) {
20 |
21 | companion object {
22 | private val ERROR_MESSAGE = "This contains non-hiragana characters"
23 |
24 | @JvmStatic
25 | @ParameterizedRobolectricTestRunner.Parameters
26 | fun data(): List> {
27 | return listOf(
28 | arrayOf("a", false, ERROR_MESSAGE),
29 | arrayOf("ア", false, ERROR_MESSAGE),
30 | arrayOf("阿", false, ERROR_MESSAGE),
31 | arrayOf("あ阿", false, ERROR_MESSAGE),
32 | arrayOf(null, true, null),
33 | arrayOf("", true, null),
34 | arrayOf("ぁあぃいぅうぇえぉおかがきぎくぐけげこご" +
35 | "さざしじすずせぜそぞただちぢっつづてでとど" +
36 | "なにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむめも" +
37 | "ゃやゅゆょよらりるれろゎわゐゑをん—―ー", true, null)
38 | )
39 | }
40 | }
41 |
42 | @get:Rule
43 | val rxImmediateSchedulerRule = RxImmediateSchedulerRule()
44 |
45 | private lateinit var subject: VtlValidator
46 |
47 | private val context: Context = RuntimeEnvironment.application
48 |
49 | @Before
50 | @Throws(Exception::class)
51 | fun setUp() {
52 | subject = HiraganaOnlyValidator(ERROR_MESSAGE)
53 | }
54 |
55 | @Test
56 | fun validate() {
57 | assertEquals(result, subject.validate(text))
58 | }
59 |
60 | @Test
61 | fun validateAsCompletable() {
62 | if (errorMessage == null) {
63 | subject.validateAsCompletable(context, text).test().assertNoErrors().assertComplete()
64 | } else {
65 | subject.validateAsCompletable(context, text).test().assertError { it ->
66 | it.message == errorMessage
67 | }
68 | }
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/library/src/test/java/co/kyash/vtl/validators/KatakanaOnlyValidatorTest.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import co.kyash.vtl.testing.RxImmediateSchedulerRule
5 | import junit.framework.Assert.assertEquals
6 | import org.junit.Before
7 | import org.junit.Rule
8 | import org.junit.Test
9 | import org.junit.runner.RunWith
10 | import org.robolectric.ParameterizedRobolectricTestRunner
11 | import org.robolectric.RuntimeEnvironment
12 |
13 | @Suppress("unused")
14 | @RunWith(ParameterizedRobolectricTestRunner::class)
15 | class KatakanaOnlyValidatorTest(
16 | private val text: String?,
17 | private val result: Boolean,
18 | private val errorMessage: String?
19 | ) {
20 |
21 | companion object {
22 | private val ERROR_MESSAGE = "This contains non-hiragana characters"
23 |
24 | @JvmStatic
25 | @ParameterizedRobolectricTestRunner.Parameters
26 | fun data(): List> {
27 | return listOf(
28 | arrayOf("a", false, ERROR_MESSAGE),
29 | arrayOf("あ", false, ERROR_MESSAGE),
30 | arrayOf("阿", false, ERROR_MESSAGE),
31 | arrayOf("ア阿", false, ERROR_MESSAGE),
32 | arrayOf(null, true, null),
33 | arrayOf("", true, null),
34 | arrayOf("ァアィイゥウェエォオカガキギクグケゲコゴ" +
35 | "サザシジスズセゼソゾタダチヂッツヅテデトド" +
36 | "ナニヌネノハバパヒビピフブプヘベペホボポマミムメモ" +
37 | "ャヤュユョヨラリルレロヮワヰヱヲンヴヵヶ—―ー", true, null)
38 | )
39 | }
40 | }
41 |
42 | @get:Rule
43 | val rxImmediateSchedulerRule = RxImmediateSchedulerRule()
44 |
45 | private lateinit var subject: VtlValidator
46 |
47 | private val context: Context = RuntimeEnvironment.application
48 |
49 | @Before
50 | @Throws(Exception::class)
51 | fun setUp() {
52 | subject = KatakanaOnlyValidator(ERROR_MESSAGE)
53 | }
54 |
55 | @Test
56 | fun validate() {
57 | assertEquals(result, subject.validate(text))
58 | }
59 |
60 | @Test
61 | fun validateAsCompletable() {
62 | if (errorMessage == null) {
63 | subject.validateAsCompletable(context, text).test().assertNoErrors().assertComplete()
64 | } else {
65 | subject.validateAsCompletable(context, text).test().assertError { it ->
66 | it.message == errorMessage
67 | }
68 | }
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/library/src/test/java/co/kyash/vtl/validators/MinLengthValidatorTest.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import co.kyash.vtl.testing.RxImmediateSchedulerRule
5 | import junit.framework.Assert.assertEquals
6 | import org.junit.Before
7 | import org.junit.Rule
8 | import org.junit.Test
9 | import org.junit.runner.RunWith
10 | import org.robolectric.ParameterizedRobolectricTestRunner
11 | import org.robolectric.RuntimeEnvironment
12 |
13 | @Suppress("unused")
14 | @RunWith(ParameterizedRobolectricTestRunner::class)
15 | class MinLengthValidatorTest(
16 | private val text: String?,
17 | private val trim: Boolean,
18 | private val result: Boolean,
19 | private val errorMessage: String?
20 | ) {
21 |
22 | companion object {
23 | private val MIN_LENGTH = 5
24 | private val ERROR_MESSAGE = "This field has error"
25 |
26 | @JvmStatic
27 | @ParameterizedRobolectricTestRunner.Parameters
28 | fun data(): List> {
29 | return listOf(
30 | // Failure
31 | arrayOf(null, true, false, ERROR_MESSAGE),
32 | arrayOf("", true, false, ERROR_MESSAGE),
33 | arrayOf(" ", true, false, ERROR_MESSAGE),
34 | arrayOf("abcd", true, false, ERROR_MESSAGE),
35 |
36 | // Success
37 | arrayOf(" ", false, true, null),
38 | arrayOf("abcde", true, true, null),
39 | arrayOf("abcdef", true, true, null)
40 | )
41 | }
42 | }
43 |
44 | @get:Rule
45 | val rxImmediateSchedulerRule = RxImmediateSchedulerRule()
46 |
47 | private lateinit var subject: VtlValidator
48 |
49 | private val context: Context = RuntimeEnvironment.application
50 |
51 | @Before
52 | @Throws(Exception::class)
53 | fun setUp() {
54 | subject = MinLengthValidator(ERROR_MESSAGE, MIN_LENGTH, trim)
55 | }
56 |
57 | @Test
58 | fun validate() {
59 | assertEquals(result, subject.validate(text))
60 | }
61 |
62 | @Test
63 | fun validateAsCompletable() {
64 | if (errorMessage == null) {
65 | subject.validateAsCompletable(context, text).test().assertNoErrors().assertComplete()
66 | } else {
67 | subject.validateAsCompletable(context, text).test().assertError { it ->
68 | it.message == errorMessage
69 | }
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/library/src/test/java/co/kyash/vtl/validators/NoSpecialCharacterValidatorTest.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import co.kyash.vtl.testing.RxImmediateSchedulerRule
5 | import junit.framework.Assert.assertEquals
6 | import org.junit.Before
7 | import org.junit.Rule
8 | import org.junit.Test
9 | import org.junit.runner.RunWith
10 | import org.robolectric.ParameterizedRobolectricTestRunner
11 | import org.robolectric.RuntimeEnvironment
12 |
13 | @RunWith(ParameterizedRobolectricTestRunner::class)
14 | class NoSpecialCharacterValidatorTest(
15 | private val text: String?,
16 | private val result: Boolean,
17 | private val errorMessage: String?
18 | ) {
19 | companion object {
20 | private const val ERROR_MESSAGE = "This contains special characters"
21 |
22 | @JvmStatic
23 | @ParameterizedRobolectricTestRunner.Parameters
24 | fun data(): List> =
25 | listOf(
26 | // CJK Unified Ideographs Extension B
27 | arrayOf("\uD844\uDE3D", false, ERROR_MESSAGE),
28 | // Folded Hands
29 | arrayOf("\uD83D\uDE4F", false, ERROR_MESSAGE),
30 | // Grinning Face
31 | arrayOf("\uD83D\uDE00", false, ERROR_MESSAGE),
32 | // Telephone
33 | arrayOf("\u260E\uFE0F", false, ERROR_MESSAGE),
34 | // Telephone
35 | arrayOf("\u260E\uFE0E", false, ERROR_MESSAGE),
36 | // Man Astronaut
37 | arrayOf("\uD83D\uDC68\u200D\uD83D\uDE80", false, ERROR_MESSAGE),
38 | // Skin Tone
39 | arrayOf("\uD83C\uDFFD", false, ERROR_MESSAGE),
40 | // Keycap Digit 1
41 | arrayOf("1\uFE0F\u20E3", false, ERROR_MESSAGE),
42 | arrayOf(null, true, null),
43 | arrayOf(" ", true, null),
44 | arrayOf("ABCD", true, null),
45 | arrayOf("あいうえお", true, null),
46 | arrayOf("Aaあ文1!@#$%^&*()_=-+\";:'{}|\\[]<>?,.", true, null),
47 | // CJK Unified Ideographs Extension A
48 | arrayOf("\u4DB5", true, null)
49 | )
50 | }
51 |
52 | @get:Rule
53 | val rxImmediateSchedulerRule = RxImmediateSchedulerRule()
54 |
55 | private lateinit var validator: VtlValidator
56 |
57 | private val context: Context = RuntimeEnvironment.application
58 |
59 | @Before
60 | fun setUp() {
61 | validator = NoSpecialCharacterValidator(ERROR_MESSAGE)
62 | }
63 |
64 | @Test
65 | fun validate() {
66 | assertEquals(result, validator.validate(text))
67 | }
68 |
69 | @Test
70 | fun validateAsCompletable() {
71 | if (errorMessage == null) {
72 | validator.validateAsCompletable(context, text).test().assertNoErrors().assertComplete()
73 | } else {
74 | validator.validateAsCompletable(context, text).test().assertError { it ->
75 | it.message == errorMessage
76 | }
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/library/src/test/java/co/kyash/vtl/validators/NumberOnlyValidatorTest.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import co.kyash.vtl.testing.RxImmediateSchedulerRule
5 | import junit.framework.Assert.assertEquals
6 | import org.junit.Before
7 | import org.junit.Rule
8 | import org.junit.Test
9 | import org.junit.runner.RunWith
10 | import org.robolectric.ParameterizedRobolectricTestRunner
11 | import org.robolectric.RuntimeEnvironment
12 |
13 | @Suppress("unused")
14 | @RunWith(ParameterizedRobolectricTestRunner::class)
15 | class NumberOnlyValidatorTest(
16 | private val text: String?,
17 | private val result: Boolean,
18 | private val errorMessage: String?
19 | ) {
20 |
21 | companion object {
22 | private val ERROR_MESSAGE = "This contains non-hiragana characters"
23 |
24 | @JvmStatic
25 | @ParameterizedRobolectricTestRunner.Parameters
26 | fun data(): List> {
27 | return listOf(
28 | arrayOf("a", false, ERROR_MESSAGE),
29 | arrayOf("あ", false, ERROR_MESSAGE),
30 | arrayOf("阿", false, ERROR_MESSAGE),
31 | arrayOf("1阿", false, ERROR_MESSAGE),
32 | arrayOf(null, true, null),
33 | arrayOf("", true, null),
34 | arrayOf("1234567890", true, null)
35 | )
36 | }
37 | }
38 |
39 | @get:Rule
40 | val rxImmediateSchedulerRule = RxImmediateSchedulerRule()
41 |
42 | private lateinit var subject: VtlValidator
43 |
44 | private val context: Context = RuntimeEnvironment.application
45 |
46 | @Before
47 | @Throws(Exception::class)
48 | fun setUp() {
49 | subject = NumberOnlyValidator(ERROR_MESSAGE)
50 | }
51 |
52 | @Test
53 | fun validate() {
54 | assertEquals(result, subject.validate(text))
55 | }
56 |
57 | @Test
58 | fun validateAsCompletable() {
59 | if (errorMessage == null) {
60 | subject.validateAsCompletable(context, text).test().assertNoErrors().assertComplete()
61 | } else {
62 | subject.validateAsCompletable(context, text).test().assertError { it ->
63 | it.message == errorMessage
64 | }
65 | }
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/library/src/test/java/co/kyash/vtl/validators/RequiredValidatorTest.kt:
--------------------------------------------------------------------------------
1 | package co.kyash.vtl.validators
2 |
3 | import android.content.Context
4 | import co.kyash.vtl.testing.RxImmediateSchedulerRule
5 | import junit.framework.Assert.assertEquals
6 | import org.junit.Before
7 | import org.junit.Rule
8 | import org.junit.Test
9 | import org.junit.runner.RunWith
10 | import org.robolectric.ParameterizedRobolectricTestRunner
11 | import org.robolectric.RuntimeEnvironment
12 |
13 | @Suppress("unused")
14 | @RunWith(ParameterizedRobolectricTestRunner::class)
15 | class RequiredValidatorTest(
16 | private val text: String?,
17 | private val trim: Boolean,
18 | private val result: Boolean,
19 | private val errorMessage: String?
20 | ) {
21 |
22 | companion object {
23 | private val ERROR_MESSAGE = "This field is required"
24 |
25 | @JvmStatic
26 | @ParameterizedRobolectricTestRunner.Parameters
27 | fun data(): List> {
28 | return listOf(
29 | // Failure
30 | arrayOf(null, true, false, ERROR_MESSAGE),
31 | arrayOf("", true, false, ERROR_MESSAGE),
32 | arrayOf(" ", true, false, ERROR_MESSAGE),
33 | arrayOf(" ", true, false, ERROR_MESSAGE),
34 |
35 | // Success
36 | arrayOf(" ", false, true, null),
37 | arrayOf(" ", false, true, null),
38 | arrayOf("konifar", true, true, null)
39 | )
40 | }
41 | }
42 |
43 | @get:Rule
44 | val rxImmediateSchedulerRule = RxImmediateSchedulerRule()
45 |
46 | private lateinit var subject: VtlValidator
47 |
48 | private val context: Context = RuntimeEnvironment.application
49 |
50 | @Before
51 | @Throws(Exception::class)
52 | fun setUp() {
53 | subject = RequiredValidator(ERROR_MESSAGE, trim)
54 | }
55 |
56 | @Test
57 | fun validate() {
58 | assertEquals(result, subject.validate(text))
59 | }
60 |
61 | @Test
62 | fun validateAsCompletable() {
63 | if (errorMessage == null) {
64 | subject.validateAsCompletable(context, text).test().assertNoErrors().assertComplete()
65 | } else {
66 | subject.validateAsCompletable(context, text).test().assertError { it ->
67 | it.message == errorMessage
68 | }
69 | }
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/library/src/test/resources/robolectric.properties:
--------------------------------------------------------------------------------
1 | constants=co.kyash.vtl.BuildConfig
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':example', ':library'
2 |
--------------------------------------------------------------------------------
/versions.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | versions = [
3 | compileSdk : 26,
4 | buildTools : "27.0.3",
5 | minSdk : 19,
6 | targetSdk : 26,
7 | gradleBuildTool : "3.1.0",
8 | mavenGradle : "2.0",
9 | kotlin : "1.2.30",
10 | ktlint : "0.14.0",
11 | ktlintGradle : "3.0.0",
12 | fabricGradleTool: "1.25.1",
13 | supportLibrary : "27.1.1",
14 | espresso : "3.0.1",
15 | retrofit : "2.3.0",
16 | stetho : "1.5.0",
17 | kotshi : "0.3.0-beta1",
18 | ]
19 |
20 | depends = [
21 | kotlin : [
22 | stdlib: "org.jetbrains.kotlin:kotlin-stdlib-jre7:$versions.kotlin",
23 | ],
24 |
25 | //==================== Support Library ====================
26 | support : [
27 | appcompat: "com.android.support:appcompat-v7:$versions.supportLibrary",
28 | design : "com.android.support:design:$versions.supportLibrary",
29 | cardview : "com.android.support:cardview-v7:$versions.supportLibrary",
30 | ],
31 |
32 | crashlytics : "com.crashlytics.sdk.android:crashlytics:2.8.0@aar",
33 |
34 | //==================== Network ====================
35 | retrofit : [
36 | core : "com.squareup.retrofit2:retrofit:$versions.retrofit",
37 | converterMoshi: "com.squareup.retrofit2:converter-moshi:$versions.retrofit",
38 | adapterRxJava2: "com.squareup.retrofit2:adapter-rxjava2:$versions.retrofit",
39 | ],
40 |
41 | //==================== Structure ====================
42 | kotshi : [
43 | api : "se.ansman.kotshi:api:$versions.kotshi",
44 | compiler: "se.ansman.kotshi:compiler:$versions.kotshi",
45 | ],
46 | rxjava2 : [
47 | core : "io.reactivex.rxjava2:rxjava:2.1.8",
48 | android: "io.reactivex.rxjava2:rxandroid:2.0.1",
49 | kotlin : "io.reactivex.rxjava2:rxkotlin:2.2.0",
50 | ],
51 | binding : [
52 | compiler: "com.android.databinding:compiler:3.1.0",
53 | ],
54 |
55 | //==================== Debug ====================
56 | stetho : [
57 | core : "com.facebook.stetho:stetho:$versions.stetho",
58 | okhttp3: "com.facebook.stetho:stetho-okhttp3:$versions.stetho",
59 | ],
60 |
61 | //==================== Test ====================
62 | junit : "junit:junit:4.12",
63 | mockitoKotlin: "com.nhaarman:mockito-kotlin:1.5.0",
64 | robolectric : [
65 | core: "org.robolectric:robolectric:3.5.1",
66 | ],
67 | supporttest : [
68 | runner : "com.android.support.test:runner:1.0.1",
69 | espresso: "com.android.support.test.espresso:espresso-core:3.0.1"
70 | ],
71 | espresso : [
72 | core : "com.android.support.test.espresso:espresso-core:$versions.espresso",
73 | intents: "com.android.support.test.espresso:espresso-intents:$versions.espresso"
74 | ],
75 | ]
76 | }
--------------------------------------------------------------------------------