|
@@ -9,18 +9,12 @@ 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.LayoutInflater;
|
|
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
-import android.view.ViewGroup;
|
|
|
|
|
import android.webkit.WebChromeClient;
|
|
import android.webkit.WebChromeClient;
|
|
|
import android.webkit.WebResourceRequest;
|
|
import android.webkit.WebResourceRequest;
|
|
|
import android.webkit.WebView;
|
|
import android.webkit.WebView;
|
|
|
import android.webkit.WebViewClient;
|
|
import android.webkit.WebViewClient;
|
|
|
-import android.widget.ArrayAdapter;
|
|
|
|
|
-import android.widget.BaseAdapter;
|
|
|
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
|
-import android.widget.ListView;
|
|
|
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
@@ -46,24 +40,16 @@ import com.sheep.gamegroup.view.adapter.TaskStateAdapter;
|
|
|
import com.sheep.gamegroup.view.customview.SProgress;
|
|
import com.sheep.gamegroup.view.customview.SProgress;
|
|
|
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.adapter.DownListAdapter;
|
|
|
|
|
-import com.sheep.jiuyan.samllsheep.base.BaseActivity;
|
|
|
|
|
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.download.DownloadViewHolder;
|
|
|
|
|
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 org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
-import org.xutils.HttpManager;
|
|
|
|
|
-import org.xutils.common.Callback;
|
|
|
|
|
-import org.xutils.common.task.PriorityExecutor;
|
|
|
|
|
import org.xutils.ex.DbException;
|
|
import org.xutils.ex.DbException;
|
|
|
-import org.xutils.http.HttpMethod;
|
|
|
|
|
-import org.xutils.http.RequestParams;
|
|
|
|
|
import org.xutils.x;
|
|
import org.xutils.x;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
@@ -115,7 +101,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
* 下载
|
|
* 下载
|
|
|
*/
|
|
*/
|
|
|
private DownLoadTvAdp loadTvAdp;
|
|
private DownLoadTvAdp loadTvAdp;
|
|
|
- private Callback.Cancelable cancelable;
|
|
|
|
|
|
|
+ private List<DownloadInfo> infoList = new ArrayList<>();
|
|
|
|
|
|
|
|
@Inject
|
|
@Inject
|
|
|
TaskDialogPresenter preference;
|
|
TaskDialogPresenter preference;
|
|
@@ -147,7 +133,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
setContentView(R.layout.download_item_dialog);
|
|
setContentView(R.layout.download_item_dialog);
|
|
|
ButterKnife.bind(this);
|
|
ButterKnife.bind(this);
|
|
|
activity = this;
|
|
activity = this;
|
|
|
- x.view().inject(this);
|
|
|
|
|
initViews();
|
|
initViews();
|
|
|
initDatas();
|
|
initDatas();
|
|
|
}
|
|
}
|
|
@@ -164,13 +149,18 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
dialogItemSizeTv.setText( task_entity.getPackage_size() + "M");
|
|
dialogItemSizeTv.setText( task_entity.getPackage_size() + "M");
|
|
|
isDownLoad = PackageUtil.isAppInstalled(SheepApp.mContext, task_entity.getPackage_names());
|
|
isDownLoad = PackageUtil.isAppInstalled(SheepApp.mContext, task_entity.getPackage_names());
|
|
|
|
|
|
|
|
- downLoadApk();
|
|
|
|
|
|
|
+ isHaveLoad();
|
|
|
|
|
+// downLoadApk();
|
|
|
/**
|
|
/**
|
|
|
* 下载
|
|
* 下载
|
|
|
*/
|
|
*/
|
|
|
- loadTvAdp = new DownLoadTvAdp(activity);
|
|
|
|
|
|
|
+ loadTvAdp = new DownLoadTvAdp(activity, infoList);
|
|
|
listview_down.setAdapter(loadTvAdp);
|
|
listview_down.setAdapter(loadTvAdp);
|
|
|
|
|
|
|
|
|
|
+ loadTvAdp.setTaskState(type);
|
|
|
|
|
+ loadTvAdp.addTaskPreference(preference);
|
|
|
|
|
+ loadTvAdp.addTaskEty(task_entity);
|
|
|
|
|
+
|
|
|
//Todo ok
|
|
//Todo ok
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("id",task_entity.getRelease_task_id());
|
|
jsonObject.put("id",task_entity.getRelease_task_id());
|
|
@@ -178,7 +168,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void initViews() {
|
|
|
|
|
|
|
+ private void initViews() {
|
|
|
|
|
|
|
|
// startStaskSprogress.setVisibility(View.GONE);
|
|
// startStaskSprogress.setVisibility(View.GONE);
|
|
|
task_entity = (TaskEty) getIntent().getSerializableExtra("task_entity");
|
|
task_entity = (TaskEty) getIntent().getSerializableExtra("task_entity");
|
|
@@ -277,7 +267,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
startStaskSprogress.setVisibility(View.VISIBLE);
|
|
startStaskSprogress.setVisibility(View.VISIBLE);
|
|
|
if (task_entity != null) {
|
|
if (task_entity != null) {
|
|
|
ClassFileHelper.getInstance().createSDDirection();
|
|
ClassFileHelper.getInstance().createSDDirection();
|
|
|
- final File mApkPath = new File(ClassFileHelper.DIR, task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX);
|
|
|
|
|
|
|
+ File mApkPath = new File(ClassFileHelper.DIR, task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX);
|
|
|
if (!mApkPath.exists()) {
|
|
if (!mApkPath.exists()) {
|
|
|
// new File(mApkPath.getAbsolutePath());
|
|
// new File(mApkPath.getAbsolutePath());
|
|
|
try{
|
|
try{
|
|
@@ -302,65 +292,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
downloadInfo.setPkgName(task_entity.getPackage_names());
|
|
downloadInfo.setPkgName(task_entity.getPackage_names());
|
|
|
MyDbManager.getInstance().saveOrUpdateUser(downloadInfo);//保存到数据库
|
|
MyDbManager.getInstance().saveOrUpdateUser(downloadInfo);//保存到数据库
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- //设置请求参数
|
|
|
|
|
- RequestParams params = new RequestParams(task_entity.getDownload_link());
|
|
|
|
|
- params.setAutoResume(true);//设置是否在下载是自动断点续传
|
|
|
|
|
- params.setAutoRename(false);//设置是否根据头信息自动命名文件
|
|
|
|
|
- params.setSaveFilePath(mApkPath.getAbsolutePath());
|
|
|
|
|
- params.setExecutor(new PriorityExecutor(2, true));//自定义线程池,有效的值范围[1, 3], 设置为3时, 可能阻塞图片加载.
|
|
|
|
|
- params.setCancelFast(true);//是否可以被立即停止.
|
|
|
|
|
- cancelable = x.http().get(params, new Callback.ProgressCallback<File>(){
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onSuccess(File file) {
|
|
|
|
|
- Log.e("-----下载","onSuccess");
|
|
|
|
|
- PackageUtil.installApk(getApplicationContext(), mApkPath.getAbsolutePath());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onError(Throwable throwable, boolean b) {
|
|
|
|
|
- Log.e("-----下载","onError--"+"throwable:"+throwable.getMessage()+",b:"+b);
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onCancelled(CancelledException e) {
|
|
|
|
|
- Log.e("-----下载","onCancelled");
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onFinished() {
|
|
|
|
|
- Log.e("-----下载","onFinished");
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onWaiting() {
|
|
|
|
|
- Log.e("-----下载","onWaiting");
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onStarted() {
|
|
|
|
|
- Log.e("-----下载","onStarted");
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onLoading(long total, long current, boolean b) {
|
|
|
|
|
- Log.e("-----下载","onLoading--total:"+total+",current:"+current+",b:"+b);
|
|
|
|
|
- Message message = new Message();
|
|
|
|
|
- message.what = 1;
|
|
|
|
|
- Bundle bundle = new Bundle();
|
|
|
|
|
- bundle.putLong("total", total);
|
|
|
|
|
- bundle.putLong("current", current);
|
|
|
|
|
- message.setData(bundle);
|
|
|
|
|
- handler.sendMessage(message);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
} else {
|
|
} else {
|
|
|
PackageUtil.installApk(getApplicationContext(), mApkPath.getAbsolutePath());
|
|
PackageUtil.installApk(getApplicationContext(), mApkPath.getAbsolutePath());
|
|
|
}
|
|
}
|
|
@@ -375,12 +306,13 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
/**
|
|
/**
|
|
|
* 判断apk是否下载过
|
|
* 判断apk是否下载过
|
|
|
*/
|
|
*/
|
|
|
- private void isHave(){
|
|
|
|
|
|
|
+ private DownloadInfo isHaveLoad(){
|
|
|
|
|
+ DownloadInfo downloadInfo = null;
|
|
|
if (task_entity != null) {
|
|
if (task_entity != null) {
|
|
|
ClassFileHelper.getInstance().createSDDirection();
|
|
ClassFileHelper.getInstance().createSDDirection();
|
|
|
File mApkPath = new File(ClassFileHelper.DIR, task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX);
|
|
File mApkPath = new File(ClassFileHelper.DIR, task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX);
|
|
|
if (!mApkPath.exists()) {
|
|
if (!mApkPath.exists()) {
|
|
|
- DownloadInfo downloadInfo = MyDbManager.getInstance().dbFindDownLoad(task_entity.getTask_name(), mApkPath.getAbsolutePath());
|
|
|
|
|
|
|
+ downloadInfo = MyDbManager.getInstance().dbFindDownLoad(task_entity.getTask_name(), mApkPath.getAbsolutePath());
|
|
|
if (downloadInfo == null) {
|
|
if (downloadInfo == null) {
|
|
|
downloadInfo = new DownloadInfo();
|
|
downloadInfo = new DownloadInfo();
|
|
|
downloadInfo.setUrl(task_entity.getDownload_link());
|
|
downloadInfo.setUrl(task_entity.getDownload_link());
|
|
@@ -393,10 +325,13 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
downloadInfo.setPkgName(task_entity.getPackage_names());
|
|
downloadInfo.setPkgName(task_entity.getPackage_names());
|
|
|
MyDbManager.getInstance().saveOrUpdateUser(downloadInfo);//保存到数据库
|
|
MyDbManager.getInstance().saveOrUpdateUser(downloadInfo);//保存到数据库
|
|
|
}else{
|
|
}else{
|
|
|
- start_task_tv.setText("继续下载");
|
|
|
|
|
|
|
+// start_task_tv.setText("继续下载");
|
|
|
}
|
|
}
|
|
|
|
|
+ infoList.clear();
|
|
|
|
|
+ infoList.add(downloadInfo);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ return downloadInfo;
|
|
|
}
|
|
}
|
|
|
/**
|
|
/**
|
|
|
* 去试玩
|
|
* 去试玩
|
|
@@ -448,7 +383,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
@Override
|
|
@Override
|
|
|
public void startTaskFailView(Object o) {
|
|
public void startTaskFailView(Object o) {
|
|
|
|
|
|
|
|
- G.showToast("开启任务失败");
|
|
|
|
|
|
|
+ G.showToast(((BaseMessage)o).getMsg()+ "");
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -481,9 +416,6 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
@Override
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
|
- if(cancelable != null){
|
|
|
|
|
- cancelable.cancel();
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|