|
|
@@ -0,0 +1,360 @@
|
|
|
+package com.sheep.gamegroup.heler;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.Gravity;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.kfzs.duanduan.utils.NumberFormatUtils;
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
+import com.sheep.gamegroup.model.entity.OrienteeringDetail;
|
|
|
+import com.sheep.gamegroup.model.entity.TaskAcceptedEty;
|
|
|
+import com.sheep.gamegroup.model.entity.TaskEty;
|
|
|
+import com.sheep.gamegroup.model.entity.TaskReleaseEty;
|
|
|
+import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
+import com.sheep.gamegroup.util.CommonUtil;
|
|
|
+import com.sheep.gamegroup.util.GlideImageLoader;
|
|
|
+import com.sheep.gamegroup.util.Jump2View;
|
|
|
+import com.sheep.gamegroup.util.LogUtil;
|
|
|
+import com.sheep.gamegroup.util.RxjavaCountDownTimer;
|
|
|
+import com.sheep.gamegroup.util.TimeUtil;
|
|
|
+import com.sheep.gamegroup.util.UMConfigUtils;
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
+import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
+
|
|
|
+import java.util.Locale;
|
|
|
+
|
|
|
+import rx.android.schedulers.AndroidSchedulers;
|
|
|
+import rx.functions.Action1;
|
|
|
+import rx.schedulers.Schedulers;
|
|
|
+
|
|
|
+import static com.sheep.gamegroup.util.UMConfigUtils.Event.FIND_TASK;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by realicing on 2018/7/3.
|
|
|
+ * realicing@sina.com
|
|
|
+ */
|
|
|
+public class TaskHelper {
|
|
|
+ private Action1<Integer> action1;
|
|
|
+ public TaskHelper(Action1<Integer> action1){
|
|
|
+ this.action1 = action1;
|
|
|
+ }
|
|
|
+
|
|
|
+ private TaskAcceptedEty taskAcceptedEty;
|
|
|
+ private int release_task_id;
|
|
|
+ private Activity activity;
|
|
|
+ public void initAcceptedTask(Activity activity, final int release_task_id) {
|
|
|
+ this.activity = activity;
|
|
|
+ this.release_task_id = release_task_id;
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().getAcceptedTaskDetail(release_task_id)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ LogUtil.println("baseMessage onNext "+ JSON.toJSONString(baseMessage));
|
|
|
+ taskAcceptedEty = baseMessage.getData(TaskAcceptedEty.class);
|
|
|
+ initTask(release_task_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ LogUtil.println("baseMessage onError "+JSON.toJSONString(baseMessage));
|
|
|
+ initTask(release_task_id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ private TaskReleaseEty taskReleaseEty;
|
|
|
+ private void initTask(int release_task_id) {
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().taskDesc(release_task_id)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ LogUtil.println("baseMessage onNext "+JSON.toJSONString(baseMessage));
|
|
|
+ taskReleaseEty = baseMessage.getData(TaskReleaseEty.class);
|
|
|
+ if(action1 != null)
|
|
|
+ action1.call(1);//刷新界面
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ LogUtil.println("baseMessage onError "+JSON.toJSONString(baseMessage));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ private OrienteeringDetail orienteeringDetail;
|
|
|
+ private void initGameTask(final View itemView, String third_task_id) {
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().getMyGame(third_task_id)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ LogUtil.println("baseMessage onNext "+JSON.toJSONString(baseMessage));
|
|
|
+ orienteeringDetail = baseMessage.getData(OrienteeringDetail.class);
|
|
|
+ loadTask(itemView);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ LogUtil.println("baseMessage onError "+JSON.toJSONString(baseMessage));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean hasTask() {
|
|
|
+ return taskReleaseEty != null && taskReleaseEty.getTask() != null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private RxjavaCountDownTimer timer;
|
|
|
+ public void loadTask(final View itemView) {
|
|
|
+ itemView.setVisibility(View.VISIBLE);
|
|
|
+ if(taskReleaseEty == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ final TaskEty taskEty = taskReleaseEty.getTask();
|
|
|
+ if(taskEty == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ImageView find_information_game_icon = (ImageView)itemView.findViewById(R.id.find_information_game_icon);
|
|
|
+ TextView find_information_game_name = (TextView)itemView.findViewById(R.id.find_information_game_name);
|
|
|
+ TextView find_information_game_surplus = (TextView)itemView.findViewById(R.id.find_information_game_surplus);
|
|
|
+ TextView find_information_game_time = (TextView)itemView.findViewById(R.id.find_information_game_time);
|
|
|
+ TextView find_information_game_yuan = (TextView)itemView.findViewById(R.id.find_information_game_yuan);
|
|
|
+ TextView find_information_game_task0 = (TextView)itemView.findViewById(R.id.find_information_game_task0);
|
|
|
+ TextView find_information_game_task = (TextView)itemView.findViewById(R.id.find_information_game_task);
|
|
|
+ final TextView find_information_game_task_end_time = (TextView)itemView.findViewById(R.id.find_information_game_task_end_time);
|
|
|
+ if(orienteeringDetail != null){//已经完成的游戏任务
|
|
|
+ find_information_game_task.setVisibility(View.VISIBLE);
|
|
|
+ find_information_game_task0.setVisibility(View.VISIBLE);
|
|
|
+ find_information_game_yuan.setVisibility(View.INVISIBLE);
|
|
|
+ find_information_game_surplus.setText(String.format(Locale.CHINA, "可定向消费:%.1f元", orienteeringDetail.getBalance()));
|
|
|
+ find_information_game_surplus.setTextColor(activity.getResources().getColor(R.color.red_fd2d54));
|
|
|
+ find_information_game_task.setText("去充值");
|
|
|
+ find_information_game_task.setEnabled(true);
|
|
|
+ downloadHelper.updateDownloadTaskView(activity, taskEty, find_information_game_task0);
|
|
|
+ find_information_game_task.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ ViewUtil.showGamePayAccount(activity, orienteeringDetail.getGame_id());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ reloadDataType = 1;//回来后将刷新界面数据 taskAcceptedEty
|
|
|
+ Jump2View.getInstance().goGameTaskDetailView(activity, release_task_id, orienteeringDetail.getGame_id(),1);
|
|
|
+ UMConfigUtils.IdEvent.TASK.commit(release_task_id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ GlideImageLoader.centerImage(find_information_game_icon, taskEty.getIcon());
|
|
|
+ ViewUtil.setText(find_information_game_name, taskReleaseEty.getName());
|
|
|
+ ViewUtil.setText(find_information_game_surplus, String.format(Locale.CHINA, "剩余%s份", taskReleaseEty.getLast_num()));
|
|
|
+ ViewUtil.setText(find_information_game_time, String.format(Locale.CHINA, "截止日期:%s", taskReleaseEty.getDeadline().equals("永久") ? taskReleaseEty.getDeadline() : TimeUtil.TimeStamp2Date(NumberFormatUtils.parseLong(taskReleaseEty.getDeadline()), "yyyy/MM/dd HH:mm")));
|
|
|
+ ViewUtil.setText(find_information_game_yuan, String.format(Locale.CHINA, "+%s元", taskReleaseEty.getBonus()));
|
|
|
+ find_information_game_task0.setVisibility(View.GONE);
|
|
|
+ find_information_game_yuan.setVisibility(View.VISIBLE);
|
|
|
+ switch (taskEty.getTask_type()) {// 1时间试玩任务 2 信用卡任务 3应用下载 4h5业务 1001畅思 1000连续任务, 1002 1003游戏任务
|
|
|
+ case 2://信用卡任务
|
|
|
+ find_information_game_task.setVisibility(View.GONE);
|
|
|
+ find_information_game_task_end_time.setVisibility(View.GONE);
|
|
|
+ find_information_game_yuan.setGravity(Gravity.END);
|
|
|
+ String[] remarks = new String[0];
|
|
|
+ if(!TextUtils.isEmpty(taskEty.getRemarks())) {
|
|
|
+ remarks = taskEty.getRemarks().split(";");
|
|
|
+ }
|
|
|
+ find_information_game_time.setText(remarks.length > 0 ? remarks[0] : "");
|
|
|
+ find_information_game_surplus.setText(remarks.length > 1 ? remarks[1] : "");
|
|
|
+ itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ Jump2View.getInstance().goCreditCardTaskDetail(activity, taskReleaseEty.getId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case 1001:
|
|
|
+ break;
|
|
|
+ case 1://时间试玩任务
|
|
|
+ case 3://应用下载
|
|
|
+ case 4://h5业务
|
|
|
+ case 1000://连续任务
|
|
|
+ case 1002://游戏任务
|
|
|
+ case 1003://游戏任务
|
|
|
+ default:
|
|
|
+ find_information_game_yuan.setGravity(Gravity.CENTER);
|
|
|
+ if(taskAcceptedEty != null){
|
|
|
+ switch (taskAcceptedEty.getStatus()) {
|
|
|
+ case 1://"已接受任务";
|
|
|
+ case 2:// "正在进行中";
|
|
|
+ if(taskReleaseEty.getDeadline().equals("永久")){
|
|
|
+ find_information_game_task_end_time.setVisibility(View.GONE);
|
|
|
+ } else {
|
|
|
+ find_information_game_task_end_time.setVisibility(View.VISIBLE);
|
|
|
+ find_information_game_task_end_time.setText(TimeUtil.getHours(taskAcceptedEty.getEnd_time() * 1000));
|
|
|
+ timer = RxjavaCountDownTimer.getInstance(taskAcceptedEty.getEnd_time())
|
|
|
+ .setOnTickListener(new RxjavaCountDownTimer.OnTickListener() {
|
|
|
+ @Override
|
|
|
+ public void onFinish() {
|
|
|
+ find_information_game_task_end_time.setVisibility(View.GONE);
|
|
|
+ refreshTask();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTicker(long time) {
|
|
|
+ find_information_game_task_end_time.setText(TimeUtil.getHours(time * 1000));
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+ }
|
|
|
+ find_information_game_task.setText("取消任务");
|
|
|
+ find_information_game_task.setEnabled(true);
|
|
|
+ find_information_game_task.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ FIND_TASK.onEvent("release_task_id", release_task_id, "action", "取消任务");
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().giveUpTask(taskAcceptedEty.getId())
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ LogUtil.println("baseMessage onNext "+JSON.toJSONString(baseMessage));
|
|
|
+ refreshTask();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ LogUtil.println("baseMessage onError "+JSON.toJSONString(baseMessage));
|
|
|
+ G.showToast(baseMessage);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //暂停下载
|
|
|
+ CommonUtil.getInstance().stopDownloadTask(activity, taskEty.getDownload_link());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case 6://审核失败
|
|
|
+ find_information_game_task_end_time.setVisibility(View.GONE);
|
|
|
+ find_information_game_task.setVisibility(View.VISIBLE);
|
|
|
+ find_information_game_task.setText("审核失败");
|
|
|
+ find_information_game_task.setEnabled(false);
|
|
|
+ break;
|
|
|
+ //不可操作
|
|
|
+ case 7:// "提交审核";
|
|
|
+ find_information_game_task_end_time.setVisibility(View.GONE);
|
|
|
+ find_information_game_task.setVisibility(View.VISIBLE);
|
|
|
+ find_information_game_task.setText("正在审核");
|
|
|
+ find_information_game_task.setEnabled(false);
|
|
|
+ break;
|
|
|
+ case 3://完成任务
|
|
|
+ find_information_game_task_end_time.setVisibility(View.GONE);
|
|
|
+ find_information_game_task.setVisibility(View.VISIBLE);
|
|
|
+ find_information_game_task.setText("已经完成");
|
|
|
+ find_information_game_task.setEnabled(false);
|
|
|
+ if(taskEty.isGameTask()){
|
|
|
+ initGameTask(itemView, taskEty.getThird_task_id());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 8://任务已经下线
|
|
|
+ find_information_game_task_end_time.setVisibility(View.GONE);
|
|
|
+ find_information_game_task.setVisibility(View.VISIBLE);
|
|
|
+ find_information_game_task.setText("已经下线");
|
|
|
+ find_information_game_task.setEnabled(false);
|
|
|
+ break;
|
|
|
+ case 9:// "至少完成一个任务了";
|
|
|
+ default:
|
|
|
+ find_information_game_task_end_time.setVisibility(View.GONE);
|
|
|
+ find_information_game_task.setVisibility(View.GONE);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else if(taskReleaseEty.isOffline()){//任务已经下线
|
|
|
+ find_information_game_task_end_time.setVisibility(View.GONE);
|
|
|
+ find_information_game_task.setVisibility(View.VISIBLE);
|
|
|
+ find_information_game_task.setText("已经下线");
|
|
|
+ find_information_game_task.setEnabled(false);
|
|
|
+ } else if("0".equals(taskReleaseEty.getLast_num())){
|
|
|
+ find_information_game_task_end_time.setVisibility(View.GONE);
|
|
|
+ find_information_game_task.setVisibility(View.VISIBLE);
|
|
|
+ find_information_game_task.setText("任务已抢光");
|
|
|
+ find_information_game_task.setEnabled(false);
|
|
|
+ } else {
|
|
|
+ find_information_game_task_end_time.setVisibility(View.GONE);
|
|
|
+ find_information_game_task.setVisibility(View.VISIBLE);
|
|
|
+ find_information_game_task.setText("领取任务");
|
|
|
+ find_information_game_task.setEnabled(true);
|
|
|
+ find_information_game_task.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ taskEty.setRunTask(0);
|
|
|
+ taskEty.setRelease_task_id(taskReleaseEty.getId());
|
|
|
+ taskEty.setName(taskReleaseEty.getName());
|
|
|
+ taskEty.setAcceptedTaskId(taskReleaseEty.getAccepted_task_id());
|
|
|
+ Jump2View.getInstance().goDialogActivityView(activity, taskEty);
|
|
|
+ FIND_TASK.onEvent("release_task_id", release_task_id, "action", "领取任务");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ reloadDataType = 1;//回来后将刷新界面数据 taskAcceptedEty
|
|
|
+ Jump2View.getInstance().goTaskDetailView(activity, release_task_id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //刷新界面
|
|
|
+ public void refreshTask() {
|
|
|
+ clear();
|
|
|
+ taskAcceptedEty = null;
|
|
|
+ taskReleaseEty = null;
|
|
|
+ initAcceptedTask(activity, release_task_id);
|
|
|
+ }
|
|
|
+ private int reloadDataType;//0 不刷新数据 1刷新 taskAcceptedEty
|
|
|
+ public void onResume() {
|
|
|
+ switch (reloadDataType){
|
|
|
+ case 1:
|
|
|
+ refreshTask();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 清理计时器
|
|
|
+ */
|
|
|
+ public void clear() {
|
|
|
+ if(timer != null)
|
|
|
+ timer.clear();
|
|
|
+ timer = null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private DownloadHelper downloadHelper = new DownloadHelper();
|
|
|
+
|
|
|
+ public void updateState(int status) {
|
|
|
+ downloadHelper.updateState(status);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|