Simple Network Library

Additional

Language
Java
Version
N/A
Created
Jun 19, 2017
Updated
Jul 23, 2017 (Retired)
Owner
Ahmed Adel (ahmedadeltito)
Contributor
Ahmed Adel (ahmedadeltito)
1
Activity
Badge
Generate
Download
Source code
APK file

Advertising

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.


and after this, add the Simple Library Network dependency:

 dependencies {
         compile 'com.github.ahmed-adel-said:SimpleNetworkLibrary:-SNAPSHOT'
 }
  1. 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);
  1. To fire the request after initializing it:
networkRequest.fireRequest();
  1. 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);
  1. 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) {

                    }
                });
  1. 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) {
                            
                        }
                    })