|
|
@@ -1,102 +1,29 @@
|
|
|
package com.sheep.gamegroup.module.task.fragments;
|
|
|
|
|
|
-import android.text.TextUtils;
|
|
|
-import android.view.MotionEvent;
|
|
|
-import android.view.View;
|
|
|
-import android.widget.Button;
|
|
|
-import android.widget.ImageView;
|
|
|
-import android.widget.TextView;
|
|
|
-
|
|
|
-import com.kfzs.duanduan.cardview.ScreenUtil;
|
|
|
-import com.kfzs.duanduan.utils.ApkUtils;
|
|
|
-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.GlideImageLoader;
|
|
|
-import com.sheep.gamegroup.util.Jump2View;
|
|
|
+import android.widget.Toast;
|
|
|
+import com.lygame.wrapper.interfaces.IRewardVideoController;
|
|
|
+import com.lygame.wrapper.interfaces.IRewardVideoLoadCallback;
|
|
|
+import com.lygame.wrapper.interfaces.IRewardVideoPlayCallback;
|
|
|
+import com.lygame.wrapper.sdk.LySdk;
|
|
|
import com.sheep.gamegroup.util.LogUtil;
|
|
|
-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.R;
|
|
|
-import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
-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 butterknife.BindView;
|
|
|
-import butterknife.OnClick;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
/**
|
|
|
- * 掌酷广告视频
|
|
|
+ * 游可盈广告视频
|
|
|
*/
|
|
|
-public class FgtVideoTaskZK extends FgtVideoTaskBase {
|
|
|
-
|
|
|
- @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 VideoAd currentVideoAd;
|
|
|
-
|
|
|
- @Override
|
|
|
- public int getLayoutId() {
|
|
|
- return R.layout.activity_video_task;
|
|
|
- }
|
|
|
+public class FgtVideoTaskZK extends FgtVideoTaskBase {
|
|
|
+ private static final String TAG = "掌酷视频广告页";
|
|
|
|
|
|
- @Override
|
|
|
- public void onResume() {
|
|
|
- super.onResume();
|
|
|
- videoPlayerView.onVideoResume();
|
|
|
- configActionBtn();
|
|
|
- }
|
|
|
+ //是否领过奖了
|
|
|
+ boolean hasGetReward = false;
|
|
|
|
|
|
- @Override
|
|
|
- public void onPause() {
|
|
|
- super.onPause();
|
|
|
- videoPlayerView.onVideoPause();
|
|
|
- }
|
|
|
+ private AtomicReference<IRewardVideoController> controllerRef = new AtomicReference<>();
|
|
|
|
|
|
- @Override
|
|
|
- public void onDestroy() {
|
|
|
- if (currentVideoAd != null) {
|
|
|
- currentVideoAd.trigger(VideoAd.TYPE_VIDEO_CLOSE);
|
|
|
- }
|
|
|
- super.onDestroy();
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
protected 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
|
|
|
@@ -109,197 +36,72 @@ public class FgtVideoTaskZK extends FgtVideoTaskBase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //加载激励视频
|
|
|
+ @Override
|
|
|
protected void loadAd() {
|
|
|
- ADVideoHelper.loadVideoAD((ret, ad, msg) -> {
|
|
|
- getActivity().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(getContext(),
|
|
|
- "不好",
|
|
|
- "没获取到视频小片,需要再次获取吗?",
|
|
|
- "放弃", "重试",
|
|
|
- d -> giveUpTask(),
|
|
|
- d -> loadAd()).show();
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
+ int adId = 47906;
|
|
|
+
|
|
|
+ LySdk.loadRewardVideo(getActivity(), String.valueOf(adId), new IRewardVideoLoadCallback() {
|
|
|
+ @Override
|
|
|
+ public void onFailed(int i, String s) {
|
|
|
|
|
|
- private void configActionBtn() {
|
|
|
- if (getActivity() == null || getActivity().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;
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void onLoaded(IRewardVideoController iRewardVideoController) {
|
|
|
+ controllerRef.set(iRewardVideoController);
|
|
|
+ showAd();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- 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);
|
|
|
- tryGetReward();
|
|
|
- }
|
|
|
-
|
|
|
- @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 showAd() {
|
|
|
+ IRewardVideoController controller;
|
|
|
+ if ((controller = controllerRef.getAndSet(null)) != null) {
|
|
|
+ controller.show(new IRewardVideoPlayCallback() {
|
|
|
+ @Override
|
|
|
+ public void onAdShow() {
|
|
|
|
|
|
- private void jumpWeb() {
|
|
|
- if (currentVideoAd == null) return;
|
|
|
- Jump2View.getInstance().goWeb(getContext(), currentVideoAd.url);
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- private void openApp() {
|
|
|
- if (currentVideoAd == null) return;
|
|
|
- currentVideoAd.trigger(VideoAd.TYPE_ACTIVE);
|
|
|
- currentVideoAd.trigger(VideoAd.TYPE_OPEN);
|
|
|
- PackageUtil.startApp(getContext(), currentVideoAd.package_name);
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void onInterTriggered() {
|
|
|
+ //Toast.makeText(getContext(), "广告点击了", Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
|
|
|
- private void downloadApp() {
|
|
|
- if (currentVideoAd == null) return;
|
|
|
- videoPlayerView.onVideoPause();
|
|
|
- currentVideoAd.trigger(VideoAd.TYPE_DOWNLOAD);
|
|
|
- showDownloadDialog();
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void onAdClose() {
|
|
|
+ //用户点击关闭了界面
|
|
|
+ if (!hasGetReward) {
|
|
|
+ //未领奖,调用放弃任务接口
|
|
|
+ giveUpTask();
|
|
|
+ } else {
|
|
|
+ if (getActivity() != null)
|
|
|
+ getActivity().finish();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- private void installApp() {
|
|
|
- if (currentVideoAd == null) return;
|
|
|
- currentVideoAd.trigger(VideoAd.TYPE_INSTALL);
|
|
|
- ApkUtils.installApk(getContext(), currentVideoAd.path);
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void onVideoComplete() {
|
|
|
|
|
|
- private void installApp(VideoAd ad) {
|
|
|
- if (ad == null) return;
|
|
|
- ad.trigger(VideoAd.TYPE_INSTALL);
|
|
|
- ApkUtils.installApk(getContext(), ad.path);
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- private void showAppConfirmDialog(String title, String btnText, ViewUtil.OnConfirmDialogListener listener) {
|
|
|
- View rootView = View.inflate(getContext(), 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(getActivity(), 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(getContext(), title, rootView, "取消", btnText,
|
|
|
- d -> {
|
|
|
- d.dismiss();
|
|
|
- videoPlayerView.onVideoResume();
|
|
|
- },
|
|
|
- listener).show();
|
|
|
+ @Override
|
|
|
+ public void onRewarded() {
|
|
|
+ //满足领奖条件,去领奖
|
|
|
+ hasGetReward = true;
|
|
|
+ tryGetReward();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ Toast.makeText(getContext(), "广告未加载成功", Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private void showDownloadDialog() {
|
|
|
- final DialogProgress progress = DialogProgress.showDialog(getActivity(), 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;
|
|
|
- getActivity().runOnUiThread(() -> {
|
|
|
- if (progress.getAlertDialog().isShowing()) {
|
|
|
- progress.getTextView().setText(percent + "%");
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onStatus(String status, String msg) {
|
|
|
- getActivity().runOnUiThread(() -> {
|
|
|
- if (getActivity() == null || getActivity().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);
|
|
|
-
|
|
|
+ @Override
|
|
|
+ public int getLayoutId() {
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
}
|