Przeglądaj źródła

应用自动审核类型的任务修改为点击领取奖励按钮来完成任务

zengjiebin 8 lat temu
rodzic
commit
c7fdaf57c9

+ 8 - 8
app/src/main/java/com/sheep/gamegroup/model/util/SheepSubscriber.java

@@ -70,14 +70,14 @@ public abstract class SheepSubscriber<T> extends Subscriber<T> {
                 if(throwable.message.startsWith("{")){
                     baseMessage = JSONObject.parseObject(throwable.message, BaseMessage.class);
                 }else if(ViewUtil.isH5Content(throwable.message)){
-//                    if(BuildConfig.DEBUG){
-//                        StringBuilder title = new StringBuilder("调用接口错误");
-//                        if(e instanceof HttpException) {
-//                            title.append(";");
-//                            title.append(((HttpException) e).response().toString());
-//                        }
-//                        Jump2View.getInstance().goNotice(ActivityManager.getInstance().currentActivity(), title.toString(), throwable.message, 0);
-//                    }
+                    if(BuildConfig.DEBUG){
+                        StringBuilder title = new StringBuilder("调用接口错误");
+                        if(e instanceof HttpException) {
+                            title.append(";");
+                            title.append(((HttpException) e).response().toString());
+                        }
+                        Jump2View.getInstance().goNotice(ActivityManager.getInstance().currentActivity(), title.toString(), throwable.message, 0);
+                    }
                     baseMessage = new BaseMessage();
                     baseMessage.setMsg("服务器错误");
                 }else {

+ 74 - 3
app/src/main/java/com/sheep/gamegroup/view/activity/TaskDetailAct.java

@@ -16,6 +16,7 @@ import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.arialyy.annotations.Download;
 import com.arialyy.aria.core.Aria;
@@ -32,12 +33,14 @@ import com.kfzs.duanduan.utils.ApkUtils;
 import com.sheep.gamegroup.absBase.AbsChooseImageActivity;
 import com.sheep.gamegroup.di.components.DaggerTaskDetailComponent;
 import com.sheep.gamegroup.di.modules.TaskDetailModule;
+import com.sheep.gamegroup.model.entity.AppRecord;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.DialogEntity;
 import com.sheep.gamegroup.model.entity.Ext;
 import com.sheep.gamegroup.model.entity.TaskAcceptedEty;
 import com.sheep.gamegroup.model.entity.TaskChild;
 import com.sheep.gamegroup.model.entity.TaskEty;
+import com.sheep.gamegroup.model.entity.TaskListen;
 import com.sheep.gamegroup.model.entity.TaskReleaseEty;
 import com.sheep.gamegroup.model.util.EntityUtils;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
@@ -46,10 +49,14 @@ import com.sheep.gamegroup.presenter.TaskDetailPresenter;
 import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.DeviceUtil;
 import com.sheep.gamegroup.util.Jump2View;
+import com.sheep.gamegroup.util.LocationUtils;
+import com.sheep.gamegroup.util.LogUtil;
+import com.sheep.gamegroup.util.MyDbManager;
 import com.sheep.gamegroup.util.MyListview;
 import com.sheep.gamegroup.util.TimeUtil;
 import com.sheep.gamegroup.util.UMConfigUtils;
 import com.sheep.gamegroup.view.adapter.AdpTaskDetailChildListview;
+import com.sheep.jiuyan.samllsheep.BuildConfig;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
@@ -62,6 +69,7 @@ import org.greenrobot.eventbus.EventBus;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Locale;
 
 import javax.inject.Inject;
 
@@ -258,7 +266,10 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
                 break;
 
         }
-        if (type >= 3 && taskEty.getInspect_type() != 3) {
+        if(taskEty.getInspect_type() == 3){//应用自动审核任务
+            btnUpImag.setText("领取奖励");
+        }
+        if (type >= 3) {
 
             btnUpImag.setVisibility(View.VISIBLE);
         } else {
@@ -479,8 +490,16 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
                     }
                     break;
                 case R.id.btn_up_imag:
-                    showChooseDialog(false, true, DEFAULT_MAX_COUNT);
-                    UMConfigUtils.onEvent(UMConfigUtils.Event.TASK_UPLOAD_PICTURE);
+                    if(taskEty.getInspect_type() == 3) {//应用自动审核任务
+                        try {
+                            checkAndCommitTask();
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    } else {
+                        showChooseDialog(false, true, DEFAULT_MAX_COUNT);
+                        UMConfigUtils.onEvent(UMConfigUtils.Event.TASK_UPLOAD_PICTURE);
+                    }
                     break;
             }
         } catch (Exception ignore) {
@@ -489,6 +508,58 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
     }
 
     /**
+     * 尝试提交应用自动审核任务
+     */
+    private void checkAndCommitTask() {
+        TaskListen taskEty = SheepApp.getInstance().getTaskEty();
+        if(taskEty != null) {
+            if(TextUtils.isEmpty(taskEty.getPackage_names())){
+                G.showToast(R.string.error_package_link);
+                return;
+            }
+            String gps = LocationUtils.getInstance().getLongitudeLatitude(getApplicationContext());
+            JSONObject object = new JSONObject();
+            object.put("gps", gps);
+            long runTime = MyDbManager.getInstance().getAppRunTime(taskEty.getPackage_names());
+
+            AppRecord lastAppRecord = SheepApp.getInstance().getLastAppRecord();
+            if(lastAppRecord != null && TextUtils.equals(taskEty.getPackage_names(), lastAppRecord.getPackageName())){
+                runTime +=  System.currentTimeMillis() - SheepApp.getInstance().getLastTime();
+                SheepApp.getInstance().setLastTime(System.currentTimeMillis());
+            }
+            if(runTime <= 0){//时间小于等于0则不提交
+                G.showToast("该任务时长未达到,请继续去体验应用哦!");
+                return;
+            }
+
+            MyDbManager.getInstance().removeAppRecord();
+            LogUtil.println("MonitorAppService runTime = "+runTime);
+            object.put("task_time", runTime/1000);
+            object.put("release_task_id", taskEty.getRelease_task_id());
+            SheepApp.getInstance().getNetComponent().getApiService().commitAutoTask(object)
+                    .subscribeOn(Schedulers.io())
+                    .observeOn(AndroidSchedulers.mainThread())
+                    .subscribe(new SheepSubscriber<BaseMessage>(getApplicationContext()) {
+                        @Override
+                        public void onNext(BaseMessage baseMessage) {
+                            LogUtil.println("MonitorAppService baseMessage onNext "+ JSON.toJSONString(baseMessage));
+                            CommonUtil.getInstance().setTAskEnty(null);
+                            G.showToast(String.format(Locale.CHINA, "恭喜你,任务已完成,获得奖励%s元", taskReleaseEty.getBonus()));
+                            finish();
+                        }
+
+                        @Override
+                        public void onError(BaseMessage baseMessage) {
+                            LogUtil.println("MonitorAppService baseMessage onError "+JSON.toJSONString(baseMessage));
+                            G.showToast("该任务时长未达到,请继续去体验应用哦!");
+                        }
+                    });
+        } else {
+            G.showToast(R.string.unknown_error);
+        }
+    }
+
+    /**
      * 任务进度
      */
     private void taskSchedule() {

+ 1 - 48
app/src/main/java/com/sheep/jiuyan/samllsheep/service/FloatService.java

@@ -78,7 +78,6 @@ public class FloatService extends Service {
     }
 
     private Subscription subscription;
-    private int count = 0;
     private void startTimer() {
         if(subscription == null)
             subscription = Observable.interval(1000, TimeUnit.MILLISECONDS)
@@ -105,54 +104,8 @@ public class FloatService extends Service {
     private void checkTask() {
         TaskListen taskEty = SheepApp.getInstance().getTaskEty();
         if(taskEty != null) {
-            if(Jump2View.getInstance().startAccessibility(getApplication())){
-                if(count > (BuildConfig.DEBUG ? 6 : 60)){//每过一分钟提交一次任务
-                    count = 0;
-                    if(TextUtils.isEmpty(taskEty.getPackage_names())){
-                        if(BuildConfig.DEBUG)
-                            G.showToast("没有包名,不能提交任务");
-                        return;
-                    }
-                    String gps = LocationUtils.getInstance().getLongitudeLatitude(getApplicationContext());
-                    JSONObject object = new JSONObject();
-                    object.put("gps", gps);
-                    long runTime = MyDbManager.getInstance().getAppRunTime(taskEty.getPackage_names());
-
-                    AppRecord lastAppRecord = SheepApp.getInstance().getLastAppRecord();
-                    if(lastAppRecord != null && TextUtils.equals(taskEty.getPackage_names(), lastAppRecord.getPackageName())){
-                        runTime +=  System.currentTimeMillis() - SheepApp.getInstance().getLastTime();
-                        SheepApp.getInstance().setLastTime(System.currentTimeMillis());
-                    }
-                    if(runTime <= 0){//时间小于等于0则不提交
-                        return;
-                    }
-
-                    MyDbManager.getInstance().removeAppRecord();
-                    LogUtil.println("MonitorAppService runTime = "+runTime);
-                    object.put("task_time", runTime/1000);
-                    object.put("release_task_id", taskEty.getRelease_task_id());
-                    SheepApp.getInstance().getNetComponent().getApiService().commitAutoTask(object)
-                            .subscribeOn(Schedulers.io())
-                            .observeOn(AndroidSchedulers.mainThread())
-                            .subscribe(new SheepSubscriber<BaseMessage>(getApplicationContext()) {
-                                @Override
-                                public void onNext(BaseMessage baseMessage) {
-                                    LogUtil.println("MonitorAppService baseMessage onNext "+ JSON.toJSONString(baseMessage));
-                                    CommonUtil.getInstance().setTAskEnty(null);
-                                }
-
-                                @Override
-                                public void onError(BaseMessage baseMessage) {
-                                    LogUtil.println("MonitorAppService baseMessage onError "+JSON.toJSONString(baseMessage));
-                                }
-                            });
-                }
-                LogUtil.println("MonitorAppService count = "+count);
-                count++;
-                return;
-            }
+            Jump2View.getInstance().startAccessibility(getApplication());
         }
-        count = 0;
     }
 
 

+ 1 - 1
app/src/main/java/com/sheep/jiuyan/samllsheep/service/MonitorAppService.java

@@ -52,7 +52,7 @@ public class MonitorAppService extends AccessibilityService {
                 long lastTime = SheepApp.getInstance().getLastTime();
                 if(lastAppRecord != null && lastTime != 0)
                     lastAppRecord.setTime(lastAppRecord.getTime() + curTime - lastTime);
-                if(lastAppRecord != null && TextUtils.equals(taskEty.getPackage_names(), packageName.toString()))
+                if(lastAppRecord != null && TextUtils.equals(taskEty.getPackage_names(), lastAppRecord.getPackageName()))
                     MyDbManager.getInstance().saveOrUpdate(lastAppRecord);
 
                 SheepApp.getInstance().setLastTime(curTime);

+ 2 - 0
app/src/main/res/values/strings.xml

@@ -14,7 +14,9 @@
     <string name="coming_soon">敬请期待</string>
     <string name="loading_data">数据正在加载中,请稍候重试</string>
     <string name="service_error">服务器错误,请稍候再试</string>
+    <string name="unknown_error">未知错误,请稍候再试</string>
     <string name="error_download_link">下载地址错误,请联系客服</string>
+    <string name="error_package_link">包名错误,请联系客服</string>
     <string name="last_page">&#060;</string>
     <string name="next_page">&#062;</string>