瀏覽代碼

修改下载方法,去除在线更新方法

YanYi 6 年之前
父節點
當前提交
f507a17f24

+ 1 - 1
.idea/misc.xml

@@ -129,7 +129,7 @@
       </value>
     </option>
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
   <component name="ProjectType">

+ 2 - 2
app/build.gradle

@@ -32,7 +32,7 @@ dependencies {
     androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
     implementation project(':okhttplib')
     implementation 'com.yanyi.benyanyi:loglib:1.0.0'
-    implementation 'com.yanyi.benyanyi:permissionlib:1.0.1'
-    implementation 'io.reactivex.rxjava2:rxjava:2.2.2'
+    implementation 'com.yanyi.benyanyi:permissionlib:1.0.2'
+    implementation 'io.reactivex.rxjava2:rxjava:2.2.4'
     implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
 }

+ 0 - 15
app/src/main/java/com/mylove/okhttp/DownloadActivity.java

@@ -12,8 +12,6 @@ import com.mylove.loglib.JLog;
 import com.mylove.okhttp.download.DownLoadObserver;
 import com.mylove.okhttp.download.DownloadInfo;
 import com.mylove.okhttp.download.DownloadManager;
-import com.mylove.okhttp.download.UpdateObserver;
-import com.mylove.okhttp.download.UpdateUtil;
 
 /**
  * @author BenYanYi
@@ -55,19 +53,6 @@ public class DownloadActivity extends AppCompatActivity implements View.OnClickL
 //        cancelBtn1.setOnClickListener(this);
 //        cancelBtn2.setOnClickListener(this);
 //        cancelBtn3.setOnClickListener(this);
-      UpdateUtil updateUtil=  new UpdateUtil(mContext,this,url1);
-      updateUtil.update();
-      updateUtil.setUpdateObserver(new UpdateObserver() {
-          @Override
-          protected void onSuccess(DownloadBean downloadBean) {
-              JLog.d(downloadBean);
-          }
-
-          @Override
-          public void onError(Throwable e) {
-
-          }
-      });
     }
 
     @Override

+ 0 - 23
app/src/main/java/com/mylove/okhttp/MainActivity.java

@@ -7,8 +7,6 @@ import android.support.annotation.Nullable;
 import android.support.v7.app.AppCompatActivity;
 
 import com.mylove.loglib.JLog;
-import com.mylove.okhttp.download.UpdateObserver;
-import com.mylove.okhttp.download.UpdateUtil;
 import com.mylove.okhttp.listener.OnOkHttpListener;
 import com.yanyi.permissionlib.PermissionHelper;
 import com.yanyi.permissionlib.PermissionType;
@@ -96,27 +94,6 @@ public class MainActivity extends AppCompatActivity {
 //                JLog.e(t.getMessage());
 //            }
 //        });
-        UpdateUtil updateUtil = new UpdateUtil(this, this, url)
-                .setIcon(R.mipmap.ic_launcher)
-                .setMessage("更新")
-                .setTitle("更新测试")
-                .setLimit(false)
-                .setShowNotice(true)
-                .setShowProgress(true)
-                .setInstallApk(true)
-                .setStartClass(MainActivity.class);
-        updateUtil.update();
-        updateUtil.setUpdateObserver(new UpdateObserver() {
-            @Override
-            protected void onSuccess(DownloadBean downloadBean) {
-                JLog.d(downloadBean);
-            }
-
-            @Override
-            public void onError(Throwable e) {
-
-            }
-        });
     }
 
     @Override

+ 0 - 2
okhttplib/src/main/java/com/mylove/okhttp/DownloadBean.java

@@ -7,14 +7,12 @@ package com.mylove.okhttp;
  * @overview 下载状态
  */
 public class DownloadBean {
-    public int progress;
     public int status = 0;
     public String filePath;
 
     @Override
     public String toString() {
         return "DownloadBean{" +
-                "progress=" + progress +
                 ", status=" + status +
                 ", filePath='" + filePath + '\'' +
                 '}';

+ 0 - 57
okhttplib/src/main/java/com/mylove/okhttp/DownloadDialog.java

@@ -1,57 +0,0 @@
-package com.mylove.okhttp;
-
-import android.content.Context;
-import android.content.DialogInterface;
-import android.support.v7.app.AlertDialog;
-
-/**
- * @author BenYanYi
- * @date 2018/11/20 09:45
- * @email ben@yanyi.red
- * @overview
- */
-public class DownloadDialog {
-    private String title = "升级";
-    private String message = "发现新的安装包";
-    private boolean isLimit = false;//是否可以关闭
-
-    public DownloadDialog() {
-    }
-
-    public DownloadDialog setTitle(String title) {
-        this.title = title;
-        return this;
-    }
-
-    public DownloadDialog setMessage(String message) {
-        this.message = message;
-        return this;
-    }
-
-    public DownloadDialog setLimit(boolean limit) {
-        isLimit = limit;
-        return this;
-    }
-
-    void init(Context context) {
-        final AlertDialog.Builder builder = new AlertDialog.Builder(context);
-        builder.setTitle(title);
-        builder.setMessage(message);
-        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
-            @Override
-            public void onClick(DialogInterface dialog, int which) {
-
-            }
-        });
-        if (!isLimit) {
-            builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
-                @Override
-                public void onClick(DialogInterface dialog, int which) {
-                    dialog.dismiss();
-                }
-            });
-        }
-        builder.setCancelable(isLimit);
-        builder.show();
-    }
-}

+ 10 - 8
okhttplib/src/main/java/com/mylove/okhttp/DownloadObservable.java

@@ -35,6 +35,7 @@ class DownloadObservable {
     @SuppressLint("StaticFieldLeak")
     private static Context mContext;
     private String filePath;
+    private String fileName;
     private static OkHttpClient okHttpClient;
 
     private DownloadObservable() {
@@ -62,8 +63,9 @@ class DownloadObservable {
         return instance;
     }
 
-    void request(String url, String filePath, final OnDownloadListener onDownloadListener) {
+    void request(String url, String filePath, String fileName, final OnDownloadListener onDownloadListener) {
         this.filePath = filePath;
+        this.fileName = fileName;
         getObservable(url)
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
@@ -81,7 +83,7 @@ class DownloadObservable {
                         if (bean.status == 1) {
                             onDownloadListener.onSuccess(bean.filePath);
                         } else {
-                            onDownloadListener.onDownloading(bean.progress);
+                            onDownloadListener.onDownloading();
                         }
                     }
 
@@ -127,7 +129,6 @@ class DownloadObservable {
      * 请求
      */
     private void sendCall(final String url, Call call, final ObservableEmitter<DownloadBean> subscriber) {
-
         call.enqueue(new Callback() {
             @Override
             public void onFailure(@NonNull Call call, @NonNull IOException e) {
@@ -149,7 +150,12 @@ class DownloadObservable {
                 try {
                     is = response.body().byteStream();
                     long total = response.body().contentLength();
-                    File file = new File(savePath, FileUtil.getNameFromUrl(url));
+                    File file;
+                    if (FormatUtil.isEmpty(fileName)) {
+                        file = new File(savePath, FileUtil.getNameFromUrl(url));
+                    } else {
+                        file = new File(savePath, fileName);
+                    }
                     bean.filePath = file.getAbsolutePath();
                     if (OkHttpInfo.isLOG)
                         LogHelper.d(filePath);
@@ -158,11 +164,7 @@ class DownloadObservable {
                     while ((len = is.read(buf)) != -1) {
                         fos.write(buf, 0, len);
                         sum += len;
-                        int progress = (int) (sum * 1.0f / total * 100);
-                        if (OkHttpInfo.isLOG)
-                            LogHelper.i(progress + "%");
                         bean.status = 0;
-                        bean.progress = progress;
                         if (OkHttpInfo.isLOG)
                             LogHelper.d(bean);
                         // 下载中

+ 0 - 223
okhttplib/src/main/java/com/mylove/okhttp/DownloadObservables.java

@@ -1,223 +0,0 @@
-package com.mylove.okhttp;
-
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.os.Handler;
-import android.os.Message;
-import android.support.annotation.NonNull;
-
-import com.mylove.okhttp.listener.OnDownloadListener;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.concurrent.TimeUnit;
-
-import okhttp3.Call;
-import okhttp3.Callback;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.Response;
-
-/**
- * @author BenYanYi
- * @date 2018/9/13 17:43
- * @email ben@yanyi.red
- * @overview
- */
-public class DownloadObservables {
-    @SuppressLint("StaticFieldLeak")
-    private static DownloadObservables instance;
-    @SuppressLint("StaticFieldLeak")
-    private static Context mContext;
-    private String filePath;
-    private static OkHttpClient okHttpClient;
-    private String filePaths = "";
-    private String url;
-    private OnDownloadListener downloadListener;
-
-    private DownloadObservables() {
-    }
-
-    static DownloadObservables getInstance(Context context) {
-        if (instance == null) {
-            synchronized (DownloadObservable.class) {
-                if (instance == null) {
-                    instance = new DownloadObservables();
-                    OkHttpClient httpClient = new OkHttpClient();
-                    okHttpClient = httpClient.newBuilder()
-                            .addNetworkInterceptor(new CacheInterceptor())
-                            .addInterceptor(Cache.HTTP_LOGGING_INTERCEPTOR)
-                            .cache(Cache.privateCache(context))
-                            .connectTimeout(30, TimeUnit.SECONDS)
-                            .readTimeout(30, TimeUnit.SECONDS)
-                            .writeTimeout(30, TimeUnit.SECONDS)
-                            .build();
-                }
-            }
-        }
-        mContext = context;
-        return instance;
-    }
-
-    void request(String url, String filePath, OnDownloadListener onDownloadListener) {
-        this.filePath = filePath;
-        this.url = url;
-        this.downloadListener = onDownloadListener;
-        send();
-    }
-
-    private void send() {
-        InternetBean bean = Internet.ifInternet(mContext);
-        if (bean.getStatus()) {
-            Request request = new Request.Builder()
-                    .url(url)
-                    .build();
-            Call call = okHttpClient.newCall(request);
-            sendCall(url, call);
-        } else {
-            if (downloadListener != null) {
-                downloadListener.onFailure(new Throwable(bean.getMsg()));
-            }
-        }
-    }
-
-    /**
-     * 请求
-     */
-    private void sendCall(final String url, Call call) {
-
-        call.enqueue(new Callback() {
-            @Override
-            public void onFailure(@NonNull Call call, @NonNull IOException e) {
-                if (OkHttpInfo.isLOG)
-                    LogHelper.e(e.getMessage());
-                if (downloadListener != null) {
-                    downloadListener.onFailure(e);
-                }
-            }
-
-            @Override
-            public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
-                final DownloadBean bean = new DownloadBean();
-                InputStream is = null;
-                byte[] buf = new byte[2048];
-                int len = 0;
-                FileOutputStream fos = null;
-                // 储存下载文件的目录
-                String savePath = FileUtil.isExistDir(filePath);
-                try {
-                    is = response.body().byteStream();
-                    long total = response.body().contentLength();
-                    File file = new File(savePath);
-                    bean.filePath = savePath;
-                    if (OkHttpInfo.isLOG)
-                        LogHelper.d(filePath);
-                    fos = new FileOutputStream(file);
-                    long sum = 0;
-                    while ((len = is.read(buf)) != -1) {
-                        fos.write(buf, 0, len);
-                        sum += len;
-                        final int progress = (int) (sum * 1.0f / total * 100);
-                        if (OkHttpInfo.isLOG)
-                            LogHelper.i(progress + "%");
-                        bean.status = 0;
-                        bean.progress = progress;
-                        if (OkHttpInfo.isLOG)
-                            LogHelper.d(bean);
-                        // 下载中
-                        new Thread() {
-                            @Override
-                            public void run() {
-                                Message message = new Message();
-                                message.obj = progress;
-                                message.what = 1;
-                                mHandler.sendMessage(message);
-                            }
-                        }.start();
-                    }
-                    fos.flush();
-                    // 下载完成
-                    bean.progress = 100;
-                    bean.status = 1;
-                    if (OkHttpInfo.isLOG)
-                        LogHelper.d(bean);
-                    filePaths = file.getAbsolutePath();
-                    // 下载中
-                    new Thread() {
-                        @Override
-                        public void run() {
-                            Message message = new Message();
-                            message.obj = bean;
-                            message.what = 2;
-                            mHandler.sendMessage(message);
-                        }
-                    }.start();
-                } catch (final Exception e) {
-                    if (OkHttpInfo.isLOG)
-                        LogHelper.e(e.getMessage());
-                    new Thread() {
-                        @Override
-                        public void run() {
-                            Message message = new Message();
-                            message.obj = e;
-                            message.what = 3;
-                            mHandler.sendMessage(message);
-                        }
-                    }.start();
-                } finally {
-                    try {
-                        if (is != null)
-                            is.close();
-                    } catch (IOException e) {
-                        if (OkHttpInfo.isLOG)
-                            LogHelper.e(e.getMessage());
-                    }
-                    try {
-                        if (fos != null)
-                            fos.close();
-                    } catch (IOException e) {
-                        if (OkHttpInfo.isLOG)
-                            LogHelper.e(e.getMessage());
-                    }
-                }
-                new Thread() {
-                    @Override
-                    public void run() {
-                        mHandler.sendEmptyMessage(0);
-                    }
-                }.start();
-            }
-        });
-    }
-
-    private Handler mHandler = new Handler() {
-        @Override
-        public void handleMessage(Message msg) {
-            super.handleMessage(msg);
-            int what = msg.what;
-            if (what == 0) {
-                if (downloadListener != null) {
-                    downloadListener.onCompleted();
-                }
-            } else if (what == 1) {
-                int progress = (int) msg.obj;
-                if (downloadListener != null) {
-                    downloadListener.onDownloading(progress);
-                }
-            } else if (what == 2) {
-                DownloadBean bean = (DownloadBean) msg.obj;
-                if (downloadListener != null) {
-                    downloadListener.onDownloading(bean.progress);
-                    downloadListener.onSuccess(bean);
-                }
-            } else if (what == 3) {
-                Exception exception = (Exception) msg.obj;
-                if (downloadListener != null) {
-                    downloadListener.onFailure(exception);
-                }
-            }
-        }
-    };
-}

+ 0 - 30
okhttplib/src/main/java/com/mylove/okhttp/DownloadObserver.java

@@ -1,30 +0,0 @@
-package com.mylove.okhttp;
-
-import io.reactivex.Observer;
-import io.reactivex.disposables.Disposable;
-
-/**
- * @author BenYanYi
- * @date 2018/11/29 17:24
- * @email ben@yanyi.red
- * @overview
- */
-public abstract class DownloadObserver implements Observer<DownloadBean> {
-    protected Disposable d;
-
-    @Override
-    public void onComplete() {
-
-    }
-
-    @Override
-    public void onSubscribe(Disposable d) {
-        this.d = d;
-    }
-
-    @Override
-    public void onError(Throwable e) {
-
-    }
-
-}

+ 9 - 9
okhttplib/src/main/java/com/mylove/okhttp/DownloadRequest.java

@@ -5,8 +5,6 @@ import android.content.Context;
 
 import com.mylove.okhttp.listener.OnDownloadListener;
 
-import java.io.File;
-
 /**
  * @author myLove
  */
@@ -41,19 +39,21 @@ public class DownloadRequest {
         if (FormatUtil.isEmpty(filePath)) {
             throw new NullPointerException("filePath is the SDCard directory of the downloaded file, cannot be empty.");
         }
-        DownloadObservable.getInstance(mContext).request(url, filePath, onDownloadListener);
+        DownloadObservable.getInstance(mContext).request(url, filePath, "", onDownloadListener);
     }
 
     /**
-     * @param filePath         储存下载文件的SDCard目录
-     * @param downloadListener 监听
+     * @param filePath           储存下载文件的SDCard目录
+     * @param fileName           文件名称
+     * @param onDownloadListener 监听
      */
-    public void downloads(String filePath, OnDownloadListener downloadListener) {
+    @Deprecated
+    public void download(String filePath, String fileName, OnDownloadListener onDownloadListener) {
         //saveDir判断不能为空
         if (FormatUtil.isEmpty(filePath)) {
-            File file = new File(mContext.getPackageName(), FileUtil.getNameFromUrl(url));
-            filePath = file.getPath();
+            throw new NullPointerException("filePath is the SDCard directory of the downloaded file, cannot be empty.");
         }
-        DownloadObservables.getInstance(mContext).request(url, filePath, downloadListener);
+        DownloadObservable.getInstance(mContext).request(url, filePath, fileName, onDownloadListener);
     }
+
 }

+ 0 - 16
okhttplib/src/main/java/com/mylove/okhttp/download/OnDownloadCallBack.java

@@ -1,16 +0,0 @@
-package com.mylove.okhttp.download;
-
-/**
- * @author BenYanYi
- * @date 2018/11/29 16:29
- * @email ben@yanyi.red
- * @overview
- */
-public interface OnDownloadCallBack {
-
-    void onNext(DownloadInfo downloadInfo);
-
-    void onError(Throwable e);
-
-    void onComplete();
-}

+ 0 - 23
okhttplib/src/main/java/com/mylove/okhttp/download/UpdateObserver.java

@@ -1,23 +0,0 @@
-package com.mylove.okhttp.download;
-
-import com.mylove.okhttp.DownloadBean;
-
-/**
- * @author BenYanYi
- * @date 2018/12/03 10:18
- * @email ben@yanyi.red
- * @overview
- */
-public abstract class UpdateObserver {
-
-    protected abstract void onSuccess(DownloadBean downloadBean);
-
-    protected void onComplete() {
-
-    }
-
-    public abstract void onError(Throwable e);
-
-    protected void onDialogDismiss() {
-    }
-}

+ 0 - 318
okhttplib/src/main/java/com/mylove/okhttp/download/UpdateUtil.java

@@ -1,318 +0,0 @@
-package com.mylove.okhttp.download;
-
-import android.app.Activity;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Build;
-import android.support.annotation.DrawableRes;
-import android.support.v4.content.FileProvider;
-import android.support.v7.app.AlertDialog;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.ProgressBar;
-
-import com.mylove.okhttp.DownloadBean;
-import com.mylove.okhttp.LogHelper;
-import com.mylove.okhttp.OkHttpUtil;
-import com.mylove.okhttp.R;
-import com.mylove.okhttp.listener.OnDownloadListener;
-
-import java.io.File;
-
-/**
- * @author BenYanYi
- * @date 2018/11/20 10:23
- * @email ben@yanyi.red
- * @overview
- */
-public class UpdateUtil {
-    private Activity mActivity;
-    private Context mContext;
-
-    private String downloadUrl = "";//app下载地址
-    private String title = "升级";
-    private String message = "发现新的安装包";
-    private static boolean isLimit = false;//是否可以关闭
-
-    private boolean isShowNotice = false;//是否显示通知栏
-    private boolean isShowProgress = false;//是否显示下载进度弹窗
-
-    private int icon;
-
-    private NotificationUtil notificationUtil;
-    private AlertDialog.Builder progressDialog;
-    private ProgressBar progressBar;
-    private AlertDialog dialog;
-
-    private Class<?> aClass;
-
-    private static boolean isInstallApk = false;
-    private UpdateObserver updateObserver;
-
-    private String filePath;
-
-    private static final int INSTALL_APK = 0x1020;
-
-    public UpdateUtil(Context context, Activity mActivity, String downloadUrl) {
-        this.mActivity = mActivity;
-        this.mContext = context;
-        setDownloadUrl(downloadUrl);
-    }
-
-    public UpdateUtil setDownloadUrl(String downloadUrl) {
-        if (FormatUtil.isEmpty(downloadUrl)) {
-            throw new NullPointerException("");
-        }
-        this.downloadUrl = downloadUrl;
-        return this;
-    }
-
-    /**
-     * 设置弹窗标题
-     */
-    public UpdateUtil setTitle(String title) {
-        if (FormatUtil.isNotEmpty(title)) {
-            this.title = title;
-        }
-        return this;
-    }
-
-    /**
-     * 设置弹窗内容
-     */
-    public UpdateUtil setMessage(String message) {
-        if (FormatUtil.isNotEmpty(message)) {
-            this.message = message;
-        }
-        return this;
-    }
-
-    /**
-     * 是否需要强制下载
-     */
-    public UpdateUtil setLimit(boolean limit) {
-        isLimit = limit;
-        return this;
-    }
-
-    /**
-     * 是否显示下载进度弹窗
-     *
-     * @param showProgress
-     */
-    public UpdateUtil setShowProgress(boolean showProgress) {
-        isShowProgress = showProgress;
-        return this;
-    }
-
-    /**
-     * 是否显示通知弹窗
-     */
-    public UpdateUtil setShowNotice(boolean showNotice) {
-        isShowNotice = showNotice;
-        return this;
-    }
-
-    /**
-     * 通知弹窗跳转页面
-     *
-     * @param aClass
-     */
-    public UpdateUtil setStartClass(Class<?> aClass) {
-        this.aClass = aClass;
-        return this;
-    }
-
-    /**
-     * 设置图标
-     */
-    public UpdateUtil setIcon(@DrawableRes int icon) {
-        this.icon = icon;
-        return this;
-    }
-
-    /**
-     * 是否需要安装
-     */
-    public UpdateUtil setInstallApk(boolean installApk) {
-        isInstallApk = installApk;
-        return this;
-    }
-
-    /**
-     * 下载监听
-     */
-    public UpdateUtil setUpdateObserver(UpdateObserver updateObserver) {
-        this.updateObserver = updateObserver;
-        return this;
-    }
-
-    /**
-     * 存储目录
-     */
-    public UpdateUtil setFilePath(String filePath) {
-        this.filePath = filePath;
-        return this;
-    }
-
-    /**
-     * 升级
-     */
-    public void update() {
-        if (FormatUtil.isEmpty(title)) {
-            title = "提示";
-        }
-        if (FormatUtil.isEmpty(message)) {
-            message = "是否下载";
-        }
-        notificationUtil = new NotificationUtil(mActivity, icon, title);
-        if (aClass != null) {
-            notificationUtil.setClass(aClass);
-        }
-        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
-        if (icon != 0) {
-            builder.setIcon(icon);
-        }
-        builder.setTitle(title);
-        builder.setMessage(message);
-        builder.setPositiveButton("立即更新", new DialogInterface.OnClickListener() {
-            @Override
-            public void onClick(DialogInterface dialog, int which) {
-                dialog.dismiss();
-                download();
-            }
-        });
-        if (!isLimit) {
-            builder.setNegativeButton("下次提醒", new DialogInterface.OnClickListener() {
-                @Override
-                public void onClick(DialogInterface dialog, int which) {
-                    dialog.dismiss();
-                    if (updateObserver != null) {
-                        updateObserver.onDialogDismiss();
-                    }
-                }
-            });
-        }
-        builder.setCancelable(!isLimit);
-        builder.show();
-    }
-
-    /**
-     * 进度条
-     */
-    private AlertDialog.Builder getProgressDialog() {
-        if (progressDialog == null) {
-            AlertDialog.Builder progressDialog1 = new AlertDialog.Builder(mContext);
-            View mView = LayoutInflater.from(mContext).inflate(R.layout.progress_dialog, null);
-            progressDialog1.setView(mView);
-            progressDialog1.setTitle(title);
-            progressDialog1.setMessage("正在下载");
-//        progressDialog.setProgress(0);
-            // 设置ProgressDialog 的进度条是否不明确
-            progressDialog1.setCancelable(false);
-            if (icon != 0)
-                progressDialog1.setIcon(icon);
-            progressBar = mView.findViewById(R.id.progress);
-            progressBar.setMax(100);
-            progressDialog = progressDialog1;
-        }
-        return progressDialog;
-    }
-
-    /**
-     * 下载
-     */
-    private void download() {
-        if (isShowProgress) {
-            dialog = getProgressDialog().show();
-        }
-        if (isShowNotice) {
-            notificationUtil.showNotification(1020);
-        }
-        OkHttpUtil.getInstance(mContext).downloadFile(downloadUrl).downloads(filePath, new OnDownloadListener() {
-            @Override
-            public void onDownloading(int progress) {
-                LogHelper.v("进度" + progress);
-                if (notificationUtil != null && isShowNotice) {
-                    notificationUtil.updateProgressText(1020, progress, "已下载" + progress + "%");
-                }
-                if (isShowProgress) {
-                    getProgressDialog().setMessage("已下载" + progress + "%");
-//                    getProgressDialog().setProgress(progress);
-                    if (progressBar != null) {
-                        progressBar.setProgress(progress);
-                    }
-                }
-            }
-
-            @Override
-            public void onCompleted() {
-                if (updateObserver != null) {
-                    updateObserver.onComplete();
-                }
-            }
-
-            @Override
-            public <T> void onSuccess(T message) {
-                DownloadBean downloadBean = (DownloadBean) message;
-                if (downloadBean != null && downloadBean.status == 1) {
-                    if (isShowNotice) {
-                        notificationUtil.cancel(1020);
-                    }
-                    if (isShowProgress) {
-                        dialog.dismiss();
-                    }
-                    if (isInstallApk && FileUtil.ifUrl(downloadBean.filePath, ".apk")) {
-                        installApk(new File(downloadBean.filePath));
-                    }
-                }
-                if (updateObserver != null) {
-                    updateObserver.onSuccess(downloadBean);
-                }
-            }
-
-            @Override
-            public void onFailure(Throwable t) {
-                if (updateObserver != null) {
-                    updateObserver.onError(t);
-                }
-            }
-        });
-    }
-
-    /**
-     * 安装下载完成的安装包
-     *
-     * @param file
-     */
-    private void installApk(File file) {
-        //判读版本是否在7.0以上
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-            //在AndroidManifest中的android:authorities值
-            LogHelper.a(file.getAbsolutePath());
-            Uri apkUri = FileProvider.getUriForFile(mActivity, mActivity.getPackageName() + ".fileProvider", file);
-            Intent install = new Intent(Intent.ACTION_VIEW);
-            install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
-            install.setDataAndType(apkUri, "application/vnd.android.package-archive");
-            mActivity.startActivityForResult(install, INSTALL_APK);
-        } else {
-            Intent install = new Intent(Intent.ACTION_VIEW);
-            install.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
-            install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            mActivity.startActivityForResult(install, INSTALL_APK);
-        }
-    }
-
-//    public static void onActivityResult(int requestCode, int resultCode, Intent data) {
-//        if (requestCode == INSTALL_APK) {
-//            if (isLimit && isInstallApk) {
-//
-//            } else {
-//
-//            }
-//        }
-//    }
-}

+ 0 - 15
okhttplib/src/main/java/com/mylove/okhttp/listener/OnDownloadCallBack.java

@@ -1,15 +0,0 @@
-package com.mylove.okhttp.listener;
-
-/**
- * @author BenYanYi
- * @date 2018/9/14 10:24
- * @email ben@yanyi.red
- * @overview
- */
-public interface OnDownloadCallBack {
-    void onDownloading(int progress);
-
-    void onSuccess(String filePath);
-
-    void onFailure(Throwable throwable);
-}

+ 0 - 13
okhttplib/src/main/java/com/mylove/okhttp/listener/OnDownloadFileCallBack.java

@@ -1,13 +0,0 @@
-package com.mylove.okhttp.listener;
-
-/**
- * @author BenYanYi
- * @date 2018/11/20 17:05
- * @email ben@yanyi.red
- * @overview
- */
-public interface OnDownloadFileCallBack {
-    void onDownloading(int progress);
-
-    void onSuccess();
-}

+ 2 - 2
okhttplib/src/main/java/com/mylove/okhttp/listener/OnDownloadListener.java

@@ -8,7 +8,7 @@ package com.mylove.okhttp.listener;
  */
 public interface OnDownloadListener extends OnOkHttpListener {
     /**
-     * @param progress 下载进度
+     * 下载中
      */
-    void onDownloading(int progress);
+    void onDownloading();
 }