Bläddra i källkod

提交1.1.8版本,优化下载方法,下载返回改成eventbus

yanyi 5 år sedan
förälder
incheckning
d7cbf8553f

+ 2 - 1
README.md

@@ -4,9 +4,10 @@
 
 module 下添加
 
-`implementation 'com.yanyi.benyanyi:okhttplib:1.1.7'` 
+`implementation 'com.yanyi.benyanyi:okhttplib:1.1.8'` 
   
 ### 更新记录
+* 2019-08-19(1.1.8) 
 * 2019-08-16(1.1.7) 优化下载方法,添加下载暂停方法
 * 2019-08-15(1.1.6) 优化下载方法,添加下载文件后缀添加方法
 * 2019-08-13(1.1.5) 重构代码,优化方法,使调用更简洁明了

+ 3 - 1
app/build.gradle

@@ -34,8 +34,10 @@ dependencies {
     androidTestImplementation 'com.android.support.test:runner:1.0.2'
     androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
     implementation project(':okhttplib')
-    implementation 'com.yanyi.benyanyi:loglib:1.0.3'
+    implementation 'com.yanyi.benyanyi:loglib:1.0.1'
     implementation 'com.yanyi.benyanyi:permissionlib:1.0.9'
     implementation 'io.reactivex.rxjava2:rxjava:2.2.10'
     implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
+    implementation 'org.greenrobot:eventbus:3.1.1'
+
 }

+ 8 - 2
app/src/main/java/com/mylove/okhttp/AppContext.java

@@ -3,7 +3,7 @@ package com.mylove.okhttp;
 import android.app.Application;
 import android.content.Context;
 
