|
|
@@ -1,12 +1,11 @@
|
|
|
package com.sheep.gamegroup.view.activity;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
+import android.content.Intent;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.os.Message;
|
|
|
-import android.preference.DialogPreference;
|
|
|
-import android.support.annotation.NonNull;
|
|
|
import android.support.annotation.Nullable;
|
|
|
import android.support.annotation.RequiresApi;
|
|
|
import android.util.Log;
|
|
|
@@ -17,7 +16,6 @@ import android.webkit.WebView;
|
|
|
import android.webkit.WebViewClient;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
|
-import android.widget.Toast;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
@@ -26,6 +24,7 @@ import com.bumptech.glide.Glide;
|
|
|
import com.bumptech.glide.request.RequestOptions;
|
|
|
import com.kfzs.duanduan.event.BigEvent;
|
|
|
import com.kfzs.duanduan.event.EventTypes;
|
|
|
+import com.kfzs.duanduan.services.KFDownloadServices;
|
|
|
import com.kfzs.duanduan.utils.dlg.DeviceUtils;
|
|
|
import com.sheep.gamegroup.di.components.DaggerTaskDialogComponent;
|
|
|
import com.sheep.gamegroup.di.modules.TaskDialogModule;
|
|
|
@@ -37,8 +36,7 @@ import com.sheep.gamegroup.presenter.TaskDialogPresenter;
|
|
|
import com.sheep.gamegroup.util.DeviceUtil;
|
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
|
import com.sheep.gamegroup.util.MyDbManager;
|
|
|
-import com.sheep.gamegroup.util.MyListview;
|
|
|
-import com.sheep.gamegroup.view.adapter.DownLoadTvAdp;
|
|
|
+import com.sheep.gamegroup.util.MyListview;;
|
|
|
import com.sheep.gamegroup.view.adapter.TaskStateAdapter;
|
|
|
import com.sheep.gamegroup.view.customview.SProgress;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
@@ -57,8 +55,6 @@ import org.wlf.filedownloader.FileDownloader;
|
|
|
import org.wlf.filedownloader.listener.OnDetectBigUrlFileListener;
|
|
|
import org.wlf.filedownloader.listener.OnDownloadFileChangeListener;
|
|
|
import org.wlf.filedownloader.listener.OnFileDownloadStatusListener;
|
|
|
-import org.xutils.ex.DbException;
|
|
|
-import org.xutils.x;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
|
@@ -83,8 +79,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
TextView dialogItemNameTv;
|
|
|
@BindView(R.id.dialog_item_size_tv)
|
|
|
TextView dialogItemSizeTv;
|
|
|
- @BindView(R.id.start_stask_sprogress)
|
|
|
- SProgress startStaskSprogress;
|
|
|
@BindView(R.id.doalog_item_get_rewards_tv)
|
|
|
TextView doalogItemGetRewardsTv;
|
|
|
@BindView(R.id.webview)
|
|
|
@@ -93,8 +87,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
TextView start_task_tv;
|
|
|
@BindView(R.id.listview)
|
|
|
MyListview listview;
|
|
|
- @BindView(R.id.listview_down)
|
|
|
- MyListview listview_down;
|
|
|
private TaskEty task_entity;
|
|
|
private List<TaskState> stateList = new ArrayList<>();//状态列表
|
|
|
private TaskStateAdapter stateAdapter;
|
|
|
@@ -106,11 +98,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
private boolean isDownLoad = false;//是否下载
|
|
|
private String buttonStr = "开始任务";//是否下载
|
|
|
private Activity activity;
|
|
|
- /**
|
|
|
- * 下载
|
|
|
- */
|
|
|
- private DownLoadTvAdp loadTvAdp;
|
|
|
- private List<DownloadInfo> infoList = new ArrayList<>();
|
|
|
+ Intent intentService;
|
|
|
|
|
|
@Inject
|
|
|
TaskDialogPresenter preference;
|
|
|
@@ -123,14 +111,12 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
case 0:
|
|
|
task_entity.setRunTask(1);
|
|
|
setBtnState();
|
|
|
- loadTvAdp.notifyDataSetChanged();
|
|
|
break;
|
|
|
case 1:
|
|
|
Bundle bundle = msg.getData();
|
|
|
long total = bundle.getLong("total");
|
|
|
long current = bundle.getLong("current");
|
|
|
|
|
|
- startStaskSprogress.setProgress((int) (current*100/total));
|
|
|
start_task_tv.setText((int) (current*100/total));
|
|
|
break;
|
|
|
}
|
|
|
@@ -143,6 +129,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
setContentView(R.layout.download_item_dialog);
|
|
|
ButterKnife.bind(this);
|
|
|
activity = this;
|
|
|
+ intentService = new Intent(activity, KFDownloadServices.class);
|
|
|
initViews();
|
|
|
initDatas();
|
|
|
doFiler();
|
|
|
@@ -161,11 +148,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
|
|
|
// isHaveLoad();
|
|
|
// downLoadApk();
|
|
|
- /**
|
|
|
- * 下载
|
|
|
- */
|
|
|
- loadTvAdp = new DownLoadTvAdp(activity, infoList);
|
|
|
- listview_down.setAdapter(loadTvAdp);
|
|
|
|
|
|
setBtnState();
|
|
|
|
|
|
@@ -178,7 +160,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
|
|
|
private void initViews() {
|
|
|
|
|
|
-// startStaskSprogress.setVisibility(View.GONE);
|
|
|
task_entity = (TaskEty) getIntent().getSerializableExtra("task_entity");
|
|
|
if (task_entity == null) {
|
|
|
finish();
|
|
|
@@ -209,7 +190,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
|
|
|
}
|
|
|
|
|
|
- @OnClick({R.id.doalog_item_get_rewards_tv, R.id.dialog_item_x, R.id.start_task_tv, R.id.start_stask_sprogress})
|
|
|
+ @OnClick({R.id.doalog_item_get_rewards_tv, R.id.dialog_item_x, R.id.start_task_tv})
|
|
|
public void onViewClicked(View view) {
|
|
|
switch (view.getId()) {
|
|
|
case R.id.doalog_item_get_rewards_tv:
|
|
|
@@ -223,21 +204,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
case R.id.start_task_tv:
|
|
|
startStask();
|
|
|
break;
|
|
|
- case R.id.start_stask_sprogress:
|
|
|
-// refresh();
|
|
|
- try {
|
|
|
- downloadManager.startDownload(
|
|
|
- downloadInfo.getPkgName(),
|
|
|
- downloadInfo.getUrl(),
|
|
|
- downloadInfo.getLabel(),
|
|
|
- downloadInfo.getFileSavePath(), "",
|
|
|
- downloadInfo.isAutoResume(),
|
|
|
- downloadInfo.isAutoRename(),
|
|
|
- null);
|
|
|
- } catch (DbException ex) {
|
|
|
- Toast.makeText(x.app(), "添加下载失败", Toast.LENGTH_LONG).show();
|
|
|
- }
|
|
|
- break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -274,51 +240,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 下载游戏
|
|
|
- */
|
|
|
- private void downLoadApk(){
|
|
|
-
|
|
|
- start_task_tv.setVisibility(View.GONE);
|
|
|
- startStaskSprogress.setVisibility(View.VISIBLE);
|
|
|
- if (task_entity != null) {
|
|
|
- ClassFileHelper.getInstance().createSDDirection();
|
|
|
- File mApkPath = new File(ClassFileHelper.DIR, task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX);
|
|
|
- if (!mApkPath.exists()) {
|
|
|
-// new File(mApkPath.getAbsolutePath());
|
|
|
- try{
|
|
|
-
|
|
|
- downloadInfo = DownloadManager.getInstance().startDownloadOne(task_entity.getPackage_names(),
|
|
|
- task_entity.getDownload_link(), task_entity.getTask_name(),
|
|
|
- mApkPath.getAbsolutePath(), task_entity.getIcon(), true, false, null);
|
|
|
- return;
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- DownloadInfo 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);//保存到数据库
|
|
|
- }
|
|
|
- } else {
|
|
|
- PackageUtil.installApk(getApplicationContext(), mApkPath.getAbsolutePath());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- /**
|
|
|
- * 下载
|
|
|
- */
|
|
|
-
|
|
|
- }
|
|
|
- /**
|
|
|
* 判断apk是否下载过
|
|
|
*/
|
|
|
private DownloadInfo isHaveLoad(){
|
|
|
@@ -342,8 +263,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
}else{
|
|
|
// start_task_tv.setText("继续下载");
|
|
|
}
|
|
|
- infoList.clear();
|
|
|
- infoList.add(downloadInfo);
|
|
|
}
|
|
|
}
|
|
|
return downloadInfo;
|
|
|
@@ -373,10 +292,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
}
|
|
|
}
|
|
|
start_task_tv.setText(buttonStr);
|
|
|
-
|
|
|
- loadTvAdp.setTaskState(type);
|
|
|
- loadTvAdp.addTaskPreference(preference);
|
|
|
- loadTvAdp.addTaskEty(task_entity);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -506,10 +421,23 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
private void doFiler(){
|
|
|
FileDownloader.registerDownloadStatusListener(onFileDownloadStatusListener);
|
|
|
FileDownloader.registerDownloadFileChangeListener(mOnDownloadFileChangeListener);
|
|
|
+
|
|
|
+ try{
|
|
|
+
|
|
|
+// intent.setAction("ITOP.MOBILE.SIMPLE.SERVICE.SENSORSERVICE");
|
|
|
+ stopService(intentService);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
private void unFiler(){
|
|
|
FileDownloader.unregisterDownloadStatusListener(onFileDownloadStatusListener);
|
|
|
FileDownloader.unregisterDownloadFileChangeListener(mOnDownloadFileChangeListener);
|
|
|
+ try {
|
|
|
+ startService(intentService);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
private void startFiler(){
|
|
|
ClassFileHelper.getInstance().createSDDirection();
|