Skip to content

Commit 6c01bde

Browse files
committed
Add extension function doc and update README to add link to extension doc
1 parent bd0de22 commit 6c01bde

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

EXTENSIONS.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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
151154
Keep this repository as one of your project tracked remote.
152155

0 commit comments

Comments
 (0)