-import com.benyanyi.loglib.Jlog;
+import com.mylove.loglib.JLog;
 
 /**
  * @author myLove
@@ -15,11 +15,17 @@ import com.benyanyi.loglib.Jlog;
 public class AppContext extends Application {
 
     public static Context mContext;
+    private static DownloadManager downloadManager;
 
     @Override
     public void onCreate() {
         super.onCreate();
-        Jlog.init(true);
+        JLog.init(true);
         mContext = this;
+        downloadManager = DownloadManager.getInstance(mContext);
+    }
+
+    public static DownloadManager getDownloadManager() {
+        return downloadManager;
     }
 }

+ 81 - 58
app/src/main/java/com/mylove/okhttp/DownloadActivity.java

@@ -8,10 +8,12 @@ import android.view.View;
 import android.widget.Button;
 import android.widget.ProgressBar;
 
-import com.benyanyi.loglib.Jlog;
 import com.benyanyi.okhttp.OkHttpUtil;
 import com.benyanyi.okhttp.download.DownloadInfo;
-import com.benyanyi.okhttp.listener.OnDownLoadObserver;
+
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+import org.greenrobot.eventbus.ThreadMode;
 
 /**
  * @author BenYanYi
@@ -23,6 +25,7 @@ public class DownloadActivity extends AppCompatActivity implements View.OnClickL
     private Button downloadBtn1, downloadBtn2, downloadBtn3;
     private Button cancelBtn1, cancelBtn2, cancelBtn3;
     private ProgressBar progress1, progress2, progress3;
+    String url2 = "https://go.ziwanyouxi.com/ad/=ITOwgjM/28092";
 
     private Context mContext;
 
@@ -31,6 +34,7 @@ public class DownloadActivity extends AppCompatActivity implements View.OnClickL
         super.onCreate(savedInstanceState);
         setContentView(R.layout.act_download);
         mContext = this;
+        EventBus.getDefault().register(this);
         downloadBtn1 = bindView(R.id.main_btn_down1);
         downloadBtn2 = bindView(R.id.main_btn_down2);
         downloadBtn3 = bindView(R.id.main_btn_down3);
@@ -55,67 +59,70 @@ public class DownloadActivity extends AppCompatActivity implements View.OnClickL
     @Override
     public void onClick(View v) {
         String url1 = "http://www.yanyi.red/bluetooth/ios.pdf";
-        String url2 = "https://go.ziwanyouxi.com/ad/=ITOwgjM/28092";
         String url3 = "https://go.ziwanyouxi.com/ad/=MDO3kjM/29783";
         switch (v.getId()) {
             case R.id.main_btn_down1:
-                OkHttpUtil.getInstance(mContext).url(url1).download().start(new OnDownLoadObserver() {
-                    @Override
-                    public void onNext(DownloadInfo downloadInfo) {
-                        super.onNext(downloadInfo);
-                        Jlog.v(downloadInfo.getProgress());
-                        progress1.setMax((int) downloadInfo.getTotal());
-                        progress1.setProgress((int) downloadInfo.getProgress());
-                    }
-
-                    @Override
-                    public void onComplete() {
-
-                    }
-                });
-                break;
-            case R.id.main_btn_down2:
-                OkHttpUtil.getInstance(mContext).url(url2).download(".apk").start(new OnDownLoadObserver() {
-                    @Override
-                    public void onNext(DownloadInfo downloadInfo) {
-                        Jlog.v(downloadInfo.getProgress());
-                        progress2.setMax((int) downloadInfo.getTotal());
-                        progress2.setProgress((int) downloadInfo.getProgress());
-                    }
-
-                    @Override
-                    public void onError(Throwable e) {
-
-                    }
-
-                    @Override
-                    public void onComplete() {
-
-                    }
-                });
-                break;
-            case R.id.main_btn_down3:
-                OkHttpUtil.getInstance(mContext).url(url3).download(".apk").start(new OnDownLoadObserver() {
-                    @Override
-                    public void onNext(DownloadInfo downloadInfo) {
-                        Jlog.v(downloadInfo.getProgress());
-                        progress3.setMax((int) downloadInfo.getTotal());
-                        progress3.setProgress((int) downloadInfo.getProgress());
-                    }
-
-                    @Override
-                    public void onError(Throwable e) {
-
-                    }
-
-                    @Override
-                    public void onComplete() {
-
-                    }
-                });
+                AppContext.getDownloadManager().start(url2);
                 break;
+//            case R.id.main_btn_down1:
+//                OkHttpUtil.getInstance(mContext).url(url1).download().start(new OnDownLoadObserver() {
+//                    @Override
+//                    public void onNext(DownloadInfo downloadInfo) {
+//                        super.onNext(downloadInfo);
+//                        JLog.v(downloadInfo.getProgress());
+//                        progress1.setMax((int) downloadInfo.getTotal());
+//                        progress1.setProgress((int) downloadInfo.getProgress());
+//                    }
+//
+//                    @Override
+//                    public void onComplete() {
+//
+//                    }
+//                });
+//                break;
+//            case R.id.main_btn_down2:
+//                OkHttpUtil.getInstance(mContext).url(url2).download(".apk").start(new OnDownLoadObserver() {
+//                    @Override
+//                    public void onNext(DownloadInfo downloadInfo) {
+//                        JLog.v(downloadInfo.getProgress());
+//                        progress2.setMax((int) downloadInfo.getTotal());
+//                        progress2.setProgress((int) downloadInfo.getProgress());
+//                    }
+//
+//                    @Override
+//                    public void onError(Throwable e) {
+//
+//                    }
+//
+//                    @Override
+//                    public void onComplete() {
+//
+//                    }
+//                });
+//                break;
+//            case R.id.main_btn_down3:
+//                OkHttpUtil.getInstance(mContext).url(url3).download(".apk").start(new OnDownLoadObserver() {
+//                    @Override
+//                    public void onNext(DownloadInfo downloadInfo) {
+//                        JLog.v(downloadInfo.getProgress());
+//                        progress3.setMax((int) downloadInfo.getTotal());
+//                        progress3.setProgress((int) downloadInfo.getProgress());
+//                    }
+//
+//                    @Override
+//                    public void onError(Throwable e) {
+//
+//                    }
+//
+//                    @Override
+//                    public void onComplete() {
+//
+//                    }
+//                });
+//                break;
             case R.id.main_btn_cancel1:
-                OkHttpUtil.getInstance(mContext).url(url1).download().cancel();
+                AppContext.getDownloadManager().cancel(url2);
+//                OkHttpUtil.getInstance(mContext).url(url1).download().cancel();
                 break;
             case R.id.main_btn_cancel2:
                 OkHttpUtil.getInstance(mContext).url(url2).download().pause();
@@ -128,9 +135,25 @@ public class DownloadActivity extends AppCompatActivity implements View.OnClickL
         }
     }
 
+    @Subscribe(threadMode = ThreadMode.MAIN)
+    public void download(DownloadInfo downloadInfo) {
+        if (downloadInfo != null) {
+            if (downloadInfo.getUrl().equals(url2)) {
+                progress1.setMax((int) downloadInfo.getTotal());
+                progress1.setProgress((int) downloadInfo.getProgress());
+            }
+        }
+    }
+
     private <T extends View> T bindView(@IdRes int id) {
         View viewById = findViewById(id);
         return (T) viewById;
     }
 
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+        EventBus.getDefault().unregister(this);
+    }
 }

+ 37 - 0
app/src/main/java/com/mylove/okhttp/DownloadManager.java

@@ -0,0 +1,37 @@
+package com.mylove.okhttp;
+
+import android.content.Context;
+
+import com.benyanyi.okhttp.OkHttpUtil;
+
+/**
+ * @author YanYi
+ * @date 2019-08-19 11:15
+ * @email ben@yanyi.red
+ * @overview
+ */
+public class DownloadManager {
+
+    private static DownloadManager instance;
+    private Context context;
+
+    public static DownloadManager getInstance(Context mContext) {
+        if (instance == null) {
+            instance = new DownloadManager(mContext);
+        }
+        return instance;
+    }
+
+    private DownloadManager(Context context) {
+        this.context = context;
+    }
+
+    public void start(String url) {
+        OkHttpUtil.getInstance(context).url(url).download(".apk").start();
+    }
+
+    public void cancel(String url) {
+        OkHttpUtil.getInstance(context).url(url).download().cancel();
+    }
+
+}

