Listen the progress of downloading and uploading in Okhttp (compatible Retrofit and Glide).

Overview

Introduction

ProgressManager is a single line of code that monitors the upload and download progress of all web links in your App, including Glide’s image loading progress. Similar to EventBus, you can put multiple listeners anywhere in your App to the Url Address is registered to the framework as an identifier. When there is download or upload action at this Url address, the framework will actively call all listeners registered with this Url address to achieve synchronous update of multiple modules.

The idea and implementation of the framework can be seen in this article

Feature

  • Simple to use, just one line of code to achieve progress monitoring.
  • Multi-platform support, support Okhttp, Retrofit, Glide, using Okhttp native Api, there is no compatibility problem.
  • Low coupling. There is no direct or indirect correlation between the actual requestor and the receiving end of progress, that is, progress information can be received anywhere in App.
  • It is not invasive, you do not need to change the code that was uploaded or downloaded before using this framework, that is, using or not using this framework does not affect the original code.
  • Multi-endpoint synchronization, the upload or download progress of the same data source can be specified by multiple receivers, eliminating the need to use EventBus to achieve multiple port synchronization update progress.
  • Automatic listener management, less manual logout listener trouble.
  • Default running in the main layer, less trouble switching threads.
  • A lightweight framework that does not contain any third party libraries and is extremely small.

Download

The compile 'me. Jessyan: progressmanager: 1.3.0'Copy the code

Usage

Step 1

/ / build OkHttpClient, will OkHttpClient. Builder () the incoming with () method, initialize configuration OkHttpClient = ProgressManager. GetInstance () with (new  OkHttpClient.Builder()) .build();Copy the code

Step 2

/ / Glide. Download the listening ProgressManager getInstance () addResponseListener (IMAGE_URL, getGlideListener ()); / / Okhttp Retofit download monitor ProgressManager getInstance (). AddResponseListener (DOWNLOAD_URL, getDownloadListener ()); / / Okhttp Retofit upload to monitor ProgressManager getInstance () addRequestLisenter (UPLOAD_URL, getUploadListener ());Copy the code

ProGuard

 -keep class me.jessyan.progressmanager.** { *; }
 -keep interface me.jessyan.progressmanager.** { *; }
Copy the code

About Me

License

 Copyright 2017, jessyan

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
Copy the code