From 5d475ef2f856a1415c5b2de255a1c1088d6a2ec2 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 31 三月 2021 19:17:57 +0800
Subject: [PATCH] 白色背景修改

---
 BuWanVideo/src/com/weikou/beibeivideo/ui/ad/SplashADFragment.java |  144 ++++++++++++++++++++++++++++++-----------------
 1 files changed, 92 insertions(+), 52 deletions(-)

diff --git a/BuWanVideo/src/com/weikou/beibeivideo/ui/ad/SplashADFragment.java b/BuWanVideo/src/com/weikou/beibeivideo/ui/ad/SplashADFragment.java
index 4dbb5e3..c0587be 100644
--- a/BuWanVideo/src/com/weikou/beibeivideo/ui/ad/SplashADFragment.java
+++ b/BuWanVideo/src/com/weikou/beibeivideo/ui/ad/SplashADFragment.java
@@ -13,7 +13,9 @@
 import android.widget.TextView;
 
 import com.bytedance.sdk.openadsdk.TTSplashAd;
+import com.qq.e.ads.splash.SplashAD;
 import com.weikou.beibeivideo.R;
+import com.weikou.beibeivideo.entity.ad.AdPidInfo;
 import com.weikou.beibeivideo.entity.ad.AdPositionEnum;
 import com.weikou.beibeivideo.entity.ad.SplashAdLoadInfo;
 import com.weikou.beibeivideo.ui.SplashActivity;
@@ -36,6 +38,7 @@
     private FrameLayout fl_ad;
 
     private static SplashAdLoadInfo adLoadInfo;
+    public static long lastShowTime = 0L;
 
     private AdShowListener mAdShowListener;
 
@@ -43,29 +46,39 @@
         this.mAdShowListener = mAdShowListener;
     }
 
-    /**
-     * 鍔犺浇寮�灞忓箍鍛�
-     *
-     * @param adType
-     */
+    private SplashADFragment() {
+
+    }
+
+    public static SplashADFragment newInstance(AdPidInfo pid1, AdPidInfo pid2) {
+        SplashADFragment fragment = new SplashADFragment();
+        Bundle bundle = new Bundle();
+        bundle.putSerializable("pid1", pid1);
+        bundle.putSerializable("pid2", pid2);
+        fragment.setArguments(bundle);
+        return fragment;
+    }
+
+
     /**
      * 鍔犺浇寮�灞忓箍鍛�
      *
      * @param context
-     * @param adType1
-     * @param pid1
+     * @param adPidInfo1
+     * @param adPidInfo2
+     * @param skip
+     * @param time
      * @param first
+     * @param adLoadResultListener
      */
