|
|
@@ -0,0 +1,339 @@
|
|
|
+package com.sheep.gamegroup.view.activity;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Intent;
|
|
|
+import android.database.Cursor;
|
|
|
+import android.net.Uri;
|
|
|
+import android.os.Build;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.provider.MediaStore;
|
|
|
+import android.support.annotation.RequiresApi;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.View;
|
|
|
+import android.webkit.WebChromeClient;
|
|
|
+import android.webkit.WebResourceRequest;
|
|
|
+import android.webkit.WebView;
|
|
|
+import android.webkit.WebViewClient;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.kfzs.appstore.utils.string.HexUtils;
|
|
|
+import com.kfzs.duanduan.react.upfile.UpFileListener;
|
|
|
+import com.kfzs.duanduan.react.upfile.UpFileUtils;
|
|
|
+import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
+import com.sheep.gamegroup.di.components.DaggerTaskDetailComponent;
|
|
|
+import com.sheep.gamegroup.di.modules.TaskDetailModule;
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
+import com.sheep.gamegroup.model.entity.TaskEty;
|
|
|
+import com.sheep.gamegroup.model.entity.UploadResult;
|
|
|
+import com.sheep.gamegroup.presenter.TaskDetailContract;
|
|
|
+import com.sheep.gamegroup.presenter.TaskDetailPresenter;
|
|
|
+import com.sheep.gamegroup.util.Jump2View;
|
|
|
+import com.sheep.gamegroup.view.dialog.DialogShowLoading;
|
|
|
+import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
+import com.sheep.jiuyan.samllsheep.page.WebActivity;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+
|
|
|
+import javax.inject.Inject;
|
|
|
+
|
|
|
+import butterknife.BindView;
|
|
|
+import butterknife.ButterKnife;
|
|
|
+import butterknife.OnClick;
|
|
|
+import go.kfzssafe.Kfzssafe;
|
|
|
+import me.iwf.photopicker.PhotoPicker;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 任务详情页面
|
|
|
+ * Created by ljy on 2018/4/2.
|
|
|
+ */
|
|
|
+
|
|
|
+public class TaskDetailAct extends BaseActivity implements TaskDetailContract.View, UpFileListener {
|
|
|
+
|
|
|
+ @BindView(R.id.icon_iv)
|
|
|
+ ImageView iconIv;
|
|
|
+ @BindView(R.id.name_tv)
|
|
|
+ TextView nameTv;
|
|
|
+ @BindView(R.id.date_tv)
|
|
|
+ TextView dateTv;
|
|
|
+ @BindView(R.id.price_tv)
|
|
|
+ TextView priceTv;
|
|
|
+ @BindView(R.id.detail_task_tv)
|
|
|
+ TextView detailTaskTv;
|
|
|
+ @BindView(R.id.web_text)
|
|
|
+ WebView webText;
|
|
|
+ @BindView(R.id.ll_infos)
|
|
|
+ LinearLayout llInfos;
|
|
|
+ @BindView(R.id.btn_task_item)
|
|
|
+ TextView btnTaskItem;
|
|
|
+ @BindView(R.id.btn_up_imag)
|
|
|
+ TextView btnUpImag;
|
|
|
+ @BindView(R.id.bottom_btn_layout)
|
|
|
+ LinearLayout bottom_btn_layout;
|
|
|
+ private Activity activity;
|
|
|
+ @Inject
|
|
|
+ TaskDetailPresenter presenter;
|
|
|
+
|
|
|
+ private TaskEty taskEty;
|
|
|
+ private DialogShowLoading dialogShowLoading;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传进度
|
|
|
+ */
|
|
|
+ private boolean isUpload = true;
|
|
|
+ public void showChooseDialog() {
|
|
|
+ showChooseDialog(true, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void showChooseDialog(boolean isCrop, boolean isUpload) {
|
|
|
+ this.isUpload = isUpload;
|
|
|
+ PhotoPicker.builder()
|
|
|
+ .setPhotoCount(1)
|
|
|
+ .setShowCamera(true)
|
|
|
+ .setShowGif(false)
|
|
|
+ .setPreviewEnabled(false)
|
|
|
+ .start(this, PhotoPicker.REQUEST_CODE);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getLayoutId() {
|
|
|
+ return R.layout.task_detail_layout;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initView() {
|
|
|
+ activity = this;
|
|
|
+ taskEty = (TaskEty) getIntent().getSerializableExtra("task_enty");
|
|
|
+ DaggerTaskDetailComponent.builder()
|
|
|
+ .netComponent(SheepApp.get(activity).getNetComponent())
|
|
|
+ .taskDetailModule(new TaskDetailModule(this))
|
|
|
+ .build()
|
|
|
+ .inject(this);
|
|
|
+ TitleBarUtils.getInstance()
|
|
|
+ .setTitle(activity, "任务详情")
|
|
|
+ .setTitleFinish(activity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initListener() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initData() {
|
|
|
+ if(taskEty == null){
|
|
|
+ G.showToast("网络异常,请稍候再试");
|
|
|
+// finish();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ 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.loadUrl(request.getUrl().toString());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ webText.loadUrl(taskEty.getDownload_link());
|
|
|
+
|
|
|
+ if (taskEty.getRunTask() == 1){
|
|
|
+ detailTaskTv.setVisibility(View.VISIBLE);
|
|
|
+ bottom_btn_layout.setVisibility(View.VISIBLE);
|
|
|
+ }else {
|
|
|
+ detailTaskTv.setVisibility(View.INVISIBLE);
|
|
|
+ bottom_btn_layout.setVisibility(View.GONE);
|
|
|
+
|
|
|
+ }
|
|
|
+ if (PackageUtil.isAppInstalled(SheepApp.mContext, taskEty.getPackage_names())) {
|
|
|
+ btnTaskItem.setText("开始游戏");
|
|
|
+ } else {
|
|
|
+ btnTaskItem.setText("下载游戏");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ // TODO: add setContentView(...) invocation
|
|
|
+ ButterKnife.bind(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @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) {
|
|
|
+ switch (view.getId()) {
|
|
|
+ case R.id.detail_task_tv://查看任务截图
|
|
|
+ Intent intent = new Intent(activity, WebActivity.class);
|
|
|
+ intent.putExtra(WebActivity.INTENT_URL, taskEty.getScreenshots());
|
|
|
+ intent.putExtra(WebActivity.INTENT_TITLE, "任务提交示意");
|
|
|
+ startActivity(intent);
|
|
|
+ break;
|
|
|
+ case R.id.web_text:
|
|
|
+ break;
|
|
|
+ case R.id.ll_infos:
|
|
|
+ break;
|
|
|
+ case R.id.btn_task_item:
|
|
|
+ if (PackageUtil.isAppInstalled(SheepApp.mContext, taskEty.getPackage_names())) {
|
|
|
+ PackageUtil.startApp(SheepApp.mContext, taskEty.getPackage_names());
|
|
|
+ } else {
|
|
|
+ Jump2View.getInstance().goDialogActivityView(activity, taskEty);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case R.id.btn_up_imag:
|
|
|
+ uploadImag();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 任务进度
|
|
|
+ */
|
|
|
+ private void taskSchedule(){
|
|
|
+ llInfos.removeAllViews();
|
|
|
+ if (taskEty != null) {
|
|
|
+ int thisRun = taskEty.getRunTask();
|
|
|
+ if (thisRun == 1) {//接受了任务
|
|
|
+ llInfos.addView(getStep("领取任务", "已完成", 0));
|
|
|
+ if (PackageUtil.isAppInstalled(SheepApp.mContext, taskEty.getPackage_names())) {
|
|
|
+ llInfos.addView(getStep("下载游戏", "已完成", 0));
|
|
|
+ llInfos.addView(getStep("完成任务", "进行中", 1));
|
|
|
+ } else {
|
|
|
+ llInfos.addView(getStep("下载游戏", "待完成", 2));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ llInfos.addView(getStep("领取任务", "待完成", 2));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ llInfos.addView(getStep("领取任务", "待完成", 2));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private View getStep(String step, String state, int color) {
|
|
|
+ View view = View.inflate(this, R.layout.task_step_info, null);
|
|
|
+ ImageView img = (ImageView) view.findViewById(R.id.img_tab);
|
|
|
+ TextView tvStep = (TextView) view.findViewById(R.id.tv_step);
|
|
|
+ TextView tvStatus = (TextView) view.findViewById(R.id.tv_status);
|
|
|
+ if (color == 0) {
|
|
|
+ img.setImageResource(R.drawable.garden_green);
|
|
|
+ tvStep.setTextColor(getResources().getColor(R.color.green));
|
|
|
+ tvStatus.setTextColor(getResources().getColor(R.color.green));
|
|
|
+ } else if (color == 1) {
|
|
|
+ img.setImageResource(R.drawable.garden_yellow);
|
|
|
+ tvStep.setTextColor(getResources().getColor(R.color.yellow_text_light));
|
|
|
+ tvStatus.setTextColor(getResources().getColor(R.color.yellow_text_light));
|
|
|
+ } else {
|
|
|
+ img.setImageResource(R.drawable.garden_gray);
|
|
|
+ tvStep.setTextColor(getResources().getColor(R.color.black_text_gray));
|
|
|
+ tvStatus.setTextColor(getResources().getColor(R.color.black_text_gray));
|
|
|
+ }
|
|
|
+
|
|
|
+ tvStep.setText(step);
|
|
|
+ tvStatus.setText(state);
|
|
|
+ return view;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * update file
|
|
|
+ */
|
|
|
+ private void uploadImag() {
|
|
|
+ Intent intent = new Intent(Intent.ACTION_PICK,
|
|
|
+ android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
|
|
+ startActivityForResult(intent, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+
|
|
|
+ //获取图片路径
|
|
|
+ if (requestCode == 1 && resultCode == Activity.RESULT_OK && data != null) {
|
|
|
+ Uri selectedImage = data.getData();
|
|
|
+ String[] filePathColumns = {MediaStore.Images.Media.DATA};
|
|
|
+ Cursor c = getContentResolver().query(selectedImage, filePathColumns, null, null, null);
|
|
|
+ c.moveToFirst();
|
|
|
+ int columnIndex = c.getColumnIndex(filePathColumns[0]);
|
|
|
+ String imagePath = c.getString(columnIndex);
|
|
|
+ if (isUpload) {
|
|
|
+ dialogShowLoading = DialogShowLoading.showDialog(activity);
|
|
|
+ UpFileUtils.upImage(new File(imagePath), TaskDetailAct.this);
|
|
|
+ }
|
|
|
+ c.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void taskStatusSuccess(BaseMessage baseMessage) {
|
|
|
+ dialogShowLoading.getTextView().setText("完成");
|
|
|
+// onGetNetImageUrl(data);
|
|
|
+ dialogShowLoading.getAlertDialog().dismiss();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void taskStatusFaile(BaseMessage baseMessage) {
|
|
|
+ updateError("失败");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void Success(String msg) {
|
|
|
+ String json;
|
|
|
+ if (TextUtils.isEmpty(msg)) {
|
|
|
+ updateError("失败");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (msg.startsWith("{")) {
|
|
|
+ json = msg;
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ byte[] bytes = HexUtils.hexStr2Bytes(msg);
|
|
|
+ byte[] byteDecode = Kfzssafe.XByteDecode(bytes);
|
|
|
+ json = new String(byteDecode);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ updateError("失败");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ UploadResult uploadResult = JSON.parseObject(json, UploadResult.class);
|
|
|
+ if (uploadResult != null) {
|
|
|
+ final String data = uploadResult.getData().getUrl();
|
|
|
+ dialogShowLoading.getTextView().setText("更新中");
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("id", taskEty.getRelease_task_id());
|
|
|
+ jsonObject.put("screenshots",taskEty.getScreenshots()+"");
|
|
|
+ jsonObject.put("remark",taskEty.getRemarks()+"");
|
|
|
+ jsonObject.put("package_name",taskEty.getPackage_names()+"");
|
|
|
+ jsonObject.put("status",7+"");
|
|
|
+ presenter.taskStatus(jsonObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void updateError(String msg) {
|
|
|
+ dialogShowLoading.getTextView().setText(msg);
|
|
|
+// onNotGetImage(msg);
|
|
|
+ dialogShowLoading.getAlertDialog().dismiss();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void Progress(String progress) {
|
|
|
+ dialogShowLoading.getTextView().setText(progress);
|
|
|
+ dialogShowLoading.getTextView().append("%");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void Failure(String err) {
|
|
|
+ G.showToast(err);
|
|
|
+ }
|
|
|
+}
|