|
|
@@ -1,6 +1,12 @@
|
|
|
package com.sheep.jiuyan.samllsheep.page;
|
|
|
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
+import android.database.Cursor;
|
|
|
+import android.net.Uri;
|
|
|
+import android.provider.MediaStore;
|
|
|
+import android.support.v7.app.AlertDialog;
|
|
|
import android.text.Html;
|
|
|
import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
|
@@ -13,6 +19,7 @@ import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
import com.bumptech.glide.Glide;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
@@ -22,10 +29,13 @@ import com.sheep.jiuyan.samllsheep.net.NetManager;
|
|
|
import com.sheep.jiuyan.samllsheep.net.SheepCallback;
|
|
|
import com.sheep.jiuyan.samllsheep.net.Url;
|
|
|
import com.sheep.jiuyan.samllsheep.page.entry.TaskPublish;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.DeviceUtils;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
/**
|
|
|
@@ -46,8 +56,11 @@ public class GameDetailActivity extends BaseActivity {
|
|
|
private TextView mTvText1;
|
|
|
private TextView mTvMoney;
|
|
|
private Button mBtnTaskItem;
|
|
|
+ private Button mBtnUpImag;
|
|
|
private WebView mWebText;
|
|
|
private LinearLayout mLlInfos;
|
|
|
+ private AlertDialog mDialog;
|
|
|
+ private AlertDialog mReDialog;
|
|
|
|
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
|
@@ -70,8 +83,10 @@ public class GameDetailActivity extends BaseActivity {
|
|
|
mTvText1 = (TextView) findViewById(R.id.tv_text1);
|
|
|
mTvMoney = (TextView) findViewById(R.id.tv_money);
|
|
|
mBtnTaskItem = (Button) findViewById(R.id.btn_task_item);
|
|
|
+ mBtnUpImag = (Button) findViewById(R.id.btn_up_imag);
|
|
|
mWebText = (WebView) findViewById(R.id.web_text);
|
|
|
mLlInfos = (LinearLayout) findViewById(R.id.ll_infos);
|
|
|
+
|
|
|
TitleBarUtils.getInstance().setTitle(this, "任务详情")
|
|
|
.setTitleFinish(this);
|
|
|
mWebText.setWebChromeClient(new WebChromeClient() {
|
|
|
@@ -101,6 +116,129 @@ public class GameDetailActivity extends BaseActivity {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+ mBtnUpImag.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ checkIsRegisterTask();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkIsRegisterTask() {
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ map.put("wx_open_id", SpUtils.getOpenId(this));
|
|
|
+ map.put("publish_id", mTask.getId() + "");
|
|
|
+ NetManager.get(Url.USER_CHECK_REGISTER, map, getApplicationContext(), new SheepCallback<String>(this) {
|
|
|
+ @Override
|
|
|
+ public void success(String ok) {
|
|
|
+ if (TextUtils.equals(ok, "ok")) {
|
|
|
+ uploadImag();
|
|
|
+ } else {
|
|
|
+ showRecommitDialog("用户同时只能领取一个任务,是否此领取任务?");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void uploadImag() {
|
|
|
+ Intent intent = new Intent(Intent.ACTION_PICK,
|
|
|
+ android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
|
|
+ startActivityForResult(intent, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void startTask(final TaskPublish task) {
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ map.put("wx_open_id", SpUtils.getOpenId(this));
|
|
|
+ map.put("task_id", task.getId() + "");
|
|
|
+ map.put("imei", new DeviceUtils(getApplicationContext()).getIMEI());
|
|
|
+ NetManager.get(Url.USER_REGISTER_TASK, map, getApplicationContext(), new SheepCallback<String>(this) {
|
|
|
+ @Override
|
|
|
+ public void success(String o) {
|
|
|
+ String pkg = task.getTask().getPkg();
|
|
|
+ if (!TextUtils.isEmpty(pkg)) {
|
|
|
+ boolean installed = PackageUtil.isAppInstalled(getApplicationContext(), pkg);
|
|
|
+ if (installed) {
|
|
|
+ PackageUtil.startApp(getApplicationContext(), pkg);
|
|
|
+ } else {
|
|
|
+ Intent intent = new Intent(GameDetailActivity.this, DownloadActivity.class);
|
|
|
+ intent.putExtra("task", task.getTask());
|
|
|
+ startActivity(intent);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Toast.makeText(GameDetailActivity.this, "任务已经领取,快去完成吧", Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showRecommitDialog(String s) {
|
|
|
+ if (mReDialog == null) {
|
|
|
+ mReDialog = new AlertDialog.Builder(GameDetailActivity.this)
|
|
|
+ .setMessage(s)
|
|
|
+ .setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ startTask(mTask);
|
|
|
+ mReDialog.dismiss();
|
|
|
+ }
|
|
|
+ }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ mReDialog.dismiss();
|
|
|
+ }
|
|
|
+ }).create();
|
|
|
+ }
|
|
|
+ mReDialog.setMessage(s);
|
|
|
+ mReDialog.show();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @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);
|
|
|
+ commitTask(imagePath);
|
|
|
+ c.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void commitTask(String path) {
|
|
|
+ String topApp = "";
|
|
|
+ Intent intent = getIntent();
|
|
|
+ if (intent != null) {
|
|
|
+ topApp = intent.getStringExtra("pkg");
|
|
|
+ }
|
|
|
+ HashMap<String, String> parma = new HashMap<>();
|
|
|
+ parma.put("task_pkg", topApp);
|
|
|
+ parma.put("task_pkg", topApp);
|
|
|
+ parma.put("wx_open_id", SpUtils.getOpenId(this));
|
|
|
+ NetManager.upload(Url.UPLOAD_IMG, parma, new File(path), getApplicationContext(), new SheepCallback<String>(this) {
|
|
|
+ @Override
|
|
|
+ public void success(String s) {
|
|
|
+ Toast.makeText(GameDetailActivity.this, s, Toast.LENGTH_SHORT).show();
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void otherCode(int code, String string) {
|
|
|
+ super.otherCode(code, string);
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void failure(IOException e) {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Override
|