|
@@ -16,37 +16,56 @@ import android.widget.LinearLayout;
|
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.arialyy.annotations.Download;
|
|
|
|
|
+import com.arialyy.aria.core.Aria;
|
|
|
|
|
+import com.arialyy.aria.core.download.DownloadTarget;
|
|
|
|
|
+import com.arialyy.aria.core.download.DownloadTask;
|
|
|
|
|
+import com.arialyy.aria.core.inf.IEntity;
|
|
|
import com.bumptech.glide.Glide;
|
|
import com.bumptech.glide.Glide;
|
|
|
import com.bumptech.glide.request.RequestOptions;
|
|
import com.bumptech.glide.request.RequestOptions;
|
|
|
import com.kfzs.duanduan.datashare.DDProviderHelper;
|
|
import com.kfzs.duanduan.datashare.DDProviderHelper;
|
|
|
import com.kfzs.duanduan.datashare.provider.download.DownLoadInfo;
|
|
import com.kfzs.duanduan.datashare.provider.download.DownLoadInfo;
|
|
|
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.services.DownloadTaskService;
|
|
|
import com.sheep.gamegroup.di.components.DaggerTaskDetailComponent;
|
|
import com.sheep.gamegroup.di.components.DaggerTaskDetailComponent;
|
|
|
import com.sheep.gamegroup.di.modules.TaskDetailModule;
|
|
import com.sheep.gamegroup.di.modules.TaskDetailModule;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.DialogEntity;
|
|
|
import com.sheep.gamegroup.model.entity.TaskAcceptedEty;
|
|
import com.sheep.gamegroup.model.entity.TaskAcceptedEty;
|
|
|
import com.sheep.gamegroup.model.entity.TaskEty;
|
|
import com.sheep.gamegroup.model.entity.TaskEty;
|
|
|
import com.sheep.gamegroup.model.entity.TaskReleaseEty;
|
|
import com.sheep.gamegroup.model.entity.TaskReleaseEty;
|
|
|
|
|
+import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
import com.sheep.gamegroup.presenter.TaskDetailContract;
|
|
import com.sheep.gamegroup.presenter.TaskDetailContract;
|
|
|
import com.sheep.gamegroup.presenter.TaskDetailPresenter;
|
|
import com.sheep.gamegroup.presenter.TaskDetailPresenter;
|
|
|
|
|
+import com.sheep.gamegroup.util.CommonUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.DeviceUtil;
|
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
|
import com.sheep.gamegroup.util.TimeUtil;
|
|
import com.sheep.gamegroup.util.TimeUtil;
|
|
|
import com.sheep.gamegroup.util.UMConfigUtils;
|
|
import com.sheep.gamegroup.util.UMConfigUtils;
|
|
|
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.base.AbsChooseImageActivity;
|
|
import com.sheep.jiuyan.samllsheep.base.AbsChooseImageActivity;
|
|
|
|
|
+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.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
|
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
|
+
|
|
|
import javax.inject.Inject;
|
|
import javax.inject.Inject;
|
|
|
|
|
|
|
|
import butterknife.BindView;
|
|
import butterknife.BindView;
|
|
|
import butterknife.ButterKnife;
|
|
import butterknife.ButterKnife;
|
|
|
import butterknife.OnClick;
|
|
import butterknife.OnClick;
|
|
|
|
|
+import go.kfzssafe.Kfzssafe;
|
|
|
|
|
+import me.iwf.photopicker.PhotoPicker;
|
|
|
|
|
+import rx.android.schedulers.AndroidSchedulers;
|
|
|
|
|
+import rx.schedulers.Schedulers;
|
|
|
|
|
+
|
|
|
|
|
+import static com.sheep.jiuyan.samllsheep.utils.ClassFileHelper.DIR;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 任务详情页面
|
|
* 任务详情页面
|
|
@@ -82,8 +101,13 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
|
|
|
private TaskEty taskEty;
|
|
private TaskEty taskEty;
|
|
|
private TaskAcceptedEty task_accepted_entity;
|
|
private TaskAcceptedEty task_accepted_entity;
|
|
|
|
|
|
|
|
|
|
+ //通过task_id找
|
|
|
|
|
+ private TaskReleaseEty taskReleaseEty;
|
|
|
|
|
+
|
|
|
private int taskId = -1;
|
|
private int taskId = -1;
|
|
|
|
|
|
|
|
|
|
+ private int type;//-1:开始任务 1:下载 2:安装 3:打开 10:打开H5
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
protected int getLayoutId() {
|
|
@@ -104,6 +128,8 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
|
|
|
TitleBarUtils.getInstance()
|
|
TitleBarUtils.getInstance()
|
|
|
.setTitle(activity, "任务详情")
|
|
.setTitle(activity, "任务详情")
|
|
|
.setTitleFinish(activity);
|
|
.setTitleFinish(activity);
|
|
|
|
|
+ Aria.download(this).register();
|
|
|
|
|
+ mDownloadTaskService = new DownloadTaskService(this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -188,6 +214,123 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void initWigget(){
|
|
|
|
|
+ taskEty = taskReleaseEty.getTask();
|
|
|
|
|
+ downLoadInfo = mDownloadTaskService.getDownloadTaskByUrl(taskEty);
|
|
|
|
|
+ webText.setWebChromeClient(new WebChromeClient(){
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+ webText.getSettings().setJavaScriptEnabled(true);
|
|
|
|
|
+ webText.setWebViewClient(new WebViewClient(){
|
|
|
|
|
+ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
|
|
|
|
+ view.loadDataWithBaseURL(null,request.getUrl().toString(), "text/html", "utf-8", null);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ //封装头文件
|
|
|
|
|
+ String sHead= "<html><head><meta name=\"viewport\" content=\"width=device-width, " +
|
|
|
|
|
+ "initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes\" />"+
|
|
|
|
|
+ "<style>img{max-width:100% !important;height:auto !important;}</style>"
|
|
|
|
|
+ +"<style>body{max-width:100% !important;}</style>"+"</head><body>";
|
|
|
|
|
+ webText.loadDataWithBaseURL(null,sHead + taskEty.getDesc() + "</body></html>", "text/html", "utf-8", null);
|
|
|
|
|
+ nameTv.setText(taskReleaseEty.getName()+"");
|
|
|
|
|
+ priceTv.setText("+"+ taskReleaseEty.getBonus() +"元");
|
|
|
|
|
+ dateTv.setText(TimeUtil.getDate(TimeUtil.FORMAT, Long.valueOf(taskEty.getUpdate_time()))+"");
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ Glide.with(SheepApp.mContext)
|
|
|
|
|
+ .load(taskEty.getIcon())
|
|
|
|
|
+ .apply(new RequestOptions().placeholder(R.drawable.icon)
|
|
|
|
|
+ .dontAnimate())
|
|
|
|
|
+ .into(iconIv);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ bottom_btn_layout.setVisibility(View.VISIBLE);
|
|
|
|
|
+ detailTaskTv.setVisibility(View.INVISIBLE);
|
|
|
|
|
+ if (!taskReleaseEty.isIs_running() || taskEty.getInspect_type() == 1){
|
|
|
|
|
+ btnUpImag.setVisibility(View.GONE);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ taskEty.setRunTask(1);
|
|
|
|
|
+ btnUpImag.setVisibility(View.VISIBLE);
|
|
|
|
|
+ }
|
|
|
|
|
+ switch (taskEty.getTask_type()){
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ if(taskReleaseEty.isIs_running()){
|
|
|
|
|
+ type = 0;
|
|
|
|
|
+ if (PackageUtil.isAppInstalled(SheepApp.mContext, taskEty.getPackage_names())) {
|
|
|
|
|
+ type = 3;
|
|
|
|
|
+ btnTaskItem.setText("开始游戏");
|
|
|
|
|
+ }else if(!TextUtils.isEmpty(PackageUtil.isExistsFile(activity, taskEty.getPackage_names(), ""))){
|
|
|
|
|
+ type = 2;
|
|
|
|
|
+ btnTaskItem.setText("开始安装");
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ DownLoadInfo downLoadInfo = DDProviderHelper.getInstance()
|
|
|
|
|
+ .getDownloadTaskToPackname(activity, taskEty.getPackage_names());
|
|
|
|
|
+ if(downLoadInfo != null && !TextUtils.isEmpty(downLoadInfo.getMApkPath())){
|
|
|
|
|
+ type = 2;
|
|
|
|
|
+ btnTaskItem.setText("开始安装");
|
|
|
|
|
+ }else {
|
|
|
|
|
+ type = 1;
|
|
|
|
|
+ btnTaskItem.setText("下载游戏");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {
|
|
|
|
|
+ type = -1;
|
|
|
|
|
+ btnTaskItem.setText("领取任务");
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ btnTaskItem.setText("信用卡注册");
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 3:
|
|
|
|
|
+ if(taskReleaseEty.isIs_running()){
|
|
|
|
|
+ type = 0;
|
|
|
|
|
+ if (PackageUtil.isAppInstalled(SheepApp.mContext, taskEty.getPackage_names())) {
|
|
|
|
|
+ type = 3;
|
|
|
|
|
+ btnTaskItem.setText("打开应用");
|
|
|
|
|
+ }else if(!TextUtils.isEmpty(PackageUtil.isExistsFile(activity, taskEty.getPackage_names(), ""))){
|
|
|
|
|
+ type = 2;
|
|
|
|
|
+ btnTaskItem.setText("开始安装");
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ DownLoadInfo downLoadInfo = DDProviderHelper.getInstance()
|
|
|
|
|
+ .getDownloadTaskToPackname(activity, taskEty.getPackage_names());
|
|
|
|
|
+ if(downLoadInfo != null && !TextUtils.isEmpty(downLoadInfo.getMApkPath())){
|
|
|
|
|
+ type = 2;
|
|
|
|
|
+ btnTaskItem.setText("开始安装");
|
|
|
|
|
+ }else {
|
|
|
|
|
+ type = 1;
|
|
|
|
|
+ btnTaskItem.setText("下载应用");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {
|
|
|
|
|
+ type = -1;
|
|
|
|
|
+ btnTaskItem.setText("领取任务");
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 4:
|
|
|
|
|
+ if(taskReleaseEty.isIs_running()){
|
|
|
|
|
+ type = 10;
|
|
|
|
|
+ btnTaskItem.setText("开始任务");
|
|
|
|
|
+ }else {
|
|
|
|
|
+ type = -1;
|
|
|
|
|
+ btnTaskItem.setText("领取任务");
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+// if(taskEty.getTask_type() == 2){
|
|
|
|
|
+// btnTaskItem.setText("信用卡注册");
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+ taskSchedule();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
@@ -195,6 +338,11 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
|
|
|
ButterKnife.bind(this);
|
|
ButterKnife.bind(this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 下载模块修改
|
|
|
|
|
+ */
|
|
|
|
|
+ private DownloadTaskService mDownloadTaskService;
|
|
|
|
|
+ DownLoadInfo downLoadInfo;
|
|
|
@OnClick({R.id.detail_task_tv, R.id.web_text, R.id.ll_infos, R.id.btn_task_item, R.id.btn_up_imag})
|
|
@OnClick({R.id.detail_task_tv, R.id.web_text, R.id.ll_infos, R.id.btn_task_item, R.id.btn_up_imag})
|
|
|
public void onViewClicked(View view) {
|
|
public void onViewClicked(View view) {
|
|
|
switch (view.getId()) {
|
|
switch (view.getId()) {
|
|
@@ -210,14 +358,57 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
|
|
|
case R.id.ll_infos:
|
|
case R.id.ll_infos:
|
|
|
break;
|
|
break;
|
|
|
case R.id.btn_task_item:
|
|
case R.id.btn_task_item:
|
|
|
- if (PackageUtil.isAppInstalled(SheepApp.mContext, taskEty.getPackage_names())) {
|
|
|
|
|
- PackageUtil.startApp(SheepApp.mContext, taskEty.getPackage_names());
|
|
|
|
|
- }else if(!TextUtils.isEmpty(PackageUtil.isExistsFile(activity, taskEty.getPackage_names(), ""))){
|
|
|
|
|
- PackageUtil.installApk(SheepApp.mContext, PackageUtil.isExistsFile(activity, taskEty.getPackage_names(), ""));
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- Jump2View.getInstance().goDialogActivityView(activity, taskEty, task_accepted_entity);
|
|
|
|
|
- UMConfigUtils.onEvent(UMConfigUtils.Event.TASK_DOWNLOAD);
|
|
|
|
|
|
|
+ switch (type){
|
|
|
|
|
+ case -1:
|
|
|
|
|
+ if(taskReleaseEty.getAccepted_task_id() > 0){
|
|
|
|
|
+ Jump2View.getInstance()
|
|
|
|
|
+ .goNoticeAct(activity, new DialogEntity(null,
|
|
|
|
|
+ "是否放弃正在运行中的任务?",
|
|
|
|
|
+ "是",
|
|
|
|
|
+ "否",
|
|
|
|
|
+ null));
|
|
|
|
|
+ }else {
|
|
|
|
|
+ acceptedTask();
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 1://开始下载
|
|
|
|
|
+
|
|
|
|
|
+ DownloadTarget task = null;
|
|
|
|
|
+ if(TextUtils.isEmpty(taskReleaseEty.getTask().getDownload_link()) || !taskReleaseEty.getTask().getDownload_link().contains("http")){
|
|
|
|
|
+ G.showToast("下载地址错误!");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ task = Aria.download(this).load(taskReleaseEty.getTask().getDownload_link());
|
|
|
|
|
+
|
|
|
|
|
+ String filePath = DIR+ File.separator+taskReleaseEty.getTask().getPackage_names()+ ClassFileHelper.FILE_SUFFIX;
|
|
|
|
|
+ if(task.getTaskState() == IEntity.STATE_RUNNING){
|
|
|
|
|
+ task.stop();
|
|
|
|
|
+ } else if(task.getTaskState() == IEntity.STATE_FAIL){
|
|
|
|
|
+ task.cancel(true);
|
|
|
|
|
+ task.resetState();
|
|
|
|
|
+ task.removeRecord();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ task.setFilePath(filePath);
|
|
|
|
|
+ task.start();
|
|
|
|
|
+ }
|
|
|
|
|
+ if(mDownloadTaskService.addDownloadTask(downLoadInfo)){
|
|
|
|
|
+ //发送红点信息
|
|
|
|
|
+ EventBus.getDefault().post(BigEvent.get().setEventTypes(EventTypes.TIPS_DOWN_ICON));
|
|
|
|
|
+ }
|
|
|
|
|
+ UMConfigUtils.onEvent(UMConfigUtils.Event.TASK_DOWNLOAD);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ PackageUtil.installApk(SheepApp.mContext, PackageUtil.isExistsFile(activity, taskEty.getPackage_names(), ""));
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 3:
|
|
|
|
|
+ PackageUtil.startApp(SheepApp.mContext, taskEty.getPackage_names());
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 4:
|
|
|
|
|
+ if(!TextUtils.isEmpty(taskEty.getExt())){
|
|
|
|
|
+ Jump2View.getInstance()
|
|
|
|
|
+ .goWebview(activity, taskEty.getExt());
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case R.id.btn_up_imag:
|
|
case R.id.btn_up_imag:
|
|
@@ -239,10 +430,10 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
|
|
|
if(taskEty.getTask_type() == 2){//信用卡
|
|
if(taskEty.getTask_type() == 2){//信用卡
|
|
|
llInfos.addView(getStep("信用卡注册", "待完成", 0));
|
|
llInfos.addView(getStep("信用卡注册", "待完成", 0));
|
|
|
}else if (PackageUtil.isAppInstalled(SheepApp.mContext, taskEty.getPackage_names())) {
|
|
}else if (PackageUtil.isAppInstalled(SheepApp.mContext, taskEty.getPackage_names())) {
|
|
|
- llInfos.addView(getStep("下载游戏", "已完成", 0));
|
|
|
|
|
|
|
+ llInfos.addView(getStep("APP下载", "已完成", 0));
|
|
|
llInfos.addView(getStep("完成任务", "进行中", 1));
|
|
llInfos.addView(getStep("完成任务", "进行中", 1));
|
|
|
} else {
|
|
} else {
|
|
|
- llInfos.addView(getStep("下载游戏", "待完成", 2));
|
|
|
|
|
|
|
+ llInfos.addView(getStep("APP下载", "待完成", 2));
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
llInfos.addView(getStep("领取任务", "待完成", 2));
|
|
llInfos.addView(getStep("领取任务", "待完成", 2));
|
|
@@ -299,8 +490,8 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void taskDescSuccess(BaseMessage baseMessage) {
|
|
public void taskDescSuccess(BaseMessage baseMessage) {
|
|
|
- TaskReleaseEty taskReleaseEty = JSONObject.parseObject(JSONObject.toJSONString(baseMessage.getData()), TaskReleaseEty.class);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ taskReleaseEty = JSONObject.parseObject(JSONObject.toJSONString(baseMessage.getData()), TaskReleaseEty.class);
|
|
|
|
|
+ initWigget();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -337,4 +528,113 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
|
|
|
protected void onGetNetImageUrl(String url) {
|
|
protected void onGetNetImageUrl(String url) {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
+ if(requestCode == 0 && resultCode == RESULT_OK){
|
|
|
|
|
+ if(taskReleaseEty.getAccepted_task_id() > 0){
|
|
|
|
|
+ showProgress(true);
|
|
|
|
|
+ SheepApp.getInstance()
|
|
|
|
|
+ .getNetComponent()
|
|
|
|
|
+ .getApiService()
|
|
|
|
|
+ .giveUpTask(taskReleaseEty.getAccepted_task_id())
|
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
|
|
+ hideProgress();
|
|
|
|
|
+ G.showToast(TextUtils.isEmpty(baseMessage.getMsg()) ? "服务器错误,请稍候再试" : baseMessage.getMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
+
|
|
|
|
|
+ acceptedTask();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 领取任务
|
|
|
|
|
+ */
|
|
|
|
|
+ private void acceptedTask(){
|
|
|
|
|
+ hideProgress();
|
|
|
|
|
+ showProgress(true);
|
|
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
|
|
+ object.put("device_id", DeviceUtil.getDeviceId(activity));
|
|
|
|
|
+ object.put("release_task_id", Integer.valueOf(taskReleaseEty.getId()+""));
|
|
|
|
|
+ SheepApp.getInstance()
|
|
|
|
|
+ .getNetComponent()
|
|
|
|
|
+ .getApiService()
|
|
|
|
|
+ .acceptedTask(object)
|
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
|
|
+ hideProgress();
|
|
|
|
|
+ G.showToast(TextUtils.isEmpty(baseMessage.getMsg()) ? "服务器错误,请稍候再试" : baseMessage.getMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
+ hideProgress();
|
|
|
|
|
+ initData();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ @Download.onPre void onPre(DownloadTask task) {
|
|
|
|
|
+ if(task.getKey().equals(taskEty.getDownload_link())) {
|
|
|
|
|
+ btnTaskItem.setText("准备下载中");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ @Download.onTaskStart void taskStart(DownloadTask task) {
|
|
|
|
|
+ if(task.getKey().equals(taskEty.getDownload_link())) {
|
|
|
|
|
+ btnTaskItem.setText("开始下载中");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ @Download.onTaskResume void taskResume(DownloadTask task) {
|
|
|
|
|
+ if(task.getKey().equals(taskEty.getDownload_link())) {
|
|
|
|
|
+ btnTaskItem.setText("恢复下载中");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //在这里处理任务执行中的状态,如进度进度条的刷新
|
|
|
|
|
+ @Download.onTaskRunning protected void running(DownloadTask task) {
|
|
|
|
|
+ if(task.getKey().equals(taskEty.getDownload_link())) {
|
|
|
|
|
+ int p = task.getPercent(); //任务进度百分比
|
|
|
|
|
+ String speed = task.getConvertSpeed(); //转换单位后的下载速度,单位转换需要在配置文件中打开
|
|
|
|
|
+ long speed1 = task.getSpeed(); //原始byte长度速度
|
|
|
|
|
+ btnTaskItem.setText(p + "%");
|
|
|
|
|
+ System.out.println("Aria p " + p + ", speed = " + speed);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Download.onTaskStop void taskStop(DownloadTask task) {
|
|
|
|
|
+ if(task.getKey().equals(taskEty.getDownload_link())) {
|
|
|
|
|
+ btnTaskItem.setText(CommonUtil.CONTINUE_DOWNLOAD);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Download.onTaskCancel void taskCancel(DownloadTask task) {
|
|
|
|
|
+ if(task.getKey().equals(taskEty.getDownload_link())) {
|
|
|
|
|
+ btnTaskItem.setText("已经取消");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Download.onTaskFail void taskFail(DownloadTask task) {
|
|
|
|
|
+ if(task.getKey().equals(taskEty.getDownload_link())) {
|
|
|
|
|
+ btnTaskItem.setText(CommonUtil.FAIL_DOWNLOAD);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Download.onTaskComplete void taskComplete(DownloadTask task) {
|
|
|
|
|
+ if(task.getKey().equals(taskEty.getDownload_link())) {
|
|
|
|
|
+ //在这里处理任务完成的状态
|
|
|
|
|
+ btnTaskItem.setText(CommonUtil.START_INSTALL);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|