|
|
@@ -1,14 +1,19 @@
|
|
|
package com.sheep.gamegroup.module.task.fragments;
|
|
|
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
import android.app.Dialog;
|
|
|
+import android.content.Intent;
|
|
|
+import android.util.Log;
|
|
|
+
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
import com.sheep.gamegroup.model.entity.Release_task;
|
|
|
import com.sheep.gamegroup.model.entity.TaskAcceptedEty;
|
|
|
import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
import com.sheep.gamegroup.util.CommonUtil;
|
|
|
-import com.sheep.gamegroup.util.DataUtil;
|
|
|
import com.sheep.gamegroup.util.DeviceUtil;
|
|
|
+import com.sheep.gamegroup.util.GsonUtils;
|
|
|
import com.sheep.gamegroup.util.LocationUtils;
|
|
|
import com.sheep.gamegroup.util.LogUtil;
|
|
|
import com.sheep.gamegroup.util.UMConfigUtils;
|
|
|
@@ -18,19 +23,21 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.base.BaseFragment;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
+import io.reactivex.functions.Consumer;
|
|
|
import io.reactivex.schedulers.Schedulers;
|
|
|
|
|
|
public abstract class FgtVideoTaskBase extends BaseFragment {
|
|
|
|
|
|
+ public static String KEY_RELEASE_TASK = "key_release_task";
|
|
|
+
|
|
|
protected int releaseTaskId = -1;
|
|
|
protected Release_task releaseTask;
|
|
|
protected TaskAcceptedEty acceptedTask;
|
|
|
+ protected boolean goNext = false;
|
|
|
|
|
|
//当前已观看视频数
|
|
|
protected int watchCount = 0;
|
|
|
|
|
|
- protected boolean goNext = false;
|
|
|
-
|
|
|
public FgtVideoTaskBase setReleaseTaskId(int taskId) {
|
|
|
releaseTaskId = taskId;
|
|
|
return this;
|
|
|
@@ -41,19 +48,7 @@ public abstract class FgtVideoTaskBase extends BaseFragment {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public boolean onBackPressed() {
|
|
|
- Dialog dialog = ViewUtil.showConfirmDialog(getContext(),
|
|
|
- "提示",
|
|
|
- "你确定要放弃奖励吗?",
|
|
|
- "放弃", "继续观看",
|
|
|
- d -> giveUpTask(),
|
|
|
- d -> LogUtil.logI("continue watch video"));
|
|
|
- dialog.setCancelable(false);
|
|
|
- dialog.show();
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
+ //放弃任务
|
|
|
public void giveUpTask() {
|
|
|
if (acceptedTask != null) {
|
|
|
SheepApp.getInstance()
|
|
|
@@ -65,16 +60,21 @@ public abstract class FgtVideoTaskBase extends BaseFragment {
|
|
|
.subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
@Override
|
|
|
public void onError(BaseMessage baseMessage) {
|
|
|
+ getActivity().finish();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onNext(BaseMessage baseMessage) {
|
|
|
+ getActivity().finish();
|
|
|
}
|
|
|
});
|
|
|
+ } else {
|
|
|
+ getActivity().finish();
|
|
|
}
|
|
|
- getActivity().finish();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ //重新提交弹窗
|
|
|
protected void resubmitAutoCheck() {
|
|
|
Dialog dialog = ViewUtil.showConfirmDialog(getContext(),
|
|
|
"提示",
|
|
|
@@ -86,6 +86,7 @@ public abstract class FgtVideoTaskBase extends BaseFragment {
|
|
|
dialog.show();
|
|
|
}
|
|
|
|
|
|
+ //提交任务
|
|
|
protected void commitAutoTask() {
|
|
|
JSONObject params = new JSONObject();
|
|
|
String gps = LocationUtils.getInstance().getLongitudeLatitude();
|
|
|
@@ -102,19 +103,25 @@ public abstract class FgtVideoTaskBase extends BaseFragment {
|
|
|
CommonUtil.getInstance().updateAutoCheck(null);
|
|
|
//这里领取了奖励,要刷新用户信息
|
|
|
CommonUtil.getInstance().updateUserInfo(null);
|
|
|
- ViewUtil.showMsgDialog(getContext(),
|
|
|
- "奖励已完成,获得奖励" + releaseTask.getShowValue(DataUtil.getInstance().getUserEntity().isVIP()),
|
|
|
- "恭喜你", true);
|
|
|
+ if(getActivity()!=null){
|
|
|
+ AndroidSchedulers.mainThread().scheduleDirect(() -> {
|
|
|
+ String releaseTaskJson = GsonUtils.getGlobalGson().toJson(releaseTask);
|
|
|
+ Intent intent = getActivity().getIntent().putExtra(KEY_RELEASE_TASK,releaseTaskJson);
|
|
|
+ getActivity().setResult(Activity.RESULT_OK,intent);
|
|
|
+ getActivity().finish();
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onError(BaseMessage baseMessage) {
|
|
|
- G.showToast(baseMessage);
|
|
|
+ G.showToast(baseMessage.getMsg());
|
|
|
resubmitAutoCheck();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ //接收任务
|
|
|
protected void acceptTask() {
|
|
|
String device_id = DeviceUtil.getDeviceId(SheepApp.getInstance());
|
|
|
UMConfigUtils.Event.TASK_ACCEPT.onEvent("device_id", device_id, "release_task_id", releaseTaskId);
|
|
|
@@ -137,6 +144,7 @@ public abstract class FgtVideoTaskBase extends BaseFragment {
|
|
|
} else {
|
|
|
hideProgress();
|
|
|
G.showToast(baseMessage.getErrorMsg());
|
|
|
+ getActivity().finish();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -149,6 +157,7 @@ public abstract class FgtVideoTaskBase extends BaseFragment {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ //给商城任务随机商品
|
|
|
public void randomGoods() {
|
|
|
SheepApp.getInstance()
|
|
|
.getNetComponent()
|
|
|
@@ -157,7 +166,6 @@ public abstract class FgtVideoTaskBase extends BaseFragment {
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
.subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
-
|
|
|
@Override
|
|
|
public void onNext(BaseMessage baseMessage) {
|
|
|
hideProgress();
|
|
|
@@ -172,6 +180,7 @@ public abstract class FgtVideoTaskBase extends BaseFragment {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ //加载接收的任务
|
|
|
public void loadAcceptedTask() {
|
|
|
CommonUtil.getInstance().getAcceptedTask(releaseTaskId, at -> {
|
|
|
if (at == null) {
|
|
|
@@ -179,45 +188,49 @@ public abstract class FgtVideoTaskBase extends BaseFragment {
|
|
|
return;
|
|
|
}
|
|
|
acceptedTask = at;
|
|
|
- if (watchCount == 0) {
|
|
|
+ if (watchCount == 0)
|
|
|
loadAd();
|
|
|
- } else {
|
|
|
- Dialog dialog = ViewUtil.showConfirmDialog(getContext(),
|
|
|
- "提示",
|
|
|
- "你需要观看" + releaseTask.getTask().getVideo_num() + "个视频, 即可获得" +
|
|
|
- releaseTask.getShowValue(DataUtil.getInstance().getUserEntity().isVIP()),
|
|
|
- "放弃", "继续观看",
|
|
|
- d -> giveUpTask(),
|
|
|
- d -> loadAd());
|
|
|
- dialog.setCancelable(false);
|
|
|
- dialog.show();
|
|
|
- }
|
|
|
+ else
|
|
|
+ VideoTaskDialogUtil.showContinueWatchWarningDialog(
|
|
|
+ getContext(),
|
|
|
+ releaseTask,
|
|
|
+ d -> loadAd(),
|
|
|
+ d -> giveUpTask()
|
|
|
+ );
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- protected void handleNext() {
|
|
|
+ //尝试获取奖励
|
|
|
+ protected void tryGetReward() {
|
|
|
watchCount++;
|
|
|
- if (watchCount >= releaseTask.getTask().getVideo_num()) {
|
|
|
+ if (watchCount >= releaseTask.getTask().getVideo_num())
|
|
|
commitAutoTask();
|
|
|
- } else {
|
|
|
- Dialog dialog = ViewUtil.showConfirmDialog(getContext(),
|
|
|
- "提示",
|
|
|
- "你需要观看" + (releaseTask.getTask().getVideo_num() - watchCount) + "个视频, 即可获得" +
|
|
|
- releaseTask.getShowValue(DataUtil.getInstance().getUserEntity().isVIP()),
|
|
|
- "放弃", "继续观看",
|
|
|
- d -> giveUpTask(),
|
|
|
- d -> loadAd());
|
|
|
- dialog.setCancelable(false);
|
|
|
- dialog.show();
|
|
|
- }
|
|
|
+ else
|
|
|
+ VideoTaskDialogUtil.showContinueWatchWarningDialog(
|
|
|
+ getContext(),
|
|
|
+ releaseTask,
|
|
|
+ d -> loadAd(),
|
|
|
+ d -> giveUpTask()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onBackPressed() {
|
|
|
+ VideoTaskDialogUtil.showGiveUpWarningDialog(
|
|
|
+ getContext(),
|
|
|
+ d -> LogUtil.logI("continue watch video"),
|
|
|
+ d -> giveUpTask()
|
|
|
+ );
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onResume(){
|
|
|
+ public void onResume() {
|
|
|
super.onResume();
|
|
|
- if(goNext){
|
|
|
+ if (goNext) {
|
|
|
goNext = false;
|
|
|
- handleNext();
|
|
|
+ tryGetReward();
|
|
|
}
|
|
|
}
|
|
|
|