Simple Network Library
Android Simple Network Library for HTTP and Image Requests with cool features implemented with Simple Demo using some Material Design UI Elements.
Most Common Library Features:
- Making HTTP Requests with different Request Types like GET, POST, PUT,DELETE and PATCH.
- Making HTTP Requests with different Content Types like JSON and XML.
- Caching HTTP Request on Memory.
- Handling Multiple Requests in a Thread Safe Mechanism.
- Making Image Requests Synchronous and Asynchronous with helpful observers to handle most cases.
- Caching Image Bitmaps on Memory.
- Creating a Test Case for NetworkRequest class using JUnit testing framework.
Most Common Simple Demo Application Features:
- Using some Material Design UI Elements like CoordinatorLayout, CardView, AppBarLayout, SwipeRefreshLayout, RecyclerView and Transition.
- Handling Pull To Refresh and Load More mechanism.
User Documentation :
- For simple integration all you have to do is to add the following command in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
and after this, add the Simple Library Network dependency:
dependencies {
compile 'com.github.ahmed-adel-said:SimpleNetworkLibrary:-SNAPSHOT'
}
- To initialize HTTP request:
networkRequest = NetworkRequest.getInstance(context)
// base url
.baseUrl(String baseUrl)
// endpoint
.endpoint(String endpoint)
// request types: GET, POST, PUT, DELETE and PATCH.
.requestType(RequestType requestType)
// content types: JSON and XML
.contentType(ContentType contentType)
// decode url if the url has spaces like %20%
.decodedUrl(boolean decodedUrl)
// add params to your request
.params(Map<String, String> params)
// add headers to your request
.headers(Map<String, String> headers)
// add json body as a body to your POST, PUT, DELETE and PATCH requests
.bodyJsonObject(JSONObject bodyJsonObject)
// OnNetworkRequestResponseListener is a listener that used to observe the success and error response
.onNetworkRequestResponseListener(OnNetworkRequestResponseListener onNetworkRequestResponseListener);
- To fire the request after initializing it:
networkRequest.fireRequest();
- To initialize image HTTP request and load the required image:
userImageView.setImageUrl(
// image url
String url,
// fall back image resource if the image url is not correct and there is an error occurred while downloading the image
Integer fallbackResource,
// loading image resource that is appeared during the download of the image
Integer loadingResource,
// OnCompleteImageListener is a listener that used to observe the success downloaded bitmap
OnCompleteImageListener onCompleteImageListener);
- OnNetworkRequestResponseListener is a observer that used to handle the response of network request calls:
OnNetworkRequestResponseListener() {
@Override
public void onSuccessResponse(String response, ContentType contentType, boolean isCached) {
}
@Override
public void onErrorResponse(String error, String message, int code) {
}
});
- OnCompleteImageListener is a listener that helps the developer to get the image bitmap if he/she makes an only image single request not a multiple image requests as in the recycler view adapter as an example.:
OnCompleteImageListener() {
@Override
public void onComplete(Bitmap bitmap) {
}
})