Network

Network library with the ability to induce dependency on the request queues. Plus operations are seperated from requests, you can do multiple requests and time consuming codes in a single operation.

License

License

Categories

Categories

Net
GroupId

GroupId

com.yashoid
ArtifactId

ArtifactId

network
Last Version

Last Version

1.2.1
Release Date

Release Date

Type

Type

aar
Description

Description

Network
Network library with the ability to induce dependency on the request queues. Plus operations are seperated from requests, you can do multiple requests and time consuming codes in a single operation.
Project URL

Project URL

https://github.com/yasharpm/Network
Source Code Management

Source Code Management

https://github.com/yasharpm/Network

Download network

How to add to project

<!-- https://jarcasting.com/artifacts/com.yashoid/network/ -->
<dependency>
    <groupId>com.yashoid</groupId>
    <artifactId>network</artifactId>
    <version>1.2.1</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.yashoid/network/
implementation 'com.yashoid:network:1.2.1'
// https://jarcasting.com/artifacts/com.yashoid/network/
implementation ("com.yashoid:network:1.2.1")
'com.yashoid:network:aar:1.2.1'
<dependency org="com.yashoid" name="network" rev="1.2.1">
  <artifact name="network" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.yashoid', module='network', version='1.2.1')
)
libraryDependencies += "com.yashoid" % "network" % "1.2.1"
[com.yashoid/network "1.2.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Network

  • Network library with the ability to induce dependency on the request queues.
  • Operations are seperated from requests, you can do multiple requests and time consuming codes in a single operation.
  • You can use this library for any type of time consuming operations and not necessarily network requests.

There are two main classes: NetworkOperaion and NetworkOperator. You get the singleton instance of NetworkOperator and then post NetworkOperations on it to execute them.

Usage

Add the dependency:

dependencies {
	compile 'com.yashoid:network:2.1.1'
}

Following description is out dated. And will be updated soon.

Network Operator

There are three queues for running the operations.
  • UI content Is the queue with the most importance. As long as there is some operation on this queue. No other operations will be executed.

  • User action This queue has next level of importance. As long as there is some operation on this queue. No background operation will be executed.

  • Background Operations on this queue will only be executed if there are no other operations left to be execuuted.

If some operation is being executed on a lower importance queue and some new operation is sent to a more important queue, the new operation will be executed in parallel with the current operation(s). After the less important operation(s) is finished, the less important queue(s) will wait for the more important one to get free.

Network Operation

Each operation has a type that identifies the operation's queue and a priority. Operations with higher priority in a queue will be executed before operations with a lower priority.

Network operations structure is very similar to an AsyncTask. operate() will be called on a thread and onOperationFinished() will be called on the Main Thread. publishProgress and onProgressUpdate() are exactly similar to AsyncTask.

Network Request

There are subclasses of NetworkRequest class to perform API calls. Using network requests is optional.

Available network requests

  • JsonObjectRequest
  • JsonArrayRequest
  • JsonReaderRequest
  • FileRequest
  • StringRequest

There are useful methods to set the body for the request. Using them you can set different types of objects as the body that includes: JsonObject, JsonArray, String, InputStream, File. Calling setBody() will automatically change the request method to POST.

In addition you can set the method of the request which you can use to set non-standard methods (HttpUrlRequest normally throws a runtime exception). Also there is a method to directly access the underlying HttpUrlRequest for other uses like setting request headers.

Attention Getting request's response code is valid only after you have executed the request. In case you are using JsonReaderRequest remember to call disconnect() after you have finished using the JsonReader. For other requests disconnect is called by default.

Versions

Version
1.2.1
1.2.0
1.1.0
1.0.2
1.0.1
1.0.0