|
@@ -9,6 +9,7 @@ import android.preference.DialogPreference;
|
|
|
import android.support.annotation.NonNull;
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.annotation.Nullable;
|
|
import android.support.annotation.Nullable;
|
|
|
import android.support.annotation.RequiresApi;
|
|
import android.support.annotation.RequiresApi;
|
|
|
|
|
+import android.util.Log;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
import android.webkit.WebChromeClient;
|
|
import android.webkit.WebChromeClient;
|
|
|
import android.webkit.WebResourceRequest;
|
|
import android.webkit.WebResourceRequest;
|
|
@@ -25,6 +26,9 @@ import com.bumptech.glide.Glide;
|
|
|
import com.kfzs.duanduan.event.BigEvent;
|
|
import com.kfzs.duanduan.event.BigEvent;
|
|
|
import com.kfzs.duanduan.event.EventTypes;
|
|
import com.kfzs.duanduan.event.EventTypes;
|
|
|
import com.kfzs.duanduan.utils.dlg.DeviceUtils;
|
|
import com.kfzs.duanduan.utils.dlg.DeviceUtils;
|
|
|
|
|
+import com.liulishuo.filedownloader.BaseDownloadTask;
|
|
|
|
|
+import com.liulishuo.filedownloader.FileDownloadListener;
|
|
|
|
|
+import com.liulishuo.filedownloader.FileDownloader;
|
|
|
import com.sheep.gamegroup.di.components.DaggerTaskDialogComponent;
|
|
import com.sheep.gamegroup.di.components.DaggerTaskDialogComponent;
|
|
|
import com.sheep.gamegroup.di.modules.TaskDialogModule;
|
|
import com.sheep.gamegroup.di.modules.TaskDialogModule;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
@@ -38,14 +42,19 @@ import com.sheep.gamegroup.util.MyListview;
|
|
|
import com.sheep.gamegroup.view.adapter.DownLoadTvAdp;
|
|
import com.sheep.gamegroup.view.adapter.DownLoadTvAdp;
|
|
|
import com.sheep.gamegroup.view.adapter.TaskStateAdapter;
|
|
import com.sheep.gamegroup.view.adapter.TaskStateAdapter;
|
|
|
import com.sheep.gamegroup.view.customview.SProgress;
|
|
import com.sheep.gamegroup.view.customview.SProgress;
|
|
|
|
|
+import com.sheep.gamegroup.view.download.ProgressDownloader;
|
|
|
|
|
+import com.sheep.gamegroup.view.download.ProgressResponseBody;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.download.DowanLoadManagerDialog;
|
|
|
import com.sheep.jiuyan.samllsheep.download.DownloadInfo;
|
|
import com.sheep.jiuyan.samllsheep.download.DownloadInfo;
|
|
|
import com.sheep.jiuyan.samllsheep.download.DownloadManager;
|
|
import com.sheep.jiuyan.samllsheep.download.DownloadManager;
|
|
|
import com.sheep.jiuyan.samllsheep.download.DownloadState;
|
|
import com.sheep.jiuyan.samllsheep.download.DownloadState;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
|
|
import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
|
|
import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
|
|
|
|
|
+import com.zhy.http.okhttp.OkHttpUtils;
|
|
|
|
|
+import com.zhy.http.okhttp.callback.FileCallBack;
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
@@ -61,13 +70,17 @@ import javax.inject.Inject;
|
|
|
import butterknife.BindView;
|
|
import butterknife.BindView;
|
|
|
import butterknife.ButterKnife;
|
|
import butterknife.ButterKnife;
|
|
|
import butterknife.OnClick;
|
|
import butterknife.OnClick;
|
|
|
|
|
+import io.reactivex.Observable;
|
|
|
|
|
+import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
|
|
+import okhttp3.Call;
|
|
|
|
|
+import rx.functions.Action0;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 弹框activity
|
|
* 弹框activity
|
|
|
* Created by ljy on 2018/3/20.
|
|
* Created by ljy on 2018/3/20.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-public class DialogActivity extends Activity implements TaskDialogContract.View {
|
|
|
|
|
|
|
+public class DialogActivity extends Activity implements TaskDialogContract.View, ProgressResponseBody.ProgressListener {
|
|
|
|
|
|
|
|
@BindView(R.id.dialog_item_icon_iv)
|
|
@BindView(R.id.dialog_item_icon_iv)
|
|
|
ImageView dialogItemIconIv;
|
|
ImageView dialogItemIconIv;
|
|
@@ -91,7 +104,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
private List<TaskState> stateList = new ArrayList<>();//状态列表
|
|
private List<TaskState> stateList = new ArrayList<>();//状态列表
|
|
|
private TaskStateAdapter stateAdapter;
|
|
private TaskStateAdapter stateAdapter;
|
|
|
|
|
|
|
|
- private DownloadManager downloadManager;
|
|
|
|
|
|
|
+ private DowanLoadManagerDialog downloadManager;
|
|
|
DownloadInfo downloadInfo;
|
|
DownloadInfo downloadInfo;
|
|
|
private int type;//0,开始任务 1,开始试玩 2,开始下载
|
|
private int type;//0,开始任务 1,开始试玩 2,开始下载
|
|
|
private boolean isDownLoad = false;//是否下载
|
|
private boolean isDownLoad = false;//是否下载
|
|
@@ -106,6 +119,15 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
@Inject
|
|
@Inject
|
|
|
TaskDialogPresenter preference;
|
|
TaskDialogPresenter preference;
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * okhttp
|
|
|
|
|
+ */
|
|
|
|
|
+ private long breakPoints;
|
|
|
|
|
+ private ProgressDownloader downloader;
|
|
|
|
|
+ private File file;
|
|
|
|
|
+ private long totalBytes;
|
|
|
|
|
+ private long contentLength;
|
|
|
|
|
+
|
|
|
Handler handler = new Handler(){
|
|
Handler handler = new Handler(){
|
|
|
@Override
|
|
@Override
|
|
|
public void handleMessage(Message msg) {
|
|
public void handleMessage(Message msg) {
|
|
@@ -139,7 +161,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void initDatas() {
|
|
private void initDatas() {
|
|
|
- downloadManager = DownloadManager.getInstance();
|
|
|
|
|
|
|
+ downloadManager = DowanLoadManagerDialog.getInstance();
|
|
|
webview.loadUrl(task_entity.getBoot_address());
|
|
webview.loadUrl(task_entity.getBoot_address());
|
|
|
Glide.with(this)
|
|
Glide.with(this)
|
|
|
.load(task_entity.getIcon())
|
|
.load(task_entity.getIcon())
|
|
@@ -151,6 +173,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
isDownLoad = PackageUtil.isAppInstalled(activity, task_entity.getPackage_names());
|
|
isDownLoad = PackageUtil.isAppInstalled(activity, task_entity.getPackage_names());
|
|
|
|
|
|
|
|
isHaveLoad();
|
|
isHaveLoad();
|
|
|
|
|
+// downLoad();
|
|
|
// downLoadApk();
|
|
// downLoadApk();
|
|
|
/**
|
|
/**
|
|
|
* 下载
|
|
* 下载
|
|
@@ -158,7 +181,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
loadTvAdp = new DownLoadTvAdp(activity, infoList);
|
|
loadTvAdp = new DownLoadTvAdp(activity, infoList);
|
|
|
listview_down.setAdapter(loadTvAdp);
|
|
listview_down.setAdapter(loadTvAdp);
|
|
|
|
|
|
|
|
- setBtnState();
|
|
|
|
|
|
|
+// setBtnState();
|
|
|
|
|
|
|
|
//Todo ok
|
|
//Todo ok
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
JSONObject jsonObject = new JSONObject();
|
|
@@ -218,12 +241,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
// refresh();
|
|
// refresh();
|
|
|
try {
|
|
try {
|
|
|
downloadManager.startDownload(
|
|
downloadManager.startDownload(
|
|
|
- downloadInfo.getPkgName(),
|
|
|
|
|
- downloadInfo.getUrl(),
|
|
|
|
|
- downloadInfo.getLabel(),
|
|
|
|
|
- downloadInfo.getFileSavePath(), "",
|
|
|
|
|
- downloadInfo.isAutoResume(),
|
|
|
|
|
- downloadInfo.isAutoRename(),
|
|
|
|
|
|
|
+ downloadInfo,
|
|
|
null);
|
|
null);
|
|
|
} catch (DbException ex) {
|
|
} catch (DbException ex) {
|
|
|
Toast.makeText(x.app(), "添加下载失败", Toast.LENGTH_LONG).show();
|
|
Toast.makeText(x.app(), "添加下载失败", Toast.LENGTH_LONG).show();
|
|
@@ -261,7 +279,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
*/
|
|
*/
|
|
|
private void downLoadApk(){
|
|
private void downLoadApk(){
|
|
|
|
|
|
|
|
- start_task_tv.setVisibility(View.GONE);
|
|
|
|
|
|
|
+ start_task_tv.setVisibility(View.VISIBLE);
|
|
|
startStaskSprogress.setVisibility(View.VISIBLE);
|
|
startStaskSprogress.setVisibility(View.VISIBLE);
|
|
|
if (task_entity != null) {
|
|
if (task_entity != null) {
|
|
|
ClassFileHelper.getInstance().createSDDirection();
|
|
ClassFileHelper.getInstance().createSDDirection();
|
|
@@ -326,6 +344,14 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
infoList.clear();
|
|
infoList.clear();
|
|
|
infoList.add(downloadInfo);
|
|
infoList.add(downloadInfo);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ downloadManager.startDownload(
|
|
|
|
|
+ downloadInfo,
|
|
|
|
|
+ null);
|
|
|
|
|
+ } catch (DbException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
return downloadInfo;
|
|
return downloadInfo;
|
|
|
}
|
|
}
|
|
|
/**
|
|
/**
|
|
@@ -358,6 +384,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
loadTvAdp.setTaskState(type);
|
|
loadTvAdp.setTaskState(type);
|
|
|
loadTvAdp.addTaskPreference(preference);
|
|
loadTvAdp.addTaskPreference(preference);
|
|
|
loadTvAdp.addTaskEty(task_entity);
|
|
loadTvAdp.addTaskEty(task_entity);
|
|
|
|
|
+ downLoad();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -417,4 +444,100 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 下载
|
|
|
|
|
+ */
|
|
|
|
|
+ private void downLoad(){
|
|
|
|
|
+
|
|
|
|
|
+ ClassFileHelper.getInstance().createSDDirection();
|
|
|
|
|
+ final File mApkPath = new File(ClassFileHelper.DIR, task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX);
|
|
|
|
|
+ OkHttpUtils.get()
|
|
|
|
|
+ .url(task_entity.getDownload_link()+"")
|
|
|
|
|
+ .build()
|
|
|
|
|
+ .execute(new FileCallBack(ClassFileHelper.DIR, task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onError(Call call, Exception e, int id) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void inProgress(float progress, long total, int id) {
|
|
|
|
|
+ super.inProgress(progress, total, id);
|
|
|
|
|
+ Log.e("--","inProgress"+(int)(100*progress));
|
|
|
|
|
+ start_task_tv.setText((int)(100*progress)+"%");
|
|
|
|
|
+ if((int)(100*progress) == 100)
|
|
|
|
|
+ PackageUtil.installApk(getApplicationContext(), mApkPath.getAbsolutePath());
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onResponse(File response, int id) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * okhttp 下载
|
|
|
|
|
+ * @param contentLength
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onPreExecute(long contentLength) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void update(long totalBytes, boolean done) {
|
|
|
|
|
+ // 注意加上断点的长度
|
|
|
|
|
+ this.totalBytes = totalBytes + breakPoints;
|
|
|
|
|
+// progressBar.setProgress((int) (totalBytes + breakPoints) / 1024);
|
|
|
|
|
+ if (done) {
|
|
|
|
|
+ // 切换到主线程
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void fileDownloader(){
|
|
|
|
|
+ FileDownloader.getImpl()
|
|
|
|
|
+ .create("url")
|
|
|
|
|
+ .setWifiRequired(true)
|
|
|
|
|
+ .setPath(ClassFileHelper.DIR+task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX)
|
|
|
|
|
+ .setListener(new FileDownloadListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void pending(BaseDownloadTask task, int soFarBytes, int totalBytes) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void progress(BaseDownloadTask task, int soFarBytes, int totalBytes) {
|
|
|
|
|
+ int percent=(int) ((double) soFarBytes / (double) totalBytes * 100);
|
|
|
|
|
+ start_task_tv.setText("("+percent+"%"+")");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void completed(BaseDownloadTask task) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void paused(BaseDownloadTask task, int soFarBytes, int totalBytes) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void error(BaseDownloadTask task, Throwable e) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void warn(BaseDownloadTask task) {
|
|
|
|
|
+ continueDownLoad(task);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ private void continueDownLoad(BaseDownloadTask task) {
|
|
|
|
|
+ while (task.getSmallFileSoFarBytes()!=task.getSmallFileTotalBytes()){
|
|
|
|
|
+ int percent=(int) ((double) task.getSmallFileSoFarBytes() / (double) task.getSmallFileTotalBytes() * 100);
|
|
|
|
|
+ start_task_tv.setText("("+percent+"%"+")");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|