-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches/build_file_checksums.ser | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
| README.md | | ||
|:---| | ||
|
||
# Sug Debounce | ||
|
||
<p align="center"> | ||
<img src="image/title.png"> | ||
</p> | ||
|
||
Sometimes, we need to listen for changes in the TextView(also EditText) content, especially for some Android apps that support search, [search suggestions](https://en.wikipedia.org/wiki/Search_suggest_drop-down_list) is a very important feature that enhances the user experience. In general, | ||
Android developers prefer to use [TextWatcher](https://developer.android.com/reference/android/text/TextWatcher.html) to listen to [TextView](https://developer.android.com/reference/android/widget/TextView.html) content changes, such as follows | ||
|
||
```java | ||
textView.addTextChangedListener(new TextWatcher() { | ||
@Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { | ||
|
||
} | ||
|
||
@Override public void onTextChanged(CharSequence s, int start, int before, int count) { | ||
|
||
} | ||
|
||
@Override public void afterTextChanged(Editable s) { | ||
|
||
/*do suggestion search*/ | ||
doSearch(s.toString()); | ||
} | ||
}); | ||
``` | ||
|
||
|
||
However, there is a problem here. If you want to search for "California," you may need at least four network requests such as "c", "a", "l", "i" to get the desired suggestions list. | ||
And these asynchronous network requests may eventually show the wrong suggestion list, without any special handling. | ||
|
||
|
||
User experience! User experience! User experience! The important thing to speak three times! | ||
|
||
**We should do some debounce to avoid unnecessary network requests and avoid wasting bandwidth.** | ||
|
||
*It's similar to [javascript-debounce-function](https://davidwalsh.name/javascript-debounce-function).* | ||
|
||
|
||
## Getting Started | ||
|
||
**Download** | ||
|
||
To use this library, add this to your build.gradle file: | ||
|
||
|
||
``` | ||
allprojects { | ||
repositories { | ||
maven { url 'https://jitpack.io' } | ||
} | ||
} | ||
``` | ||
|
||
... | ||
|
||
```java | ||
dependencies { | ||
compile '' | ||
} | ||
``` | ||
|
||
**Useage** | ||
|
||
```java | ||
Debounce.onAfterTextChangedAction(textView, 300, | ||
new DebounceObserver<TextViewAfterTextChangeEvent>() { | ||
@Override public void onError(Throwable throwable) { | ||
|
||
} | ||
|
||
@Override public void onSuccess(TextViewAfterTextChangeEvent event) { | ||
|
||
/*do your search*/ | ||
doSearch(event.editable().toString()); | ||
} | ||
``` | ||
|
||
You can change the denounce `timeout`, but we recommend 300 ~ 400 ms. | ||
|
||
## Debounce VS No-Debounce | ||
|
||
|
||
**Debounce** | ||
|
||
[](https://www.youtube.com/watch?v=Pi96OY5TkPQ) | ||
|
||
**No-Debounce** | ||
|
||
[](https://www.youtube.com/watch?v=boIsA7XvHyE) | ||
|
||
|
||
## How it works | ||
|
||
<p align="center"> | ||
<img src="image/work.png"> | ||
</p> | ||
|
||
|
||
## Proguard | ||
|
||
TO-DO | ||
|
||
|
||
## Found this project useful | ||
|
||
<p align="center">:heart: Hope this article can help you. Support by clicking the :star:, or share it with people around you. :heart: </p> | ||
|
||
|
||
## About author | ||
|
||
Email : [email protected] | ||
|
||
weibo : [-小鄧子-](https://weibo.com/5367097592/profile?topnav=1&wvr=6) | ||
|
||
|
||
## License | ||
|
||
See the [LICENSE](LICENSE.md) file for license rights and limitations (MIT). | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |