File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Useful Extension Functions
2+ ## View
3+ ``` kotlin
4+ // Prevent multiple/duplicate click
5+ View .debounceClick() { .. . }
6+
7+ // Visibility
8+ View .visible()
9+ View .invisible()
10+ View .gone()
11+ View .showIf { .. . }
12+ View .hideIf { .. . }
13+ View .goneIf { .. . }
14+
15+ // Keyboard
16+ View .showKeyboard()
17+ View .hideKeyboard()
18+
19+ // Dimension
20+ View .px2dp()
21+ View .dp2px()
22+ View .px2sp()
23+ View .sp2px()
24+
25+ // Resources
26+ View .getColor(R .color.colorPrimary)
27+ View .getDrawable(R .drawable.ic_launcher)
28+ ```
29+
30+ ## EditText
31+ ``` kotlin
32+ EditText .textChanged { s -> .. . }
33+ EditText .textChanged().doOnNext { s -> .. . }.subscribe()
34+ EditText .validate(errorMessage = " The name should not be empty" ) { ! it.isNullOrBlank() }
35+ EditText .validateEmail { .. . }
36+ EditText .validateEmail(" It's not valid email" )
37+ EditText .showPassword()
38+ EditText .hidePassword()
39+ ```
40+
41+ ## TextView
42+ ``` kotlin
43+ // Set view gone while text is null or empty.
44+ TextView .setTextWithExistence(" 1234" )
45+
46+ // Set view invislble while text is null or empty.
47+ TextView .setTextWithVisibility(" 5678" )
48+ ```
49+
50+ ## String
51+ ``` kotlin
52+ String? .isValidEmail(): Boolean
53+ ```
54+
Original file line number Diff line number Diff line change @@ -147,6 +147,9 @@ fun Project.importCommonDependencies() {
147147* [ Timber] ( https://github.com/JakeWharton/timber ) , for logging.
148148* [ Epoxy] ( https://github.com/airbnb/epoxy ) , for RecyclerView complex view layout.
149149
150+ ## Useful Extensions
151+ * See [ Extension Functions.] ( ./EXTENSIONS.md )
152+
150153## How to Update
151154Keep this repository as one of your project tracked remote.
152155
You can’t perform that action at this time.
0 commit comments