|
|
@@ -2,6 +2,7 @@ package com.sheep.gamegroup.module.task;
|
|
|
|
|
|
import android.Manifest;
|
|
|
import android.content.pm.PackageManager;
|
|
|
+import android.os.Bundle;
|
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
import android.support.v4.content.ContextCompat;
|
|
|
@@ -15,11 +16,13 @@ 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;
|
|
|
@@ -29,16 +32,16 @@ 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.activity.helper.SplashHelper;
|
|
|
-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.umeng.socialize.utils.Log;
|
|
|
+import com.shuyu.gsyvideoplayer.video.GSYSampleADVideoPlayer;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
@@ -52,7 +55,11 @@ import io.reactivex.schedulers.Schedulers;
|
|
|
public class VideoTaskActivity extends BaseActivity {
|
|
|
|
|
|
@BindView(R.id.video_player_view)
|
|
|
- SheepGSYVideoView videoPlayerView;
|
|
|
+ GSYSampleADVideoPlayer videoPlayerView;
|
|
|
+ @BindView(R.id.mask_view)
|
|
|
+ View mask_view;
|
|
|
+ @BindView(R.id.desc_bottom_tv)
|
|
|
+ TextView desc_bottom_tv;
|
|
|
|
|
|
private int releaseTaskId = -1;
|
|
|
|
|
|
@@ -69,7 +76,27 @@ public class VideoTaskActivity extends BaseActivity {
|
|
|
|
|
|
@Override
|
|
|
public void onBackPressed() {
|
|
|
- super.onBackPressed();
|
|
|
+ ViewUtil.showConfirmDialog(VideoTaskActivity.this,
|
|
|
+ "提示",
|
|
|
+ "你确定要放弃奖励吗?",
|
|
|
+ "放弃", "继续观看",
|
|
|
+ d -> super.onBackPressed(),
|
|
|
+ d -> LogUtil.logI("continue watch video")).show();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCreate(Bundle b) {
|
|
|
+ super.onCreate(b);
|
|
|
+// int flag = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
|
|
|
+// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
|
+// flag |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
|
|
|
+// 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);
|
|
|
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -92,20 +119,31 @@ public class VideoTaskActivity extends BaseActivity {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void onDestroy() {
|
|
|
+ if (currentVideoAd != null) {
|
|
|
+ currentVideoAd.trigger(VideoAd.TYPE_VIDEO_CLOSE);
|
|
|
+ }
|
|
|
+ super.onDestroy();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public void initView() {
|
|
|
- hideSystemNavBar();
|
|
|
- hideSystemStatusBar();
|
|
|
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
- videoPlayerView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
- @Override
|
|
|
- public boolean onTouch(View v, MotionEvent event) {
|
|
|
- if (event.getAction() == MotionEvent.ACTION_UP && currentVideoAd != null) {
|
|
|
- currentVideoAd.clickX = (int) event.getRawX();
|
|
|
- currentVideoAd.clickY = (int) event.getRawY();
|
|
|
+ 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);
|
|
|
+ String path = ADDownloader.getUrlPath(currentVideoAd.url);
|
|
|
+ if (PackageUtil.isAppInstalled(SheepApp.getInstance(), currentVideoAd.package_name)) {
|
|
|
+ showOpenAppConfirmDialog();
|
|
|
+ }
|
|
|
+ if (!TextUtils.isEmpty(path)) {
|
|
|
+ showInstallConfigDialog();
|
|
|
+ } else {
|
|
|
showDownloadConfirmDialog();
|
|
|
}
|
|
|
- return false;
|
|
|
}
|
|
|
+ return true;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -150,13 +188,16 @@ public class VideoTaskActivity extends BaseActivity {
|
|
|
|
|
|
private void loadAd() {
|
|
|
ADVideoHelper.loadVideoAD((ret, ad, msg) -> {
|
|
|
- if (ret) {
|
|
|
- currentVideoAd = ad;
|
|
|
- playVideo();
|
|
|
- } else {
|
|
|
- G.showToast(msg);
|
|
|
- finish();
|
|
|
- }
|
|
|
+ runOnUiThread(() -> {
|
|
|
+ if (ret) {
|
|
|
+ currentVideoAd = ad;
|
|
|
+ desc_bottom_tv.setText(currentVideoAd.desc);
|
|
|
+ playVideo();
|
|
|
+ } else {
|
|
|
+ G.showToast(msg);
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -180,6 +221,7 @@ public class VideoTaskActivity extends BaseActivity {
|
|
|
@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();
|
|
|
@@ -201,6 +243,7 @@ public class VideoTaskActivity extends BaseActivity {
|
|
|
}
|
|
|
}).build(videoPlayerView);
|
|
|
videoPlayerView.startPlayLogic();
|
|
|
+ currentVideoAd.trigger(VideoAd.TYPE_VIDEO_START);
|
|
|
}
|
|
|
|
|
|
private void acceptTask() {
|
|
|
@@ -262,23 +305,96 @@ public class VideoTaskActivity extends BaseActivity {
|
|
|
@Override
|
|
|
public void onError(BaseMessage baseMessage) {
|
|
|
G.showToast(baseMessage);
|
|
|
+ resubmitAutoCheck();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private void resubmitAutoCheck() {
|
|
|
+ ViewUtil.showConfirmDialog(VideoTaskActivity.this,
|
|
|
+ "提示",
|
|
|
+ "提交任务失败,需要重新提交吗?",
|
|
|
+ "放弃", "重试",
|
|
|
+ d -> finish(),
|
|
|
+ d -> commitAutoTask()).show();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showOpenAppConfirmDialog() {
|
|
|
+ if (currentVideoAd == null) return;
|
|
|
+ showAppConfirmDialog("跳转", "打开应用", d -> {
|
|
|
+ currentVideoAd.trigger(VideoAd.TYPE_ACTIVE);
|
|
|
+ currentVideoAd.trigger(VideoAd.TYPE_OPEN);
|
|
|
+ PackageUtil.startApp(this, currentVideoAd.package_name);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
private void showDownloadConfirmDialog() {
|
|
|
if (currentVideoAd == null) return;
|
|
|
+ showAppConfirmDialog("下载", "立即下载", d -> {
|
|
|
+ currentVideoAd.trigger(VideoAd.TYPE_DOWNLOAD);
|
|
|
+ showDownloadDialog();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showInstallConfigDialog() {
|
|
|
+ if (currentVideoAd == null) return;
|
|
|
+ showAppConfirmDialog("安装", "立即安装", d -> {
|
|
|
+ currentVideoAd.trigger(VideoAd.TYPE_INSTALL);
|
|
|
+ ApkUtils.installApk(this, currentVideoAd.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.videoUrl, radius);
|
|
|
+ GlideImageLoader.roundedCornersImage(app_logo_iv, currentVideoAd.logo, radius);
|
|
|
app_name_tv.setText(currentVideoAd.title);
|
|
|
app_desc_tv.setText(currentVideoAd.desc);
|
|
|
- ViewUtil.showConfirmDialog(this, "下载", rootView, "取消", "立即下载",
|
|
|
- d -> d.dismiss(),
|
|
|
- d -> Log.e("adf", "download")).show();
|
|
|
+ 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);
|
|
|
+ final TextView percentView = new TextView(this);
|
|
|
+ progress.setTextView(percentView);
|
|
|
+ new ADDownloader()
|
|
|
+ .setListener(new ADDownloader.ProgressListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onProgress(long offset, long total) {
|
|
|
+ LogUtil.logE(offset + " /// " + total);
|
|
|
+ long percent = offset * 100 / total;
|
|
|
+ runOnUiThread(() -> {
|
|
|
+ percentView.setText(percent + "%");
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStatus(String status, String msg) {
|
|
|
+ runOnUiThread(() -> {
|
|
|
+ if ("COMPLETED".equals(status)) {
|
|
|
+ progress.getAlertDialog().dismiss();
|
|
|
+ showInstallConfigDialog();
|
|
|
+ } else {
|
|
|
+ videoPlayerView.onVideoResume();
|
|
|
+ progress.getAlertDialog().dismiss();
|
|
|
+ LogUtil.logE(status + " /// " + msg);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .init()
|
|
|
+ .start(currentVideoAd);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public boolean checkLocationPermission() {
|