-    public static void loadAd(Context context, AdUtil.AD_TYPE adType1, String pid1, boolean first, AdLoadResultListener adLoadResultListener) {
-        if (adType1 == null) {
-            adType1 = AdUtil.getAdType(context, AdPositionEnum.splash);
-            pid1 = AdUtil.getAdPid(context, AdPositionEnum.splash);
+    public static void loadAd(Context context, AdPidInfo adPidInfo1, AdPidInfo adPidInfo2, View skip, TextView time, boolean first, AdLoadResultListener adLoadResultListener) {
+        if (adPidInfo1 == null) {
+            if (adLoadResultListener != null)
+                adLoadResultListener.onNoAd();
+            return;
         }
 
-        final AdUtil.AD_TYPE adType = adType1;
-        final String pid = pid1;
-
-        SplashAdUtil.loadAD(pid, adType, context, null, null, null, new SplashAdUtil.SplashAdListener() {
+        SplashAdUtil.loadAD(adPidInfo1.getPid(), adPidInfo1.getAdType(), context, skip, time, new SplashAdUtil.SplashAdListener() {
             @Override
             public void onAdLoad(SplashAdLoadInfo adLoadInfo) {
                 SplashADFragment.adLoadInfo = adLoadInfo;
@@ -82,22 +95,9 @@
 
             @Override
             public void noAd() {//鍒濇鍔犺浇鏈姞杞藉嚭骞垮憡
-                if (AdUtil.AD_TYPE.csj == adType) {
-                    if (first) {
-                        loadAd(context, AdUtil.AD_TYPE.gdt, BeibeiConstant.GDT_SPLASH_POSITION_ID, false, adLoadResultListener);
-                    } else {
-                        if (adLoadResultListener != null)
-                            adLoadResultListener.onNoAd();
-                    }
-                } else if (AdUtil.AD_TYPE.gdt == adType) {
-                    //鍐嶆鍔犺浇绌垮北鐢插箍鍛�
-                    if (first) {
-                        loadAd(context, AdUtil.AD_TYPE.csj, CSJConstant.SPLASH_AD, false, adLoadResultListener);
-                    } else {
-                        if (adLoadResultListener != null)
-                            adLoadResultListener.onNoAd();
-                    }
 
+                if (first) {
+                    loadAd(context, adPidInfo2, null, skip, time, false, adLoadResultListener);
                 } else {
                     if (adLoadResultListener != null)
                         adLoadResultListener.onNoAd();
@@ -109,7 +109,7 @@
     private Timer timer;
     private int leftTime = 5;
 
-    public void showAd() {
+    public boolean showAd() {
         if (isAdLoaded()) {
             //绌垮北鐢插箍鍛�
             if (adLoadInfo.getCsjAd() != null) {
@@ -123,34 +123,48 @@
                 ad.setSplashInteractionListener(new TTSplashAd.AdInteractionListener() {
                     @Override
                     public void onAdClicked(View view, int type) {
+
                     }
 
                     @Override
                     public void onAdShow(View view, int type) {
+                        lastShowTime = System.currentTimeMillis();
                     }
 
                     @Override
                     public void onAdSkip() {
-
+                        if (mAdShowListener != null)
+                            mAdShowListener.onClose();
                     }
 
                     @Override
                     public void onAdTimeOver() {
-
+                        if (mAdShowListener != null)
+                            mAdShowListener.onClose();
                     }
                 });
-
-                if (timer == null)
-                    timer = new Timer();
-                timer.cancel();
+                if (timer != null)
+                    timer.cancel();
+                timer = new Timer();
+                ll_input.setVisibility(View.VISIBLE);
                 timer.schedule(new TimerTask() {
                     @Override
                     public void run() {
                         leftTime--;
                         if (leftTime < 0) {
                             timer.cancel();
-                            //杩涘叆涓婚〉
-                            mAdShowListener.onClose();
+                            if (ad_close_time != null)
+                                ad_close_time.post(new Runnable() {
+                                    @Override
+                                    public void run() {
+                                        if (ad_close_time != null)
+                                            ad_close_time.setVisibility(View.GONE);
+                                        if (ll_input != null)
+                                            ll_input.setClickable(true);
+                                    }
+                                });
+
+
                             return;
                         } else {
                             //鍊掕鏃�
@@ -162,7 +176,7 @@
                                             ad_close_time.setText(leftTime + "");
                                     }
                                 });
-
+                            ll_input.setClickable(false);
                         }
                     }
                 }, 1000, 1000);
@@ -171,17 +185,22 @@
                 ll_input.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View v) {
-                        fl_ad.removeAllViews();
                         mAdShowListener.onClose();
                     }
                 });
 
-
+                adLoadInfo = null;
             } else if (adLoadInfo.getGdtSplashAd() != null) {
-                adLoadInfo.getGdtSplashAd().showAd(fl_ad);
+                SplashAD splashAD = adLoadInfo.getGdtSplashAd();
+                splashAD.showAd(fl_ad);
+                lastShowTime = System.currentTimeMillis();
+                adLoadInfo = null;
             }
 
+            return true;
         }
+
+        return false;
     }
 
     /**
@@ -196,17 +215,10 @@
         return false;
     }
 
-    public static SplashADFragment newInstance() {
-        Bundle bundle = new Bundle();
-
-        SplashADFragment fragment = new SplashADFragment();
-        fragment.setArguments(bundle);
-        return fragment;
-    }
-
     private void initView(View root) {
         ll_input = root.findViewById(R.id.ll_input);
         ad_close_time = root.findViewById(R.id.ad_close_time);
+        fl_ad = root.findViewById(R.id.fl_ad);
     }
 
     @Nullable
@@ -214,7 +226,35 @@
     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
         View root = LayoutInflater.from(getContext()).inflate(R.layout.fragment_splash_ad, null);
         initView(root);
-        showAd();
+        if (!showAd()) {
+            Bundle arguments = getArguments();
+            AdPidInfo adPidInfo1 = null;
+            AdPidInfo adPidInfo2 = null;
+            if (arguments != null) {
+                adPidInfo1 = (AdPidInfo) arguments.getSerializable("pid1");
+                adPidInfo2 = (AdPidInfo) arguments.getSerializable("pid2");
+            }
+
+            loadAd(getContext(), adPidInfo1, adPidInfo2, ll_input, ad_close_time, true, new SplashADFragment.AdLoadResultListener() {
+
+                @Override
+                public void onAdLoad(SplashAdLoadInfo adLoadInfo) {
+                    showAd();
+                }
+
+                @Override
+                public void onNoAd() {
+                    if (mAdShowListener != null)
+                        mAdShowListener.onClose();
+                }
+
+                @Override
+                public void onClose() {
+                    if (mAdShowListener != null)
+                        mAdShowListener.onClose();
+                }
+            });
+        }
         return root;
     }
 

--
Gitblit v1.8.0