From 2c5b6e472c368e80d85b8ea2b461c9ea62981d9b Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期日, 08 十月 2023 11:28:56 +0800
Subject: [PATCH] 广告升级/bug修复

---
 BuWanVideo/src/com/weikou/beibeivideo/util/ad/SplashAdUtil.java |  130 +++++++++++++++++++++---------------------
 1 files changed, 65 insertions(+), 65 deletions(-)

diff --git a/BuWanVideo/src/com/weikou/beibeivideo/util/ad/SplashAdUtil.java b/BuWanVideo/src/com/weikou/beibeivideo/util/ad/SplashAdUtil.java
index d927a90..cc9b1ce 100644
--- a/BuWanVideo/src/com/weikou/beibeivideo/util/ad/SplashAdUtil.java
+++ b/BuWanVideo/src/com/weikou/beibeivideo/util/ad/SplashAdUtil.java
@@ -1,11 +1,15 @@
 package com.weikou.beibeivideo.util.ad;
 
 import android.app.Activity;
+import android.content.Context;
+import android.os.SystemClock;
+import android.util.Log;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.TextView;
 
 import com.bytedance.sdk.openadsdk.AdSlot;
+import com.bytedance.sdk.openadsdk.TTAdConstant;
 import com.bytedance.sdk.openadsdk.TTAdManager;
 import com.bytedance.sdk.openadsdk.TTAdNative;
 import com.bytedance.sdk.openadsdk.TTSplashAd;
@@ -14,11 +18,14 @@
 import com.qq.e.ads.splash.SplashADListener;
 import com.qq.e.comm.util.AdError;
 import com.weikou.beibeivideo.entity.ad.AdTypeVO;
