|
|
@@ -9,6 +9,7 @@ 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.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
@@ -23,17 +24,22 @@ import android.widget.ListView;
|
|
|
import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
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.sheep.gamegroup.di.components.DaggerTaskDialogComponent;
|
|
|
import com.sheep.gamegroup.di.modules.TaskDialogModule;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
import com.sheep.gamegroup.model.entity.TaskEty;
|
|
|
+import com.sheep.gamegroup.model.entity.TaskState;
|
|
|
import com.sheep.gamegroup.presenter.TaskDialogContract;
|
|
|
import com.sheep.gamegroup.presenter.TaskDialogPresenter;
|
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
|
import com.sheep.gamegroup.util.MyDbManager;
|
|
|
+import com.sheep.gamegroup.view.adapter.TaskStateAdapter;
|
|
|
import com.sheep.gamegroup.view.customview.SProgress;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
@@ -48,6 +54,7 @@ import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
|
|
|
|
|
|
|
|
|
+import org.greenrobot.eventbus.EventBus;
|
|
|
import org.xutils.HttpManager;
|
|
|
import org.xutils.common.Callback;
|
|
|
import org.xutils.common.task.PriorityExecutor;
|
|
|
@@ -57,6 +64,8 @@ import org.xutils.http.RequestParams;
|
|
|
import org.xutils.x;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
|
@@ -88,6 +97,8 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
@BindView(R.id.listview)
|
|
|
ListView listview;
|
|
|
private TaskEty task_entity;
|
|
|
+ private List<TaskState> stateList = new ArrayList<>();//状态列表
|
|
|
+ private TaskStateAdapter stateAdapter;
|
|
|
|
|
|
private DownloadManager downloadManager;
|
|
|
DownloadInfo downloadInfo;
|
|
|
@@ -112,6 +123,14 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
task_entity.setRunTask(1);
|
|
|
setBtnState();
|
|
|
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;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
@@ -135,7 +154,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
.placeholder(R.mipmap.ic_launcher)
|
|
|
.dontAnimate()
|
|
|
.into(dialogItemIconIv);
|
|
|
- dialogItemNameTv.setText(task_entity.getTask_name());
|
|
|
+ dialogItemNameTv.setText(task_entity.getName());
|
|
|
dialogItemSizeTv.setText( task_entity.getPackage_size() + "M");
|
|
|
isDownLoad = PackageUtil.isAppInstalled(SheepApp.mContext, task_entity.getPackage_names());
|
|
|
//Todo ok
|
|
|
@@ -172,94 +191,10 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- listview.setAdapter(new BaseAdapter(){
|
|
|
- @Override
|
|
|
- public int getCount() {
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Object getItem(int position) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public long getItemId(int position) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- @NonNull
|
|
|
- @Override
|
|
|
- public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
|
|
- convertView = LayoutInflater.from(activity).inflate(R.layout.try_makemoney_item, null);
|
|
|
- return convertView;
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
- /**
|
|
|
- * 下载
|
|
|
- */
|
|
|
- ClassFileHelper.getInstance().createSDDirection();
|
|
|
- File mApkPath = new File(ClassFileHelper.DIR, task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX);
|
|
|
- if (!mApkPath.exists()) {
|
|
|
- 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);
|
|
|
-// new DownloadItemViewHolder(null, downloadInfo);
|
|
|
- startStaskSprogress.setProgress(downloadInfo.getProgress());
|
|
|
- } catch (DbException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- } else {
|
|
|
- PackageUtil.installApk(getApplicationContext(), mApkPath.getAbsolutePath());
|
|
|
- }
|
|
|
- String fileSavePath = new File(mApkPath.getAbsolutePath()).getAbsolutePath();
|
|
|
- DownloadInfo downloadInfo = MyDbManager.getInstance().dbFindDownLoad(task_entity.getTask_name(), mApkPath.getAbsolutePath());
|
|
|
- //设置请求参数
|
|
|
- RequestParams params = new RequestParams(task_entity.getDownload_link());
|
|
|
- params.setAutoResume(true);//设置是否在下载是自动断点续传
|
|
|
- params.setAutoRename(false);//设置是否根据头信息自动命名文件
|
|
|
- params.setSaveFilePath("/sdcard/xutils/xUtils_1.avi");
|
|
|
- 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) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onError(Throwable throwable, boolean b) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onCancelled(CancelledException e) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onFinished() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onWaiting() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onStarted() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onLoading(long l, long l1, boolean b) {
|
|
|
+ stateAdapter = new TaskStateAdapter(activity, stateList);
|
|
|
+ listview.setAdapter(stateAdapter);
|
|
|
+ stateAdapter.notifyDataSetChanged();
|
|
|
|
|
|
- }
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
@OnClick({R.id.doalog_item_get_rewards_tv, R.id.dialog_item_x, R.id.start_task_tv, R.id.start_stask_sprogress})
|
|
|
@@ -329,18 +264,114 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
ClassFileHelper.getInstance().createSDDirection();
|
|
|
File mApkPath = new File(ClassFileHelper.DIR, task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX);
|
|
|
if (!mApkPath.exists()) {
|
|
|
- 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);
|
|
|
-// new DownloadItemViewHolder(null, downloadInfo);
|
|
|
- startStaskSprogress.setProgress(downloadInfo.getProgress());
|
|
|
- } catch (DbException e) {
|
|
|
- e.printStackTrace();
|
|
|
+// new File(mApkPath.getAbsolutePath());
|
|
|
+ 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);//保存到数据库
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ //设置请求参数
|
|
|
+ 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 {
|
|
|
PackageUtil.installApk(getApplicationContext(), mApkPath.getAbsolutePath());
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 下载
|
|
|
+ */
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 判断apk是否下载过
|
|
|
+ */
|
|
|
+ private void isHave(){
|
|
|
+ if (task_entity != null) {
|
|
|
+ ClassFileHelper.getInstance().createSDDirection();
|
|
|
+ File mApkPath = new File(ClassFileHelper.DIR, task_entity.getTask_name() + ClassFileHelper.FILE_SUFFIX);
|
|
|
+ if (!mApkPath.exists()) {
|
|
|
+ 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{
|
|
|
+ start_task_tv.setText("继续下载");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
@@ -397,6 +428,23 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
@Override
|
|
|
public void getStateSuccess(Object o) {
|
|
|
|
|
|
+ if(o == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ BaseMessage baseMessage = (BaseMessage) o;
|
|
|
+
|
|
|
+ List<TaskState> stateList = JSONArray.parseArray(JSONArray.toJSONString(baseMessage.getData() +""), TaskState.class);
|
|
|
+
|
|
|
+ if(stateList != null && stateList.size()>0){
|
|
|
+ this.stateList.clear();
|
|
|
+ this.stateList.addAll(stateList);
|
|
|
+
|
|
|
+ stateAdapter.notifyDataSetChanged();
|
|
|
+
|
|
|
+ EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.ONFRESH_TRYMAKEMANY_PAGE));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -404,4 +452,11 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ if(cancelable != null){
|
|
|
+ cancelable.cancel();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|