|
|
@@ -9,7 +9,6 @@ import android.preference.DialogPreference;
|
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.annotation.Nullable;
|
|
|
import android.support.annotation.RequiresApi;
|
|
|
-import android.util.Log;
|
|
|
import android.view.View;
|
|
|
import android.webkit.WebChromeClient;
|
|
|
import android.webkit.WebResourceRequest;
|
|
|
@@ -26,9 +25,6 @@ import com.bumptech.glide.Glide;
|
|
|
import com.kfzs.duanduan.event.BigEvent;
|
|
|
import com.kfzs.duanduan.event.EventTypes;
|
|
|
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.modules.TaskDialogModule;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
@@ -42,19 +38,14 @@ import com.sheep.gamegroup.util.MyListview;
|
|
|
import com.sheep.gamegroup.view.adapter.DownLoadTvAdp;
|
|
|
import com.sheep.gamegroup.view.adapter.TaskStateAdapter;
|
|
|
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.SheepApp;
|
|
|
-import com.sheep.jiuyan.samllsheep.download.DowanLoadManagerDialog;
|
|
|
import com.sheep.jiuyan.samllsheep.download.DownloadInfo;
|
|
|
import com.sheep.jiuyan.samllsheep.download.DownloadManager;
|
|
|
import com.sheep.jiuyan.samllsheep.download.DownloadState;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
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;
|
|
|
@@ -70,17 +61,13 @@ import javax.inject.Inject;
|
|
|
import butterknife.BindView;
|
|
|
import butterknife.ButterKnife;
|
|
|
import butterknife.OnClick;
|
|
|
-import io.reactivex.Observable;
|
|
|
-import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
-import okhttp3.Call;
|
|
|
-import rx.functions.Action0;
|
|
|
|
|
|
/**
|
|
|
* 弹框activity
|
|
|
* Created by ljy on 2018/3/20.
|
|
|
*/
|
|
|
|
|
|
-public class DialogActivity extends Activity implements TaskDialogContract.View, ProgressResponseBody.ProgressListener {
|
|
|
+public class DialogActivity extends Activity implements TaskDialogContract.View {
|
|
|
|
|
|
@BindView(R.id.dialog_item_icon_iv)
|
|
|
ImageView dialogItemIconIv;
|
|
|
@@ -104,7 +91,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View,
|
|
|
private List<TaskState> stateList = new ArrayList<>();//状态列表
|
|
|
private TaskStateAdapter stateAdapter;
|
|
|
|
|
|
- private DowanLoadManagerDialog downloadManager;
|
|
|
+ private DownloadManager downloadManager;
|
|
|
DownloadInfo downloadInfo;
|
|
|
private int type;//0,开始任务 1,开始试玩 2,开始下载
|
|
|
private boolean isDownLoad = false;//是否下载
|
|
|
@@ -119,15 +106,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View,
|
|
|
@Inject
|
|
|
TaskDialogPresenter preference;
|
|
|
|
|
|
- /**
|
|
|
- * okhttp
|
|
|
- */
|
|
|
- private long breakPoints;
|
|
|
- private ProgressDownloader downloader;
|
|
|
- private File file;
|
|
|
- private long totalBytes;
|
|
|
- private long contentLength;
|
|
|
-
|
|
|
Handler handler = new Handler(){
|
|
|
@Override
|
|
|
public void handleMessage(Message msg) {
|
|
|
@@ -161,7 +139,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View,
|
|
|
}
|
|
|
|
|
|
private void initDatas() {
|
|
|
- downloadManager = DowanLoadManagerDialog.getInstance();
|
|
|
+ downloadManager = DownloadManager.getInstance();
|
|
|
webview.loadUrl(task_entity.getBoot_address());
|
|
|
Glide.with(this)
|
|
|
.load(task_entity.getIcon())
|
|
|
@@ -170,10 +148,9 @@ public class DialogActivity extends Activity implements TaskDialogContract.View,
|
|
|
.into(dialogItemIconIv);
|
|
|
dialogItemNameTv.setText(task_entity.getName());
|
|
|
dialogItemSizeTv.setText( task_entity.getPackage_size() + "M");
|
|
|
- isDownLoad = PackageUtil.isAppInstalled(activity, task_entity.getPackage_names());
|
|
|
+ isDownLoad = PackageUtil.isAppInstalled(SheepApp.mContext, task_entity.getPackage_names());
|
|
|
|
|
|
isHaveLoad();
|
|
|
-// downLoad();
|
|
|
// downLoadApk();
|
|
|
/**
|
|
|
* 下载
|
|
|
@@ -181,7 +158,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View,
|
|
|
loadTvAdp = new DownLoadTvAdp(activity, infoList);
|
|
|
listview_down.setAdapter(loadTvAdp);
|
|
|
|
|
|
-// setBtnState();
|
|
|
+ setBtnState();
|
|
|
|
|
|
//Todo ok
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
@@ -241,7 +218,12 @@ public class DialogActivity extends Activity implements TaskDialogContract.View,
|
|
|
// refresh();
|
|
|
try {
|
|
|
downloadManager.startDownload(
|
|
|
- downloadInfo,
|
|
|
+ downloadInfo.getPkgName(),
|
|
|
+ downloadInfo.getUrl(),
|
|
|
+ downloadInfo.getLabel(),
|
|
|
+ downloadInfo.getFileSavePath(), "",
|
|
|
+ downloadInfo.isAutoResume(),
|
|
|
+ downloadInfo.isAutoRename(),
|
|
|
null);
|
|
|
} catch (DbException ex) {
|
|
|
Toast.makeText(x.app(), "添加下载失败", Toast.LENGTH_LONG).show();
|
|
|
@@ -279,7 +261,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View,
|
|
|
*/
|
|
|
private void downLoadApk(){
|
|
|
|
|
|
- start_task_tv.setVisibility(View.VISIBLE);
|
|
|
+ start_task_tv.setVisibility(View.GONE);
|
|
|
startStaskSprogress.setVisibility(View.VISIBLE);
|
|
|
if (task_entity != null) {
|
|
|
ClassFileHelper.getInstance().createSDDirection();
|
|
|
@@ -328,29 +310,24 @@ public class DialogActivity extends Activity implements TaskDialogContract.View,
|
|
|
ClassFileHelper.getInstance().createSDDirection();
|
|
|
File mApkPath = new File(ClassFileHelper.DIR, task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX);
|
|
|
downloadInfo = MyDbManager.getInstance().dbFindDownLoad(task_entity.getTask_name(), mApkPath.getAbsolutePath());
|
|
|
- if (downloadInfo == null) {
|
|
|
- downloadInfo = new DownloadInfo();
|
|
|
- downloadInfo.setUrl(task_entity.getDownload_link());
|
|
|
- downloadInfo.setAutoRename(false);
|
|
|
- downloadInfo.setAutoResume(true);
|
|
|
- downloadInfo.setLabel(task_entity.getTask_name());
|
|
|
- downloadInfo.setFileSavePath(mApkPath.getAbsolutePath());
|
|
|
- downloadInfo.setIcon(task_entity.getIcon());
|
|
|
- downloadInfo.setState(DownloadState.STARTED);
|
|
|
- downloadInfo.setPkgName(task_entity.getPackage_names());
|
|
|
- MyDbManager.getInstance().saveOrUpdateUser(downloadInfo);//保存到数据库
|
|
|
- }
|
|
|
-
|
|
|
+ if (!mApkPath.exists()) {
|
|
|
+ if (downloadInfo == null) {
|
|
|
+ downloadInfo = new DownloadInfo();
|
|
|
+ downloadInfo.setUrl(task_entity.getDownload_link());
|
|
|
+ downloadInfo.setAutoRename(false);
|
|
|
+ downloadInfo.setAutoResume(true);
|
|
|
+ downloadInfo.setLabel(task_entity.getTask_name());
|
|
|
+ downloadInfo.setFileSavePath(mApkPath.getAbsolutePath());
|
|
|
+ downloadInfo.setIcon(task_entity.getIcon());
|
|
|
+ downloadInfo.setState(DownloadState.STARTED);
|
|
|
+ downloadInfo.setPkgName(task_entity.getPackage_names());
|
|
|
+ MyDbManager.getInstance().saveOrUpdateUser(downloadInfo);//保存到数据库
|
|
|
+ }else{
|
|
|
+// start_task_tv.setText("继续下载");
|
|
|
+ }
|
|
|
infoList.clear();
|
|
|
infoList.add(downloadInfo);
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- downloadManager.startDownload(
|
|
|
- downloadInfo,
|
|
|
- null);
|
|
|
- } catch (DbException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
return downloadInfo;
|
|
|
}
|
|
|
@@ -365,7 +342,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View,
|
|
|
* 按钮状态
|
|
|
*/
|
|
|
private void setBtnState(){
|
|
|
-
|
|
|
type = 0;
|
|
|
if(task_entity.getRunTask() == 0){//开始任务
|
|
|
buttonStr = "开始任务";
|
|
|
@@ -384,7 +360,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View,
|
|
|
loadTvAdp.setTaskState(type);
|
|
|
loadTvAdp.addTaskPreference(preference);
|
|
|
loadTvAdp.addTaskEty(task_entity);
|
|
|
- downLoad();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -444,100 +419,4 @@ public class DialogActivity extends Activity implements TaskDialogContract.View,
|
|
|
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+"%"+")");
|
|
|
- }
|
|
|
- }
|
|
|
}
|