Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.asifmujteba:EasyVolley:'
}
dependencies {
implementation("com.github.asifmujteba:EasyVolley:")
}
<dependency>
<groupId>com.github.asifmujteba</groupId>
<artifactId>EasyVolley</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.asifmujteba" % "EasyVolley" % ""
:dependencies [[com.github.asifmujteba/EasyVolley ""]]
Android Volley Wrapper library to make networking easy, flexible and better.
<h2>Purpose</h2> 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. <h2>Installation</h2>GRADLE
dependencies {
compile 'com.github.asifmujteba:easyvolley:0.9.+'
}
<h2>Usage</h2>
A Sample is already included to demonstrate the usage.
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
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