Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SmartDengg committed Nov 8, 2018
0 parents commit 2277393
Show file tree
Hide file tree
Showing 66 changed files with 1,943 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
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
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/dictionaries/SmartDengg.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions .idea/markdown-navigator.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/markdown-navigator/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 125 additions & 0 deletions README.md
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**

[![Debounce search suggestions](http://img.youtube.com/vi/Pi96OY5TkPQ/0.jpg)](https://www.youtube.com/watch?v=Pi96OY5TkPQ)

**No-Debounce**

[![No-Debounce search suggestions](http://img.youtube.com/vi/boIsA7XvHyE/0.jpg)](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).



1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Loading

0 comments on commit 2277393

Please sign in to comment.