|
|
@@ -1,12 +1,17 @@
|
|
|
package com.jiuyan.sheep_children.page;
|
|
|
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.content.Intent;
|
|
|
+import android.support.v7.app.AlertDialog;
|
|
|
import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
+import android.widget.AdapterView;
|
|
|
import android.widget.BaseAdapter;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.ListView;
|
|
|
import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
import com.bumptech.glide.Glide;
|
|
|
import com.jiuyan.sheep_children.R;
|
|
|
@@ -16,6 +21,7 @@ import com.jiuyan.sheep_children.net.SheepCallback;
|
|
|
import com.jiuyan.sheep_children.net.Url;
|
|
|
import com.jiuyan.sheep_children.page.entry.Commit;
|
|
|
import com.jiuyan.sheep_children.page.entry.TaskPublish;
|
|
|
+import com.jiuyan.sheep_children.utils.PackageUtil;
|
|
|
import com.jiuyan.sheep_children.utils.SpUtils;
|
|
|
import com.zhy.adapter.abslistview.CommonAdapter;
|
|
|
import com.zhy.adapter.abslistview.ViewHolder;
|
|
|
@@ -36,6 +42,9 @@ public class TaskRecordActivity extends BaseActivity {
|
|
|
private TextView mTvTitle;
|
|
|
private View mBack;
|
|
|
private CommonAdapter mAdapter;
|
|
|
+ private List<Commit> mCommits;
|
|
|
+ private AlertDialog mDialog;
|
|
|
+ private AlertDialog mReDialog;
|
|
|
|
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
|
@@ -45,6 +54,7 @@ public class TaskRecordActivity extends BaseActivity {
|
|
|
@Override
|
|
|
public void initView() {
|
|
|
mLvTask = findViewById(R.id.lv_task);
|
|
|
+ mLvTask.setDividerHeight(0);
|
|
|
mTvTitle = findViewById(R.id.tv_title);
|
|
|
mBack = findViewById(R.id.img_back);
|
|
|
|
|
|
@@ -58,6 +68,108 @@ public class TaskRecordActivity extends BaseActivity {
|
|
|
finish();
|
|
|
}
|
|
|
});
|
|
|
+ mLvTask.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
+ final Commit commit = mCommits.get(position);
|
|
|
+ if (mDialog == null) {
|
|
|
+ mDialog = new AlertDialog.Builder(TaskRecordActivity.this)
|
|
|
+ .setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ dispatch(commit);
|
|
|
+ mDialog.dismiss();
|
|
|
+ }
|
|
|
+ }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ mDialog.dismiss();
|
|
|
+ }
|
|
|
+ }).create();
|
|
|
+ }
|
|
|
+ mDialog.setMessage(getTip(commit.getStatus()));
|
|
|
+ mDialog.show();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void dispatch(final Commit commit) {
|
|
|
+ if (commit.getStatus() == 3) {
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ map.put("wx_open_id", SpUtils.getOpenId(this));
|
|
|
+ NetManager.get(Url.USER_CHECK_REGISTER, map, getApplicationContext(), new SheepCallback<String>(this) {
|
|
|
+ @Override
|
|
|
+ public void success(String ok) {
|
|
|
+ if (TextUtils.equals(ok, "ok")) {
|
|
|
+ startRecommitTask(commit);
|
|
|
+ } else {
|
|
|
+ showRecommitDialog("你有任务正在进行,是否取消,接受新任务?", commit);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showRecommitDialog(String s, final Commit commit) {
|
|
|
+ if (mReDialog == null) {
|
|
|
+ mReDialog = new AlertDialog.Builder(TaskRecordActivity.this)
|
|
|
+ .setMessage(s)
|
|
|
+ .setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ startRecommitTask(commit);
|
|
|
+ mReDialog.dismiss();
|
|
|
+ }
|
|
|
+ }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ mReDialog.dismiss();
|
|
|
+ }
|
|
|
+ }).create();
|
|
|
+ }
|
|
|
+ mReDialog.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void startRecommitTask(final Commit commit) {
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ map.put("wx_open_id", SpUtils.getOpenId(this));
|
|
|
+ map.put("task_id", commit.getTaskPublishId() + "");
|
|
|
+ NetManager.get(Url.USER_REGISTER_TASK, map, getApplicationContext(), new SheepCallback<String>(this) {
|
|
|
+ @Override
|
|
|
+ public void success(String o) {
|
|
|
+ String pkg = commit.getTask().getPkg();
|
|
|
+ if (!TextUtils.isEmpty(pkg)) {
|
|
|
+ boolean installed = PackageUtil.isAppInstalled(getApplicationContext(), pkg);
|
|
|
+ if (installed) {
|
|
|
+ PackageUtil.startApp(getApplicationContext(), pkg);
|
|
|
+ } else {
|
|
|
+ Intent intent = new Intent(TaskRecordActivity.this, DownloadActivity.class);
|
|
|
+ intent.putExtra("task", commit.getTask());
|
|
|
+ startActivity(intent);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Toast.makeText(TaskRecordActivity.this, "任务已经重新激活,快去完成吧", Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getTip(int status) {
|
|
|
+ String str = null;
|
|
|
+ switch (status) {
|
|
|
+ case 1:
|
|
|
+ str = "您提交的任务正在排队审核,请耐心等待,很快就好";
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ str = "您提交的任务已经通过审核,羊毛已经入库~~";
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ str = "您提交的任务审核未通过,是否重新提交";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return str;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -69,11 +181,12 @@ public class TaskRecordActivity extends BaseActivity {
|
|
|
NetManager.get(Url.USER_COMMIT, map, getApplicationContext(), new SheepCallback<List<Commit>>(this) {
|
|
|
@Override
|
|
|
public void success(List<Commit> commits) {
|
|
|
+ mCommits = commits;
|
|
|
if (mAdapter == null)
|
|
|
mLvTask.setAdapter(mAdapter = new CommonAdapter<Commit>(TaskRecordActivity.this, R.layout.task_record_item, commits) {
|
|
|
@Override
|
|
|
protected void convert(ViewHolder viewHolder, Commit item, int position) {
|
|
|
- String[] tmp1 = item.getCheckTime().split("-");
|
|
|
+ String[] tmp1 = item.getCreateTime().split("-");
|
|
|
String[] tmp2 = tmp1[2].split(" ")[1].split(":");
|
|
|
String time = tmp1[1] + "/" + tmp1[2].split(" ")[0] + "\n" + tmp2[0] + ":" + tmp2[1];
|
|
|
viewHolder.setText(R.id.tv_time, time);
|