⌨️ RxJava library to fetch suggestions for keywords using Google Suggest API
APACHE-2.0 License
Version 2 supporting RxJava 2 is in development in master
branch. For version 1 with RxJava 1 support, visit v 1.0 branch
A RxJava library to fetch search suggestions backed by Google Suggest
.
If you have a content based app, this library makes it easier to show search suggestions so that your users spend less time typing the whole word.
The implementation is decoupled meaning the suggestions fetching can be used for any purpose and not only limited to search.
Library is available via jcenter()
.
jcenter()
to your project level build.gradle
file.allprojects {
repositories {
jcenter()
}
}
build.gradle
file.dependencies{
compile 'in.arunkumarsampath:suggestions:1.0.3'
}
This library is compiled with Java 8 and thus requires your project to have Java 8 compilation enabled. This was done since the old Jack compiler is deprecated in favor of improved Java 8 compiler starting from Android Studio 3.0+ and to take advantage of lamdas
and try with resources
.
If you are not using Android Studio 3.0+, follow this guide. Else if you already are, then add these lines to force compilation with Java 8.
android {
// Configure only for each module that uses Java 8
// language features (either in its source code or
// through dependencies).
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
This library provides two different ways to fetch suggestions.
Using RxSuggestion#fetch(String)
. Example: Fetch suggestions for the word Batman
:
RxSuggestions.fetch("Batman")
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(suggestions -> {
// List of suggestions here.
});
This library provides a convenient Transformer
which takes a stream of strings and converts them in their suggestions. This is very helpful if you use library such as RxBinding
with EditText
.
RxTextView.afterTextChangeEvents(searchBox)
.map(changeEvent -> changeEvent.editable().toString())
.compose(RxSuggestions.suggestionsTransformer())
.doOnNext(this::setSuggestions) // Your suggestions
.doOnError(t -> Log.e(TAG, t.toString()))
.subscribe()
Input transforming to reduce network requests is also handled by library itself so you don't have to use debounce
etc.
This feature was initially developed for use in my browser app Chromer.
If you are a developer and would like to improve this library, please consider making a pull request or create an issue so I can look into it.
Copyright 2017 Arunkumar
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.