+ 21 - 16
app/src/main/java/com/mylove/okhttp/MainActivity.java

@@ -4,14 +4,15 @@ import android.content.Intent;
 import android.os.Bundle;
 import android.support.annotation.Nullable;
 import android.support.v7.app.AppCompatActivity;
+import android.view.View;
 
-import com.benyanyi.loglib.Jlog;
 import com.benyanyi.okhttp.OkHttpUtil;
 import com.benyanyi.okhttp.listener.OnOkHttpListener;
 import com.benyanyi.permissionlib.PermissionCallBack;
 import com.benyanyi.permissionlib.PermissionHelper;
 import com.benyanyi.permissionlib.PermissionType;
 import com.benyanyi.permissionlib.msg.FailureMsg;
+import com.mylove.loglib.JLog;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -32,6 +33,23 @@ public class MainActivity extends AppCompatActivity {
 //        setContentView(R.layout.notification_contentview);
         setContentView(R.layout.activity_main);
         init();
+
+//        permissionHelper = new PermissionHelper(this, strings);
+//        permissionHelper.hasPermission(new PermissionHelper.OnPermissionListener() {
+//            @Override
+//            public void onAllPermissionSuccess() {
+////                init();
+//                downloadAPK();
+//            }
+//
+//            @Override
+//            public void onAllPermissionFailure() {
+//
+//            }
+//        });
+    }
+
+    public void onClick(View view){
         String[] strings = new String[]{PermissionType.STORAGE};
         PermissionHelper.getInstance(this).hasPermission(1, new PermissionCallBack() {
             @Override
@@ -49,19 +67,6 @@ public class MainActivity extends AppCompatActivity {
 
             }
         }, strings);
-//        permissionHelper = new PermissionHelper(this, strings);
-//        permissionHelper.hasPermission(new PermissionHelper.OnPermissionListener() {
-//            @Override
-//            public void onAllPermissionSuccess() {
-////                init();
-//                downloadAPK();
-//            }
-//
-//            @Override
-//            public void onAllPermissionFailure() {
-//
-//            }
-//        });
     }
 
     private void init() {
@@ -81,12 +86,12 @@ public class MainActivity extends AppCompatActivity {
 
             @Override
             public void onSuccess(Object message) {
-                Jlog.v(message);
+                JLog.v(message);
             }
 
             @Override
             public void onFailure(Throwable t) {
-                Jlog.e(t.getMessage());
+                JLog.e(t.getMessage());
             }
         });
     }

+ 10 - 2
app/src/main/res/layout/activity_main.xml

@@ -1,6 +1,14 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="vertical" android:layout_width="match_parent"
-    android:layout_height="match_parent">
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <Button
+        android:id="@+id/but"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:onClick="onClick"
+        android:text="下载" />
 
 </LinearLayout>

+ 1 - 1
okhttplib/bintrayUpload.gradle

