EasyVolley


Source link: https://github.com/asifmujteba/EasyVolley

EasyVolley

Android Volley Wrapper library to make networking easy, flexible and better.

Purpose

In 2013 google introduced Volley: Easy & Fast Networking library for Android. Since then I fell in love with Volley. It is indeed fast, easy and highly customizable But the approach to integrate it within a project for example, loading images, extending requests, customizing requests etc all seemed quite confusing to me. I always thought of how can we make it easy to use and easy to custimze P.S. also adding some new features would be nice :). This thought became the inspiration behind EasyVolley.

Installation

GRADLE

dependencies {

compile 'com.github.asifmujteba:easyvolley:0.9.+' 
}
 

Usage

A Sample is already included to demonstrate the usage.
  • Initialize and do global configurations using EasyVolley class once on application start and dispose in the end, preferably by extending Applcation class.
EasyVolley.initialize(getApplicationContext());
 
EasyVolley.dispose();
  

Performing Http Requests

EasyVolley.withGlobalQueue()

  .load(URL_COMES_HERE)

  .asJsonObject()

  .setSubscriber(OBJECT_REFERENCE_HERE) // Once this object unsubscribes the request is cancelled and no callbacks are called

  .setCallback(new ASFRequestListener<JsonObject>() {

@Override

public void onSuccess(JsonObject response) {

 // DO_SOMETHING_HERE

}

@Override

public void onFailure(Exception e) {

 // SO_SOMETHING_HERE

}

  
}
)

  .start();
 

Subscription Mechanism

Call .setSubscriber(OBJECT_REFERENCE_HERE) on a request to attach it against the object passed. i-e, Pass the activity here.

And call EasyVolley.unSubscribe(OBJECT_REFERENCE_HERE); when the request is longer needed i-e, In onDestroy() method of Activity.

This will ensure that requests are cancelled and callbacks are not called after the activity has been destroyed.

Performing Image Requests

  • Ability to set callbacks on image load or directly load it into an ImageView
  • Ability to set image width, height and different scale types.
EasyVolley.withGlobalQueue()

  .load(url)

  .asBitmap()

  .setMaxWidth(WIDTH_HERE) // OPTIONAL

  .setMaxHeight(HEIGHT_HERE) // OPTIONAL

  .setScaleType(SCALE_TYPE_HERE) // OPTIONAL

  .setCallback(...) // OPTIONAL

  .into(IMAGE_VIEW_HERE) // OPTIONAL

  .start();
 

Managing Request Queues

By default EasyVolley creates a global Request Queue to process all requests. We can also create new request queues if needed.

EasyVolley.withNewQueue(getApplicationContext()) 

Setting Headers

EasyVolley.withGlobalQueue()

  .load(URL_COMES_HERE)

  .addHeader(KEY1_HERE, VALUE1_HERE)

  .addHeader(KEY2_HERE, VALUE2_HERE)

  ... 

Adding Get/Post Parameters

EasyVolley.withGlobalQueue()

  .load(URL_COMES_HERE)

  .addParam(KEY1_HERE, VALUE1_HERE)

  .addParam(KEY2_HERE, VALUE2_HERE)

  ... 

Request Caching

  • Cache uses least recently used technique to limit memory size.
  • By defaut all requests are cached in memory and disk as well. (caching http requests directly in memory in addition to images really fastens the User experience especially for fast scrolling scenarios)
  • Http headers, Get parameters, Post body digest are all taken into consideration for effiecient caching

Coming Soon / TODO

- Schedule Callbacks on Main Thread always. - Respecting Http Cache-Control and Expiry Headers for memory Cache as well. - Auto scale images to fit ImageViews by inspecting ImageView attributes - Treat same image requests with different scale sizes differently. - Ability to Add http headers and parameters to all requests globally and for a specfic Request Queue. - Ability to set Image loading configurations globally - Loading and caching images from Content Providers and Local disk - Multipart Http Requests - Write Wrappers for upload/Download tasks - Batch Requests - By default set low priority for Image Requests - Prioritize certain requests

Author

Asif Mujteba, [email protected] Twitter: @asifmujteba

License

This library is available under the Apache v2 license. See the LICENSE file for more info.

Resources

ConnectBot is a Secure Shell client for the Android platform. Its ultimate goal is to create a secure connection through which you can use a shell on a remote machine and transfer files back and forth to your phone.

Provides a logging wrapper around a WebViewClient, in order to figure out what is going on.

This happens by creating a DebugWebViewClient which logs events and passes them to an enclosed WebViewClient.

An Android Parallax ViewPager.

The advantage of this library is that the UI components within the adapter view can be individually moved at different speeds.

Basic implementation of Android Recycler View purely written in Kotlin.

The ultimate developer guide to Android application linking methods.

Android library that makes it easy to create floating UI elements.

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