+import com.weikou.beibeivideo.entity.ad.SplashAdLoadInfo;
 import com.weikou.beibeivideo.util.BeibeiConstant;
 import com.weikou.beibeivideo.util.DimenUtils;
 import com.weikou.beibeivideo.util.downutil.StringUtils;
 
 public class SplashAdUtil {
+
+    private static final String TAG = "SplashAdUtil";
 
     /**
      * 鍔犺浇寮�灞忓箍鍛�
@@ -26,32 +33,33 @@
      * @param adType
      * @param context
      * @param skip
-     * @param vg_ad
      * @param tv_time
      * @param splashAdListener
      */
-    public static void loadAD(AdUtil.AD_TYPE adType, Activity context, final View skip, ViewGroup vg_ad, final TextView tv_time, final SplashAdListener splashAdListener) {
-        if (adType==null) {
+    public static void loadAD(String pid, AdUtil.AD_TYPE adType, Context context, final View skip, final TextView tv_time, final SplashAdListener splashAdListener) {
+        if (adType == null) {
             splashAdListener.close();
             return;
         }
-        if (AdUtil.AD_TYPE.csj==adType) {
-            loadCSJ(context, skip, vg_ad, splashAdListener);
-        } else if (AdUtil.AD_TYPE.gdt==adType) {
-            loadGDT(context, skip, vg_ad, tv_time, splashAdListener);
+        if (AdUtil.AD_TYPE.csj == adType) {
+            loadCSJ(pid, context, skip, splashAdListener);
+        } else if (AdUtil.AD_TYPE.gdt == adType) {
+            loadGDT(pid, context, skip, tv_time, splashAdListener);
         } else {
             splashAdListener.close();
         }
     }
 
-    private static void loadGDT(Activity context, final View skip, ViewGroup vg_ad, final TextView tv_time, final SplashAdListener splashAdListener) {
+    private static SplashAD gdtSplashAD;
+
+    private static void loadGDT(String code, Context context, final View skip, final TextView tv_time, final SplashAdListener splashAdListener) {
 
         String channel = ManifestDataUtil.getAppMetaData(context, "UMENG_CHANNEL");
-        String code = BeibeiConstant.GDT_SPLASH_POSITION_ID;
-        if ("vivo".equalsIgnoreCase(channel)) {
-            code = BeibeiConstant.GDT_SPLASH_VIVO_POSITION_ID;
-        }
-        new SplashAD(context, skip, code, new SplashADListener() {
+        if (StringUtils.isNullOrEmpty(code))
+            code = BeibeiConstant.GDT_SPLASH_POSITION_ID;
+        if (skip != null)
+            skip.setVisibility(View.VISIBLE);
+        gdtSplashAD = new SplashAD(context, code, new SplashADListener() {
             @Override
             public void onADDismissed() {
                 splashAdListener.close();
@@ -59,33 +67,38 @@
 
             @Override
             public void onNoAD(AdError adError) {
+                Log.i(TAG, "GDT:onNoAD-" + adError.getErrorMsg());
                 splashAdListener.noAd();
             }
 
 
             @Override
             public void onADPresent() {
-                skip.post(new Runnable() {
-                    @Override
-                    public void run() {
-                        skip.setVisibility(View.VISIBLE);
-                    }
-                });
+                if (skip != null)
+                    skip.post(new Runnable() {
+                        @Override
+                        public void run() {
+                            skip.setVisibility(View.VISIBLE);
+                        }
+                    });
             }
 
             @Override
             public void onADClicked() {
                 System.out.println("");
+                splashAdListener.onAdClick();
+
             }
 
             @Override
             public void onADTick(final long l) {
-                tv_time.post(new Runnable() {
-                    @Override
-                    public void run() {
-                        tv_time.setText(l / 1000 + "");
-                    }
-                });
+                if (tv_time != null)
+                    tv_time.post(new Runnable() {
+                        @Override
+                        public void run() {
+                            tv_time.setText(l / 1000 + "");
+                        }
+                    });
             }
 
             @Override
@@ -95,15 +108,12 @@
 
             @Override
             public void onADLoaded(long l) {
-                System.out.println("");
-                skip.post(new Runnable() {
-                    @Override
-                    public void run() {
-                        skip.setVisibility(View.VISIBLE);
-                    }
-                });
+                Log.i(TAG, "GDT:onADLoaded-" + l);
+                splashAdListener.onAdLoad(new SplashAdLoadInfo(gdtSplashAD, System.currentTimeMillis() + (l - SystemClock.elapsedRealtime())));
             }
-        }, 0).fetchAndShowIn(vg_ad);
+        }, 3500);
+
+        gdtSplashAD.fetchAdOnly();
     }
 
 
@@ -112,12 +122,21 @@
      *
      * @param context
      * @param skip
-     * @param vg_ad
      * @param splashAdListener
      */
-    private static void loadCSJ(Activity context, final View skip, final ViewGroup vg_ad, final SplashAdListener splashAdListener) {
-        skip.setVisibility(View.GONE);
-        TTAdManager ttAdManager = TTAdManagerHolder.get();
+    private static void loadCSJ(String code, Context context, final View skip, final SplashAdListener splashAdListener) {
+        if (skip != null)
+            skip.setVisibility(View.GONE);
+        TTAdManager ttAdManager = null;
+
+        try {
+            ttAdManager = TTAdManagerHolder.get();
+        } catch (Exception e) {
+        }
+        if (ttAdManager == null) {
+            splashAdListener.noAd();
+            return;
+        }
         TTAdNative mTTAdNative = ttAdManager.createAdNative(context.getApplicationContext());
         //绌垮北鐢插箍鍛�
         int width = DimenUtils.getScreenWidth(context.getApplicationContext());
@@ -126,11 +145,8 @@
             width = 720;
         if (height == 0)
             height = 1080;
-        String channel = ManifestDataUtil.getAppMetaData(context, "UMENG_CHANNEL");
-        String code = CSJConstant.SPLASH_AD;
-        if ("vivo".equalsIgnoreCase(channel)) {
-            code = CSJConstant.SPLASH_AD_VIVO;
-        }
+        if (StringUtils.isNullOrEmpty(code))
+            code = CSJConstant.SPLASH_AD;
 
         AdSlot adSlot = new AdSlot.Builder()
                 .setCodeId(code)
@@ -155,37 +171,21 @@
                     splashAdListener.noAd();
                     return;
                 }
-                View view = ad.getSplashView();
-                vg_ad.removeAllViews();
-                //鎶奡plashView 娣诲姞鍒癡iewGroup涓�
-                vg_ad.addView(view);
-                //璁剧疆SplashView鐨勪氦浜掔洃鍚櫒
-                ad.setSplashInteractionListener(new TTSplashAd.AdInteractionListener() {
-                    @Override
-                    public void onAdClicked(View view, int type) {
-                    }
 
-                    @Override
-                    public void onAdShow(View view, int type) {
-                    }
+                splashAdListener.onAdLoad(new SplashAdLoadInfo(System.currentTimeMillis() + 1000 * 60 * 30L, ad));
 
-                    @Override
-                    public void onAdSkip() {
-                        splashAdListener.close();
-                    }
-
-                    @Override
-                    public void onAdTimeOver() {
-                        splashAdListener.close();
-                    }
-                });
             }
-        });
+        }, 4000);
 
 
     }
 
     public interface SplashAdListener {
+
+        public void onAdLoad(SplashAdLoadInfo adLoadInfo);
+
+        public void onAdClick();
+
         public void close();
 
         public void noAd();

--
Gitblit v1.8.0