@@ -7,7 +7,7 @@ def siteUrl = 'http://www.yanyis.space/yanyi/baseokhttp' // 项目主页。
 def gitUrl = 'http://www.yanyis.space/yanyi/baseokhttp.git' // Git仓库的url。
 
 group = "com.yanyi.benyanyi"// 唯一包名,比如compile 'com.ansen.http:okhttpencapsulation:1.0.1'中的com.ansen.http就是这里配置的。
-version = "1.1.7" //项目引用的版本号,比如compile 'com.ansen.http:okhttpencapsulation:1.0.1'中的1.0.1就是这里配置的。
+version = "1.1.8" //项目引用的版本号,比如compile 'com.ansen.http:okhttpencapsulation:1.0.1'中的1.0.1就是这里配置的。
 install {
     repositories.mavenInstaller {
         // This generates POM.xml with proper parameters

+ 2 - 0
okhttplib/build.gradle

@@ -38,5 +38,7 @@ dependencies {
     implementation 'com.google.code.gson:gson:2.8.5'
     implementation 'com.squareup.retrofit2:retrofit:2.5.0'
     api files('lib/android-xml-json.jar')
+    implementation 'org.greenrobot:eventbus:3.1.1'
+
 }
 apply from: 'bintrayUpload.gradle'

+ 11 - 4
okhttplib/src/main/java/com/benyanyi/okhttp/download/DownloadCall.java

@@ -2,7 +2,6 @@ package com.benyanyi.okhttp.download;
 
 import android.content.Context;
 
-import com.benyanyi.okhttp.listener.OnDownLoadObserver;
 import com.benyanyi.okhttp.util.FormatUtil;
 
 /**
@@ -23,12 +22,20 @@ public class DownloadCall implements DownloadConfig {
         this.suffix = builder.suffix;
     }
 
+    //    @Override
+//    public void start(OnDownLoadObserver onDownLoadObserver) {
+//        if (FormatUtil.isEmpty(this.suffix)) {
+//            DownloadManager.getInstance(mContext).download(url, onDownLoadObserver);
+//        } else {
+//            DownloadManager.getInstance(mContext).download(url, suffix, onDownLoadObserver);
+//        }
+//    }
     @Override
-    public void start(OnDownLoadObserver onDownLoadObserver) {
+    public void start() {
         if (FormatUtil.isEmpty(this.suffix)) {
-            DownloadManager.getInstance(mContext).download(url, onDownLoadObserver);
+            DownloadManager.getInstance(mContext).download(url);
         } else {
-            DownloadManager.getInstance(mContext).download(url, suffix, onDownLoadObserver);
+            DownloadManager.getInstance(mContext).download(url, suffix);
         }
     }
 

+ 2 - 3
okhttplib/src/main/java/com/benyanyi/okhttp/download/DownloadConfig.java

@@ -1,7 +1,5 @@
 package com.benyanyi.okhttp.download;
 
-import com.benyanyi.okhttp.listener.OnDownLoadObserver;
-
 /**
  * @author YanYi
  * @date 2019-08-15 10:25
@@ -10,7 +8,8 @@ import com.benyanyi.okhttp.listener.OnDownLoadObserver;
  */
 public interface DownloadConfig {
 
-    void start(OnDownLoadObserver onDownLoadObserver);
+//    void start(OnDownLoadObserver onDownLoadObserver);
+    void start();
 
     void pause();
 

+ 21 - 0
okhttplib/src/main/java/com/benyanyi/okhttp/download/DownloadInfo.java

@@ -9,6 +9,17 @@ import java.io.File;
  * @overview
  */
 public class DownloadInfo {
+
+    /**
+     * 下载状态
+     */
+    public static final String DOWNLOAD_ING = "download_ing";    // 下载中
+    public static final String DOWNLOAD_PAUSE = "download_pause"; // 下载暂停
+    public static final String DOWNLOAD_WAIT = "download_wait";  // 等待下载
+    public static final String DOWNLOAD_CANCEL = "download_cancel"; // 下载取消
+    public static final String DOWNLOAD_OVER = "download_over";    // 下载结束
+    public static final String DOWNLOAD_ERROR = "download_error";  // 下载出错
+
     /**
      * 获取进度失败
      */
@@ -18,6 +29,7 @@ public class DownloadInfo {
     private long progress;
     private String fileName;
     private File file;
+    private String downloadStatus;
 
     public DownloadInfo(String url) {
         this.url = url;
@@ -59,6 +71,14 @@ public class DownloadInfo {
         this.file = file;
     }
 
+    public String getDownloadStatus() {
+        return downloadStatus;
+    }
+
+    public void setDownloadStatus(String downloadStatus) {
+        this.downloadStatus = downloadStatus;
+    }
+
     @Override
     public String toString() {
         return "DownloadInfo{" +
@@ -67,6 +87,7 @@ public class DownloadInfo {
                 ", progress=" + progress +
                 ", fileName='" + fileName + '\'' +
                 ", file=" + file +
+                ", downloadStatus='" + downloadStatus + '\'' +
                 '}';
     }
 }

+ 70 - 62
okhttplib/src/main/java/com/benyanyi/okhttp/download/DownloadManager.java

@@ -2,8 +2,6 @@ package com.benyanyi.okhttp.download;
 
 import android.content.Context;
 
-import com.benyanyi.okhttp.listener.OnDownLoadObserver;
-
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -51,7 +49,7 @@ class DownloadManager {
      * @param mContext
      * @return
      */
-    public static DownloadManager getInstance(Context mContext) {
+    static DownloadManager getInstance(Context mContext) {
         for (; ; ) {
             DownloadManager current = INSTANCE.get();
             if (current != null) {
@@ -71,76 +69,86 @@ class DownloadManager {
         this.mContext = mContext;
     }
 
+    /**
+     * 查看是否在下载任务中
+     *
+     * @param url
+     * @return
+     */
+    boolean getDownloadUrl(String url) {
+        return downCalls.containsKey(url);
+    }
+
     /**
      * 开始下载
      *
-     * @param suffix             文件名后缀
-     * @param url                下载请求的网址
-     * @param onDownLoadObserver 用来回调的接口
+     * @param suffix 文件名后缀
+     * @param url    下载请求的网址
+     *               //     * @param onDownLoadObserver 用来回调的接口
      */
-    void download(String url, String suffix, OnDownLoadObserver onDownLoadObserver) {
+    void download(String url, String suffix) {
         this.suffix = suffix;
-        this.download(url, onDownLoadObserver);
+        this.download(url);
     }
 
     /**
      * 开始下载
      *
-     * @param url                下载请求的网址
-     * @param onDownLoadObserver 用来回调的接口
+     * @param url 下载请求的网址
+     *            //     * @param onDownLoadObserver 用来回调的接口
      */
-    void download(String url, OnDownLoadObserver onDownLoadObserver) {
-        if (!downCalls.containsKey(url)) {
-            Observable.just(url)
-                    //call的map已经有了,就证明正在下载,则这次不下载
-                    .filter(new Predicate<String>() {
-                        @Override
-                        public boolean test(String s) throws Exception {
-                            return !downCalls.containsKey(s);
-                        }
-                    })
-                    .flatMap(new Function<String, ObservableSource<?>>() {
-                        @Override
-                        public ObservableSource<?> apply(String s) throws Exception {
-                            return Observable.just(createDownInfo(s));
-                        }
-                    })
-                    //检测本地文件夹,生成新的文件名
-                    .map(new Function<Object, DownloadInfo>() {
-                        @Override
-                        public DownloadInfo apply(Object o) throws Exception {
-                            return getRealFileName((DownloadInfo) o);
-                        }
-                    })
-                    //下载
-                    .flatMap(new Function<DownloadInfo, ObservableSource<DownloadInfo>>() {
-                        @Override
-                        public ObservableSource<DownloadInfo> apply(DownloadInfo downloadInfo) throws Exception {
-                            return Observable.create(new DownloadSubscribe(downloadInfo));
-                        }
-                    })
-                    //在主线程回调
-                    .observeOn(AndroidSchedulers.mainThread())
-                    //在子线程执行
-                    .subscribeOn(Schedulers.io())
-                    //添加观察者
-                    .subscribe(onDownLoadObserver);
-        } else {
-//            Call call = downCalls.get(url);
-//            if (call != null) {
-//                call.cancel();
-//            }
-            Observable.just(url)
-                    .flatMap(new Function<String, ObservableSource<DownloadInfo>>() {
-                        @Override
-                        public ObservableSource<DownloadInfo> apply(String s) throws Exception {
-                            return Observable.create(new DownloadingSubscribe(s));
-                        }
-                    })
-                    .subscribeOn(Schedulers.io())
-                    .observeOn(AndroidSchedulers.mainThread())
-                    .subscribe(onDownLoadObserver);
-        }
+    void download(String url) {
+//        if (!downCalls.containsKey(url)) {
+        Observable.just(url)
+                //call的map已经有了,就证明正在下载,则这次不下载
+                .filter(new Predicate<String>() {
+                    @Override
+                    public boolean test(String s) throws Exception {
+                        return !downCalls.containsKey(s);
+                    }
+                })
+                .flatMap(new Function<String, ObservableSource<?>>() {
+                    @Override
+                    public ObservableSource<?> apply(String s) throws Exception {
+                        return Observable.just(createDownInfo(s));
+                    }
+                })
+                //检测本地文件夹,生成新的文件名
+                .map(new Function<Object, DownloadInfo>() {
+                    @Override
+                    public DownloadInfo apply(Object o) throws Exception {
+                        return getRealFileName((DownloadInfo) o);
+                    }
+                })
+                //下载
+                .flatMap(new Function<DownloadInfo, ObservableSource<DownloadInfo>>() {
+                    @Override
+                    public ObservableSource<DownloadInfo> apply(DownloadInfo downloadInfo) throws Exception {
+                        return Observable.create(new DownloadSubscribe(downloadInfo));
+                    }
+                })
+                //在主线程回调
+                .observeOn(AndroidSchedulers.mainThread())
+                //在子线程执行
+                .subscribeOn(Schedulers.io())
+                //添加观察者
+                .subscribe(new DownloadObserver(mContext));
+//        } else {
+////            Call call = downCalls.get(url);
+////            if (call != null) {
+////                call.cancel();
+////            }
+//            Observable.just(url)
+//                    .flatMap(new Function<String, ObservableSource<DownloadInfo>>() {
+//                        @Override
+//                        public ObservableSource<DownloadInfo> apply(String s) throws Exception {
+//                            return Observable.create(new DownloadingSubscribe(s));
+//                        }
+//                    })
+//                    .subscribeOn(Schedulers.io())
+//                    .observeOn(AndroidSchedulers.mainThread())
+//                    .subscribe(onDownLoadObserver);
+//        }
     }
 
     /**

+ 57 - 0
okhttplib/src/main/java/com/benyanyi/okhttp/download/DownloadObserver.java

@@ -0,0 +1,57 @@
+package com.benyanyi.okhttp.download;
+
+import android.content.Context;
+
+import org.greenrobot.eventbus.EventBus;
+
+import io.reactivex.Observer;
+import io.reactivex.disposables.Disposable;
+
+/**
+ * @author YanYi
+ * @date 2019-08-19 12:37
+ * @email ben@yanyi.red
+ * @overview
+ */
+public class DownloadObserver implements Observer<DownloadInfo> {
+
+    public Disposable d;//可以用于取消注册的监听者
+    public DownloadInfo downloadInfo;
+    private Context mContext;
+
+    public DownloadObserver(Context context) {
+        this.mContext = context;
+    }
+
+    @Override
+    public void onSubscribe(Disposable d) {
+        this.d = d;
+    }
+
+    @Override
+    public void onNext(DownloadInfo downloadInfo) {
+        this.downloadInfo = downloadInfo;
+        downloadInfo.setDownloadStatus(DownloadInfo.DOWNLOAD_ING);
+        EventBus.getDefault().post(downloadInfo);
+    }
+
+    @Override
+    public void onError(Throwable e) {
+        if (DownloadManager.getInstance(mContext).getDownloadUrl(downloadInfo.getUrl())) {
+            DownloadManager.getInstance(mContext).pause(downloadInfo.getUrl());
+            downloadInfo.setDownloadStatus(DownloadInfo.DOWNLOAD_ERROR);
+            EventBus.getDefault().post(downloadInfo);
+        } else {
+            downloadInfo.setDownloadStatus(DownloadInfo.DOWNLOAD_PAUSE);
+            EventBus.getDefault().post(downloadInfo);
+        }
+    }
+
+    @Override
+    public void onComplete() {
+        if (downloadInfo != null) {
+            downloadInfo.setDownloadStatus(DownloadInfo.DOWNLOAD_OVER);
+            EventBus.getDefault().post(downloadInfo);
+        }
+    }
+}