RxSuggestions


Source link: https://github.com/arunkumar9t2/rxSuggestions

RxSuggestions

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.

Demo

Download

Library is available via jcenter().

  • Add jcenter() to your project level build.gradle file.
allprojects {

  repositories {

jcenter()
  
}
 
}
  • Add library dependency to module level build.gradle file.
dependencies{

  compile 'in.arunkumarsampath:suggestions:1.0.0' 
}

Project Setup

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

}
 
}

Usage

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.

Motivation

This feature was initially developed for use in my browser app Chromer.

Contributions

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.

  • Code style is Android Studio default.
  • No hungarian notation.

License

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.

Resources

FireTweet is an Android app powered by Lantern that gives direct unblocked access to Twitter from anywhere in the world.

This is a Scrollable App Bar for Android.

Fixed viewport image cropping library for Android with built-in support for Picasso or Glide.

Permiso is an Android library that makes requesting runtime permissions a whole lot easier.

This is a wrapper of IP-API for Android platform using Volley.

This is a simple library that resolves U.S. postal zip codes to the appropriate City/State.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes