|
@@ -2,14 +2,17 @@ package com.mylove.okhttp;
|
|
|
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
-import androidx.annotation.IdRes;
|
|
|
|
-import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.widget.Button;
|
|
import android.widget.Button;
|
|
import android.widget.ProgressBar;
|
|
import android.widget.ProgressBar;
|
|
|
|
|
|
|
|
+import androidx.annotation.IdRes;
|
|
|
|
+import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
+
|
|
|
|
+import com.benyanyi.loglib.Jlog;
|
|
import com.benyanyi.okhttp.OkHttpUtil;
|
|
import com.benyanyi.okhttp.OkHttpUtil;
|
|
import com.benyanyi.okhttp.download.DownloadInfo;
|
|
import com.benyanyi.okhttp.download.DownloadInfo;
|
|
|
|
+import com.benyanyi.okhttp.listener.OnDownLoadObserver;
|
|
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
@@ -25,7 +28,7 @@ public class DownloadActivity extends AppCompatActivity implements View.OnClickL
|
|
private Button downloadBtn1, downloadBtn2, downloadBtn3;
|
|
private Button downloadBtn1, downloadBtn2, downloadBtn3;
|
|
private Button cancelBtn1, cancelBtn2, cancelBtn3;
|
|
private Button cancelBtn1, cancelBtn2, cancelBtn3;
|
|
private ProgressBar progress1, progress2, progress3;
|
|
private ProgressBar progress1, progress2, progress3;
|
|
- String url2 = "https://go.ziwanyouxi.com/ad/=ITOwgjM/28092";
|
|
|
|
|
|
+ String url = "http://apitest.yanyi.online/app/xiangyou.apk";
|
|
|
|
|
|
private Context mContext;
|
|
private Context mContext;
|
|
|
|
|
|
@@ -58,11 +61,9 @@ public class DownloadActivity extends AppCompatActivity implements View.OnClickL
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void onClick(View v) {
|
|
public void onClick(View v) {
|
|
- String url1 = "http://www.yanyi.red/bluetooth/ios.pdf";
|
|
|
|
- String url3 = "https://go.ziwanyouxi.com/ad/=MDO3kjM/29783";
|
|
|
|
switch (v.getId()) {
|
|
switch (v.getId()) {
|
|
case R.id.main_btn_down1:
|
|
case R.id.main_btn_down1:
|
|
- AppContext.getDownloadManager().start(url2);
|
|
|
|
|
|
+// AppContext.getDownloadManager().start(url2);
|
|
break;
|
|
break;
|
|
// case R.id.main_btn_down1:
|
|
// case R.id.main_btn_down1:
|
|
// OkHttpUtil.getInstance(mContext).url(url1).download().start(new OnDownLoadObserver() {
|
|
// OkHttpUtil.getInstance(mContext).url(url1).download().start(new OnDownLoadObserver() {
|
|
@@ -80,26 +81,26 @@ public class DownloadActivity extends AppCompatActivity implements View.OnClickL
|
|
// }
|
|
// }
|
|
// });
|
|
// });
|
|
// break;
|
|
// 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_down2:
|
|
|
|
+ OkHttpUtil.getInstance(mContext).url(url).download(true).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:
|
|
// case R.id.main_btn_down3:
|
|
// OkHttpUtil.getInstance(mContext).url(url3).download(".apk").start(new OnDownLoadObserver() {
|
|
// OkHttpUtil.getInstance(mContext).url(url3).download(".apk").start(new OnDownLoadObserver() {
|
|
// @Override
|
|
// @Override
|
|
@@ -121,14 +122,14 @@ public class DownloadActivity extends AppCompatActivity implements View.OnClickL
|
|
// });
|
|
// });
|
|
// break;
|
|
// break;
|
|
case R.id.main_btn_cancel1:
|
|
case R.id.main_btn_cancel1:
|
|
- AppContext.getDownloadManager().cancel(url2);
|
|
|
|
|
|
+// AppContext.getDownloadManager().cancel(url);
|
|
// OkHttpUtil.getInstance(mContext).url(url1).download().cancel();
|
|
// OkHttpUtil.getInstance(mContext).url(url1).download().cancel();
|
|
break;
|
|
break;
|
|
case R.id.main_btn_cancel2:
|
|
case R.id.main_btn_cancel2:
|
|
- OkHttpUtil.getInstance(mContext).url(url2).download().pause();
|
|
|
|
|
|
+ OkHttpUtil.getInstance(mContext).url(url).download(true).pause();
|
|
break;
|
|
break;
|
|
case R.id.main_btn_cancel3:
|
|
case R.id.main_btn_cancel3:
|
|
- OkHttpUtil.getInstance(mContext).url(url3).download().cancel();
|
|
|
|
|
|
+ OkHttpUtil.getInstance(mContext).url(url).download(true).cancel();
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
break;
|
|
break;
|
|
@@ -138,7 +139,7 @@ public class DownloadActivity extends AppCompatActivity implements View.OnClickL
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
public void download(DownloadInfo downloadInfo) {
|
|
public void download(DownloadInfo downloadInfo) {
|
|
if (downloadInfo != null) {
|
|
if (downloadInfo != null) {
|
|
- if (downloadInfo.getUrl().equals(url2)) {
|
|
|
|
|
|
+ if (downloadInfo.getUrl().equals(url)) {
|
|
progress1.setMax((int) downloadInfo.getTotal());
|
|
progress1.setMax((int) downloadInfo.getTotal());
|
|
progress1.setProgress((int) downloadInfo.getProgress());
|
|
progress1.setProgress((int) downloadInfo.getProgress());
|
|
}
|
|
}
|