|
@@ -0,0 +1,530 @@
|
|
|
|
|
+package com.sheep.gamegroup.module.task;
|
|
|
|
|
+
|
|
|
|
|
+import android.Manifest;
|
|
|
|
|
+import android.content.pm.PackageManager;
|
|
|
|
|
+import android.os.Build;
|
|
|
|
|
+import android.os.Bundle;
|
|
|
|
|
+import android.support.annotation.NonNull;
|
|
|
|
|
+import android.support.v4.app.ActivityCompat;
|
|
|
|
|
+import android.support.v4.content.ContextCompat;
|
|
|
|
|
+import android.text.TextUtils;
|
|
|
|
|
+import android.view.MotionEvent;
|
|
|
|
|
+import android.view.View;
|
|
|
|
|
+import android.view.WindowManager;
|
|
|
|
|
+import android.widget.Button;
|
|
|
|
|
+import android.widget.ImageView;
|
|
|
|
|
+import android.widget.TextView;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.kfzs.duanduan.cardview.ScreenUtil;
|
|
|
|
|
+import com.kfzs.duanduan.utils.ApkUtils;
|
|
|
|
|
+import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
|
|
+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.module.task.helper.ADDownloader;
|
|
|
|
|
+import com.sheep.gamegroup.module.task.helper.ADVideoHelper;
|
|
|
|
|
+import com.sheep.gamegroup.module.task.helper.VideoAd;
|
|
|
|
|
+import com.sheep.gamegroup.util.CommonUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.DeviceUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.GlideImageLoader;
|
|
|
|
|
+import com.sheep.gamegroup.util.Jump2View;
|
|
|
|
|
+import com.sheep.gamegroup.util.LocationUtils;
|
|
|
|
|
+import com.sheep.gamegroup.util.LogUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.UMConfigUtils;
|
|
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
|
|
+import com.sheep.gamegroup.view.customview.SheepGSYVideoView;
|
|
|
|
|
+import com.sheep.gamegroup.view.dialog.DialogProgress;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.BuildConfig;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.R;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
|
|
|
|
|
+import com.shuyu.gsyvideoplayer.GSYVideoManager;
|
|
|
|
|
+import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder;
|
|
|
|
|
+import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack;
|
|
|
|
|
+import com.shuyu.gsyvideoplayer.video.base.GSYVideoView;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Locale;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+import butterknife.BindView;
|
|
|
|
|
+import butterknife.OnClick;
|
|
|
|
|
+import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
|
|
+import io.reactivex.schedulers.Schedulers;
|
|
|
|
|
+
|
|
|
|
|
+public class OldVideoTaskActivity extends BaseActivity {
|
|
|
|
|
+
|
|
|
|
|
+ @BindView(R.id.video_player_view)
|
|
|
|
|
+ SheepGSYVideoView videoPlayerView;
|
|
|
|
|
+ @BindView(R.id.mask_view)
|
|
|
|
|
+ View mask_view;
|
|
|
|
|
+ @BindView(R.id.desc_tv)
|
|
|
|
|
+ TextView desc_tv;
|
|
|
|
|
+ @BindView(R.id.name_tv)
|
|
|
|
|
+ TextView name_tv;
|
|
|
|
|
+ @BindView(R.id.action_btn)
|
|
|
|
|
+ Button action_btn;
|
|
|
|
|
+ @BindView(R.id.logo_iv)
|
|
|
|
|
+ ImageView logo_iv;
|
|
|
|
|
+ @BindView(R.id.countdown_view)
|
|
|
|
|
+ TextView countdown_view;
|
|
|
|
|
+
|
|
|
|
|
+ private int releaseTaskId = -1;
|
|
|
|
|
+
|
|
|
|
|
+ private Release_task releaseTask;
|
|
|
|
|
+ private TaskAcceptedEty acceptedTask;
|
|
|
|
|
+
|
|
|
|
|
+ private VideoAd currentVideoAd;
|
|
|
|
|
+ private int watchCount = 0;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected int getLayoutId() {
|
|
|
|
|
+ return R.layout.activity_video_task;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onBackPressed() {
|
|
|
|
|
+ ViewUtil.showConfirmDialog(OldVideoTaskActivity.this,
|
|
|
|
|
+ "提示",
|
|
|
|
|
+ "你确定要放弃奖励吗?",
|
|
|
|
|
+ "放弃", "继续观看",
|
|
|
|
|
+ d -> giveUpTask(),
|
|
|
|
|
+ d -> LogUtil.logI("continue watch video")).show();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onCreate(Bundle b) {
|
|
|
|
|
+ super.onCreate(b);
|
|
|
|
|
+ getWindow().addFlags(
|
|
|
|
|
+ WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
|
|
|
|
|
+ WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onWindowFocusChanged(boolean hasFocus) {
|
|
|
|
|
+ super.onWindowFocusChanged(hasFocus);
|
|
|
|
|
+ int flag = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
|
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && G.checkDeviceHasNavigationBar(this)) {
|
|
|
|
|
+ getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);//白色
|
|
|
|
|
+ flag |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
|
|
|
|
+ View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
|
|
|
|
+ View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | // hide
|
|
|
|
|
+ View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
|
|
|
|
+ }
|
|
|
|
|
+ getWindow().getDecorView().setSystemUiVisibility(flag);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onResume() {
|
|
|
|
|
+ super.onResume();
|
|
|
|
|
+ videoPlayerView.onVideoResume();
|
|
|
|
|
+ configActionBtn();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onPause() {
|
|
|
|
|
+ super.onPause();
|
|
|
|
|
+ videoPlayerView.onVideoPause();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
|
|
+ if (checkLocationPermission()) {
|
|
|
|
|
+ loadReleaseTask();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onDestroy() {
|
|
|
|
|
+ if (currentVideoAd != null) {
|
|
|
|
|
+ currentVideoAd.trigger(VideoAd.TYPE_VIDEO_CLOSE);
|
|
|
|
|
+ }
|
|
|
|
|
+ super.onDestroy();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void initView() {
|
|
|
|
|
+ videoPlayerView.setShowControlView(false);
|
|
|
|
|
+ videoPlayerView.getBackButton().setVisibility(View.GONE);
|
|
|
|
|
+ videoPlayerView.getFullscreenButton().setVisibility(View.GONE);
|
|
|
|
|
+ videoPlayerView.getBottomProgressBar().setVisibility(View.GONE);
|
|
|
|
|
+
|
|
|
|
|
+ mask_view.setOnTouchListener((v, event) -> {
|
|
|
|
|
+ if (event.getAction() == MotionEvent.ACTION_UP && currentVideoAd != null) {
|
|
|
|
|
+ currentVideoAd.clickX = (int) event.getRawX();
|
|
|
|
|
+ currentVideoAd.clickY = (int) event.getRawY();
|
|
|
|
|
+ currentVideoAd.trigger(VideoAd.TYPE_CLICK);
|
|
|
|
|
+ if (videoPlayerView.getCurrentState() == GSYVideoView.CURRENT_STATE_PAUSE) {
|
|
|
|
|
+ videoPlayerView.onVideoResume();
|
|
|
|
|
+ } else if (videoPlayerView.getCurrentState() == GSYVideoView.CURRENT_STATE_PLAYING) {
|
|
|
|
|
+ videoPlayerView.onVideoPause();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void initData() {
|
|
|
|
|
+ releaseTaskId = getIntent().getIntExtra("task_id", -1);
|
|
|
|
|
+ if (checkLocationPermission()) {
|
|
|
|
|
+ loadReleaseTask();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void loadReleaseTask() {
|
|
|
|
|
+ CommonUtil.getInstance().getTaskDesc(releaseTaskId, rt -> {
|
|
|
|
|
+ if (rt == null) {
|
|
|
|
|
+ G.showToast("没有该任务");
|
|
|
|
|
+ finish();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ releaseTask = rt;
|
|
|
|
|
+ if (releaseTask.getAccepted_task_id() > 0) {
|
|
|
|
|
+ loadAcceptedTask();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ LogUtil.logI("---------------没有接受任务---------------");
|
|
|
|
|
+ acceptTask();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void loadAcceptedTask() {
|
|
|
|
|
+ CommonUtil.getInstance().getAcceptedTask(releaseTaskId, at -> {
|
|
|
|
|
+ if (at == null) {
|
|
|
|
|
+ acceptTask();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ acceptedTask = at;
|
|
|
|
|
+ if (watchCount == 0) {
|
|
|
|
|
+ loadAd();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ViewUtil.showConfirmDialog(OldVideoTaskActivity.this,
|
|
|
|
|
+ "提示",
|
|
|
|
|
+ "你需要观看" + releaseTask.getTask().getVideo_num() + "个视频, 即可获得" + releaseTask.getBonusText() + "元",
|
|
|
|
|
+ "放弃", "继续观看",
|
|
|
|
|
+ d -> giveUpTask(),
|
|
|
|
|
+ d -> loadAd()).show();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void loadAd() {
|
|
|
|
|
+ ADVideoHelper.loadVideoAD((ret, ad, msg) -> {
|
|
|
|
|
+ runOnUiThread(() -> {
|
|
|
|
|
+ if (ret) {
|
|
|
|
|
+ currentVideoAd = ad;
|
|
|
|
|
+ desc_tv.setText(currentVideoAd.desc);
|
|
|
|
|
+ name_tv.setText(currentVideoAd.title);
|
|
|
|
|
+ GlideImageLoader.circleImage(logo_iv, currentVideoAd.logo);
|
|
|
|
|
+ playVideo();
|
|
|
|
|
+ configActionBtn();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ViewUtil.showConfirmDialog(OldVideoTaskActivity.this,
|
|
|
|
|
+ "不好",
|
|
|
|
|
+ "没获取到视频小片,需要再次获取吗?",
|
|
|
|
|
+ "放弃", "重试",
|
|
|
|
|
+ d -> giveUpTask(),
|
|
|
|
|
+ d -> loadAd()).show();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void configActionBtn() {
|
|
|
|
|
+ if (this.isDestroyed() || currentVideoAd == null || currentVideoAd.url == null) return;
|
|
|
|
|
+ if (!currentVideoAd.url.endsWith(".apk")) {
|
|
|
|
|
+ action_btn.setText("查看详情");
|
|
|
|
|
+ action_btn.setTag(0);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ String path = ADDownloader.getUrlPath(currentVideoAd.url);
|
|
|
|
|
+ if (PackageUtil.isAppInstalled(SheepApp.getInstance(), currentVideoAd.package_name)) {
|
|
|
|
|
+ action_btn.setText("打开应用");
|
|
|
|
|
+ action_btn.setTag(1);
|
|
|
|
|
+ } else if (!TextUtils.isEmpty(path)) {
|
|
|
|
|
+ action_btn.setText("立即安装");
|
|
|
|
|
+ action_btn.setTag(2);
|
|
|
|
|
+ currentVideoAd.path = path;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ action_btn.setText("下载应用");
|
|
|
|
|
+ action_btn.setTag(3);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @OnClick(R.id.action_btn)
|
|
|
|
|
+ public void onActionClick(View v) {
|
|
|
|
|
+ int action = (int) v.getTag();
|
|
|
|
|
+ switch (action) {
|
|
|
|
|
+ case 0:
|
|
|
|
|
+ jumpWeb();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ openApp();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ installApp();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 3:
|
|
|
|
|
+ downloadApp();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void playVideo() {
|
|
|
|
|
+ GSYVideoOptionBuilder gsyVideoOption = new GSYVideoOptionBuilder();
|
|
|
|
|
+ gsyVideoOption.setIsTouchWiget(false)
|
|
|
|
|
+ .setRotateViewAuto(true)
|
|
|
|
|
+ .setLockLand(true)
|
|
|
|
|
+ .setAutoFullWithSize(false)
|
|
|
|
|
+ .setShowFullAnimation(false)
|
|
|
|
|
+ .setUrl(currentVideoAd.videoUrl)
|
|
|
|
|
+ .setNeedLockFull(true)
|
|
|
|
|
+ .setCacheWithPlay(false)
|
|
|
|
|
+ .setGSYVideoProgressListener((progress, secProgress, currentPosition, duration) -> {
|
|
|
|
|
+ countdown_view.setText("" + ((duration - currentPosition) / 1000));
|
|
|
|
|
+ })
|
|
|
|
|
+ .setVideoAllCallBack(new GSYSampleCallBack() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onPrepared(String url, Object... objects) {
|
|
|
|
|
+ super.onPrepared(url, objects);
|
|
|
|
|
+ LogUtil.println("initPlay", "onPrepared", url, objects);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onAutoComplete(String url, Object... objects) {
|
|
|
|
|
+ super.onAutoComplete(url, objects);
|
|
|
|
|
+ currentVideoAd.trigger(VideoAd.TYPE_VIDEO_END);
|
|
|
|
|
+ watchCount++;
|
|
|
|
|
+ if (watchCount >= releaseTask.getTask().getVideo_num()) {
|
|
|
|
|
+ commitAutoTask();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ViewUtil.showConfirmDialog(OldVideoTaskActivity.this,
|
|
|
|
|
+ "提示",
|
|
|
|
|
+ "你需要观看" + (releaseTask.getTask().getVideo_num() - watchCount) + "个视频, 即可获得" + releaseTask.getBonusText() + "元",
|
|
|
|
|
+ "放弃", "继续观看",
|
|
|
|
|
+ d -> giveUpTask(),
|
|
|
|
|
+ d -> loadAd()).show();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onPlayError(String url, Object... objects) {
|
|
|
|
|
+ super.onPlayError(url, objects);
|
|
|
|
|
+ long curPosition = GSYVideoManager.instance().getCurPlayerManager().getCurrentPosition();
|
|
|
|
|
+ LogUtil.println("initPlay", "onPlayError", url, curPosition);
|
|
|
|
|
+ }
|
|
|
|
|
+ }).build(videoPlayerView);
|
|
|
|
|
+ videoPlayerView.startPlayLogic();
|
|
|
|
|
+ currentVideoAd.trigger(VideoAd.TYPE_VIDEO_START);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void acceptTask() {
|
|
|
|
|
+ String device_id = DeviceUtil.getDeviceId(SheepApp.getInstance());
|
|
|
|
|
+ UMConfigUtils.Event.TASK_ACCEPT.onEvent("device_id", device_id, "release_task_id", releaseTaskId);
|
|
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
|
|
+ object.put("device_id", device_id);
|
|
|
|
|
+ object.put("release_task_id", releaseTaskId);
|
|
|
|
|
+ object.put("create_time", System.currentTimeMillis() / 1000L);
|
|
|
|
|
+ object.put("app_version", String.valueOf(BuildConfig.VERSION_CODE));
|
|
|
|
|
+ SheepApp.getInstance()
|
|
|
|
|
+ .getNetComponent()
|
|
|
|
|
+ .getApiService()
|
|
|
|
|
+ .acceptedTask(object)
|
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
|
|
+ G.showToast(baseMessage.getErrorMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
+ releaseTask.setIs_running(true);
|
|
|
|
|
+ releaseTask.getTask().setRelease_task_id(releaseTask.getId());
|
|
|
|
|
+ loadAcceptedTask();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void commitAutoTask() {
|
|
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
|
|
+ String gps = LocationUtils.getInstance().getLongitudeLatitude();
|
|
|
|
|
+ params.put("gps", gps);
|
|
|
|
|
+ params.put("release_task_id", releaseTaskId);
|
|
|
|
|
+ params.put("create_time", System.currentTimeMillis() / 1000L);//这里添加时间戳,防止用户抓包后重复使用
|
|
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().commitAutoTask(params)
|
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(getApplicationContext()) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
+ CommonUtil.getInstance().updateAutoCheck(null);
|
|
|
|
|
+ //这里领取了奖励,要刷新用户信息
|
|
|
|
|
+ CommonUtil.getInstance().updateUserInfo(null);
|
|
|
|
|
+ String amount = releaseTask.getBonusText();
|
|
|
|
|
+ try {
|
|
|
|
|
+ Map h = JSON.parseObject(baseMessage.getData() + "");
|
|
|
|
|
+
|
|
|
|
|
+ amount = h.get("amount") + "";
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ViewUtil.showMsgDialog(OldVideoTaskActivity.this, String.format(Locale.CHINA, "奖励已完成,获得奖励%s元", TextUtils.isEmpty(amount) ? releaseTask.getBonusText() : amount), "恭喜你", true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
|
|
+ G.showToast(baseMessage);
|
|
|
|
|
+ resubmitAutoCheck();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void giveUpTask() {
|
|
|
|
|
+ if(acceptedTask!=null) {
|
|
|
|
|
+ SheepApp.getInstance()
|
|
|
|
|
+ .getNetComponent()
|
|
|
|
|
+ .getApiService()
|
|
|
|
|
+ .giveUpTask(acceptedTask.getId())
|
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ finish();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void resubmitAutoCheck() {
|
|
|
|
|
+ ViewUtil.showConfirmDialog(OldVideoTaskActivity.this,
|
|
|
|
|
+ "提示",
|
|
|
|
|
+ "提交任务失败,需要重新提交吗?",
|
|
|
|
|
+ "放弃", "重试",
|
|
|
|
|
+ d -> giveUpTask(),
|
|
|
|
|
+ d -> commitAutoTask()).show();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void jumpWeb() {
|
|
|
|
|
+ if (currentVideoAd == null) return;
|
|
|
|
|
+ Jump2View.getInstance().goWeb(this, currentVideoAd.url);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void openApp() {
|
|
|
|
|
+ if (currentVideoAd == null) return;
|
|
|
|
|
+ currentVideoAd.trigger(VideoAd.TYPE_ACTIVE);
|
|
|
|
|
+ currentVideoAd.trigger(VideoAd.TYPE_OPEN);
|
|
|
|
|
+ PackageUtil.startApp(this, currentVideoAd.package_name);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void downloadApp() {
|
|
|
|
|
+ if (currentVideoAd == null) return;
|
|
|
|
|
+ videoPlayerView.onVideoPause();
|
|
|
|
|
+ currentVideoAd.trigger(VideoAd.TYPE_DOWNLOAD);
|
|
|
|
|
+ showDownloadDialog();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void installApp() {
|
|
|
|
|
+ if (currentVideoAd == null) return;
|
|
|
|
|
+ currentVideoAd.trigger(VideoAd.TYPE_INSTALL);
|
|
|
|
|
+ ApkUtils.installApk(this, currentVideoAd.path);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void installApp(VideoAd ad) {
|
|
|
|
|
+ if (ad == null) return;
|
|
|
|
|
+ ad.trigger(VideoAd.TYPE_INSTALL);
|
|
|
|
|
+ ApkUtils.installApk(this, ad.path);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void showAppConfirmDialog(String title, String btnText, ViewUtil.OnConfirDialogListener listener) {
|
|
|
|
|
+ View rootView = View.inflate(this, R.layout.video_ad_confirm, null);
|
|
|
|
|
+ ImageView app_logo_iv = rootView.findViewById(R.id.app_logo_iv);
|
|
|
|
|
+ TextView app_name_tv = rootView.findViewById(R.id.app_name_tv);
|
|
|
|
|
+ TextView app_desc_tv = rootView.findViewById(R.id.app_desc_tv);
|
|
|
|
|
+ int radius = ScreenUtil.dip2px(this, 8);
|
|
|
|
|
+ GlideImageLoader.roundedCornersImage(app_logo_iv, currentVideoAd.logo, radius);
|
|
|
|
|
+ app_name_tv.setText(currentVideoAd.title);
|
|
|
|
|
+ app_desc_tv.setText(currentVideoAd.desc);
|
|
|
|
|
+ videoPlayerView.onVideoPause();
|
|
|
|
|
+ ViewUtil.showConfirmDialog(this, title, rootView, "取消", btnText,
|
|
|
|
|
+ d -> {
|
|
|
|
|
+ d.dismiss();
|
|
|
|
|
+ videoPlayerView.onVideoResume();
|
|
|
|
|
+ },
|
|
|
|
|
+ listener).show();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void showDownloadDialog() {
|
|
|
|
|
+ final DialogProgress progress = DialogProgress.showDialog(this, true);
|
|
|
|
|
+ progress.getAlertDialog().setOnDismissListener(d -> {
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+ final VideoAd thisAd = currentVideoAd.clone();
|
|
|
|
|
+ new ADDownloader()
|
|
|
|
|
+ .setListener(new ADDownloader.ProgressListener() {
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onProgress(long offset, long total) {
|
|
|
|
|
+ LogUtil.logE(offset + " /// " + total);
|
|
|
|
|
+ long percent = offset * 100 / total;
|
|
|
|
|
+ runOnUiThread(() -> {
|
|
|
|
|
+ if (progress.getAlertDialog().isShowing()) {
|
|
|
|
|
+ progress.getTextView().setText(percent + "%");
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onStatus(String status, String msg) {
|
|
|
|
|
+ runOnUiThread(() -> {
|
|
|
|
|
+ if (OldVideoTaskActivity.this.isDestroyed()) return;
|
|
|
|
|
+ if (progress.getAlertDialog().isShowing()) {
|
|
|
|
|
+ progress.getAlertDialog().dismiss();
|
|
|
|
|
+ }
|
|
|
|
|
+ if ("COMPLETED".equals(status)) {
|
|
|
|
|
+ thisAd.path = msg;
|
|
|
|
|
+ configActionBtn();
|
|
|
|
|
+ installApp(thisAd);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ videoPlayerView.onVideoResume();
|
|
|
|
|
+ LogUtil.logE(status + " /// " + msg);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .init()
|
|
|
|
|
+ .start(currentVideoAd);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public boolean checkLocationPermission() {
|
|
|
|
|
+ List<String> permissions = new ArrayList<String>();
|
|
|
|
|
+ boolean result = true;
|
|
|
|
|
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
+ permissions.add(Manifest.permission.ACCESS_COARSE_LOCATION);
|
|
|
|
|
+ result = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (permissions.size() > 0) {
|
|
|
|
|
+ String[] permissionArrays = new String[permissions.size()];
|
|
|
|
|
+ permissionArrays = permissions.toArray(permissionArrays);
|
|
|
|
|
+ ActivityCompat.requestPermissions(this,
|
|
|
|
|
+ permissionArrays,
|
|
|
|
|
+ 1111);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|