Remove search input textview(also EditTextView) debounce to help reduce unnecessary network bandwidth waste
Switch branches/tags
Nothing to show
Clone or download
Latest commit e96df24 Nov 15, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea feat:add license Nov 15, 2018
app first commit Nov 8, 2018
gradle/wrapper first commit Nov 8, 2018
image first commit Nov 8, 2018
library first commit Nov 8, 2018
.gitignore first commit Nov 8, 2018
LICENSE feat:add license Nov 15, 2018
README.md feat:add license Nov 15, 2018
build.gradle first commit Nov 8, 2018
gradle.properties first commit Nov 8, 2018
gradlew first commit Nov 8, 2018
gradlew.bat first commit Nov 8, 2018
settings.gradle first commit Nov 8, 2018

README.md

README.md

Sug Debounce

Sometimes, we need to listen for changes in the TextView(also EditText) content, especially for some Android apps that support search, search suggestions is a very important feature that enhances the user experience. In general, Android developers prefer to use TextWatcher to listen to TextView content changes, such as follows

    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.

Getting Started

Download

Step 1. Add it in your root build.gradle at the end of repositories:

    allprojects {
        repositories {
            maven { url 'https://jitpack.io' }
        }
    }

Step 2. Add the dependency

    dependencies {
	implementation 'com.github.SmartDengg:sug-debounce:1.0.0'
    }

Useage

    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 (video)

Debounce

Debounce search suggestions

No-Debounce

No-Debounce search suggestions

How it works

Proguard

TO-DO

Found this project useful

❤️ Hope this article can help you. Support by clicking the ⭐️, or share it with people around you. ❤️

About author

Email : dengwei@lianjia.com

weibo : -小鄧子-

License

See the LICENSE file for license rights and limitations (MIT).