From 2eec3de87b6b616a69a46c1f97c2397159031d2f Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 21 十一月 2023 18:01:43 +0800
Subject: [PATCH] 广告升级/bug修复

---
 BuWanVideo/src/com/weikou/beibeivideo/util/ad/ExpressAdManager.java |  269 +++++++++--------------------------------------------
 1 files changed, 49 insertions(+), 220 deletions(-)

diff --git a/BuWanVideo/src/com/weikou/beibeivideo/util/ad/ExpressAdManager.java b/BuWanVideo/src/com/weikou/beibeivideo/util/ad/ExpressAdManager.java
index 4b8c757..498dfd7 100644
--- a/BuWanVideo/src/com/weikou/beibeivideo/util/ad/ExpressAdManager.java
+++ b/BuWanVideo/src/com/weikou/beibeivideo/util/ad/ExpressAdManager.java
@@ -8,22 +8,17 @@
 import android.widget.FrameLayout;
 
 import com.bytedance.sdk.openadsdk.AdSlot;
+import com.bytedance.sdk.openadsdk.TTAdConstant;
 import com.bytedance.sdk.openadsdk.TTAdDislike;
 import com.bytedance.sdk.openadsdk.TTAdManager;
 import com.bytedance.sdk.openadsdk.TTAdNative;
 import com.bytedance.sdk.openadsdk.TTNativeExpressAd;
-import com.google.gson.Gson;
 import com.qq.e.ads.cfg.VideoOption;
 import com.qq.e.ads.nativ.ADSize;
 import com.qq.e.ads.nativ.NativeExpressAD;
 import com.qq.e.ads.nativ.NativeExpressADView;
-import com.qq.e.ads.nativ.express2.AdEventListener;
-import com.qq.e.ads.nativ.express2.NativeExpressAD2;
-import com.qq.e.ads.nativ.express2.NativeExpressADData2;
-import com.qq.e.ads.nativ.express2.VideoOption2;
 import com.qq.e.comm.util.AdError;
 import com.weikou.beibeivideo.entity.ad.ExpressAdContainer;
-import com.weikou.beibeivideo.ui.recommend.SearchActivity;
 import com.weikou.beibeivideo.util.BeibeiConstant;
 import com.weikou.beibeivideo.util.DimenUtils;
 
@@ -48,9 +43,13 @@
         sourceType = adSource;
         this.mContext = context;
         if (sourceType == AdUtil.AD_TYPE.csj) {
-            TTAdManager ttAdManager = TTAdManagerHolder.get();
-            mTTAdNative = ttAdManager.createAdNative(context);
-//            TTAdManagerHolder.get().requestPermissionIfNecessary(context);
+            TTAdManager ttAdManager = null;
+            try {
+                ttAdManager = TTAdManagerHolder.get();
+                mTTAdNative = ttAdManager.createAdNative(context);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         }
     }
 
@@ -66,7 +65,7 @@
      * @param adLoadListener
      */
     public void loadAd(int widthDP, int heightDP, String pid, int count, final IAdLoadListener adLoadListener) {
-        if (sourceType == AdUtil.AD_TYPE.gdt) {
+        if (sourceType == AdUtil.AD_TYPE.gdt||sourceType == AdUtil.AD_TYPE.gdt2) {
             loadGDT(pid, widthDP, heightDP, count, new IGDTAdLoadListener() {
                 @Override
                 public void onSuccess(List<NativeExpressADView> adList) {
@@ -77,30 +76,7 @@
                         }
                     adLoadListener.onSuccess(adContainerList);
                 }
-
-                @Override
-                public void onSuccess2(List<NativeExpressADData2> adList) {
-
-                }
             }, mContext);
-        } else if (sourceType == AdUtil.AD_TYPE.gdt2) {
-            loadGDT2(pid, widthDP, heightDP, count, new IGDTAdLoadListener() {
-                @Override
-                public void onSuccess(List<NativeExpressADView> adList) {
-
-                }
-
-                @Override
-                public void onSuccess2(List<NativeExpressADData2> adList) {
-                    List<ExpressAdContainer> adContainerList = new ArrayList<>();
-                    if (adList != null)
-                        for (NativeExpressADData2 ad : adList) {
-                            adContainerList.add(new ExpressAdContainer(ad));
-                        }
-                    adLoadListener.onSuccess(adContainerList);
-                }
-            }, mContext);
-
         } else if (sourceType == AdUtil.AD_TYPE.csj) {
             loadCSJ(pid, widthDP, heightDP, count, new ICSJAdLoadListener() {
                 @Override
@@ -127,12 +103,12 @@
         //鍔犺浇澶у浘
         int deviceWidth = DimenUtils.getScreenWidth(mContext);
         deviceWidth = DimenUtils.px2dip(mContext, deviceWidth);
-        int width = deviceWidth - 6;
+        int width = deviceWidth - 9 * 2;
         int height = (int) (width * 0.8);
         String pid = null;
         if (sourceType == AdUtil.AD_TYPE.csj) {
             pid = CSJConstant.RECOMMEND_BIG_IMG_AD;
-            height = (int) (width * 0.56);
+            height = (int) (width * 0.78);
         } else if (sourceType == AdUtil.AD_TYPE.gdt) {
             pid = BeibeiConstant.GDT_RECOMMAND_NATIVE;
         } else if (sourceType == AdUtil.AD_TYPE.gdt2) {
@@ -247,7 +223,7 @@
         String pid = null;
         if (sourceType == AdUtil.AD_TYPE.csj) {
             pid = "945379581";
-        } else if (sourceType == AdUtil.AD_TYPE.gdt) {
+        } else if (sourceType == AdUtil.AD_TYPE.gdt2) {
             pid = BeibeiConstant.GDT_SEARCH_RESULT_MIN_NATIVE;
         }
         //鑾峰彇灞忓箷鐨勫
@@ -306,8 +282,8 @@
         String pid = null;
         if (sourceType == AdUtil.AD_TYPE.csj) {
             pid = CSJConstant.APP_EXIT;
-        } else if (sourceType == AdUtil.AD_TYPE.gdt) {
-            pid = BeibeiConstant.GDT_EXIT_DIALOG;
+        } else {
+            pid = GDTConstant.PID_2_EXIT;
         }
         //鑾峰彇灞忓箷鐨勫
         int deviceWidth = DimenUtils.getScreenWidth(mContext);
@@ -329,7 +305,7 @@
         String pid = null;
         if (sourceType == AdUtil.AD_TYPE.csj) {
             pid = CSJConstant.VIDEO_SEARCH;
-        } else if (sourceType == AdUtil.AD_TYPE.gdt) {
+        } else if (sourceType == AdUtil.AD_TYPE.gdt2) {
             pid = BeibeiConstant.GDT_SEARCH_NATIVE;
         }
         int height = (int) (widthDP / 1.78f);
@@ -349,7 +325,7 @@
     private void loadGDT(String positionId, int widthDP, int heightDP, int count, final IGDTAdLoadListener adLoadListener, Context context) {
 
 
-        NativeExpressAD nativeExpressAD = new NativeExpressAD(context, new ADSize(ADSize.FULL_WIDTH, ADSize.AUTO_HEIGHT),
+        NativeExpressAD nativeExpressAD = new NativeExpressAD(context, new ADSize(widthDP, ADSize.AUTO_HEIGHT),
                 positionId, new NativeExpressAD.NativeExpressADListener() {
 
             @Override
@@ -389,16 +365,6 @@
             }
 
             @Override
-            public void onADOpenOverlay(NativeExpressADView nativeExpressADView) {
-
-            }
-
-            @Override
-            public void onADCloseOverlay(NativeExpressADView nativeExpressADView) {
-
-            }
-
-            @Override
             public void onNoAD(AdError adError) {
                 if (adLoadListener != null)
                     adLoadListener.onSuccess(null);
@@ -408,47 +374,7 @@
                 .setAutoPlayPolicy(VideoOption.AutoPlayPolicy.WIFI) // WIFI 鐜涓嬪彲浠ヨ嚜鍔ㄦ挱鏀捐棰�
                 .setAutoPlayMuted(true) // 鑷姩鎾斁鏃朵负闈欓煶
                 .build()); //
-        nativeExpressAD.setVideoPlayPolicy(VideoOption.VideoPlayPolicy.AUTO);
         nativeExpressAD.loadAD(count);
-    }
-
-    /**
-     * 2.0鐗堟湰骞跨偣閫氬師鐢�
-     *
-     * @param positionId
-     * @param widthDP
-     * @param heightDP
-     * @param count
-     * @param adLoadListener
-     * @param context
-     */
-    private void loadGDT2(String positionId, int widthDP, int heightDP, int count, final IGDTAdLoadListener adLoadListener, Context context) {
-
-        Log.i(TAG, String.format("loadGDT2:positionId-%s  widthDP-%s heightDP-%s", positionId, widthDP, heightDP));
-
-        NativeExpressAD2 nativeExpressAD2 = new NativeExpressAD2(context, positionId, new NativeExpressAD2.AdLoadListener() {
-            @Override
-            public void onLoadSuccess(List<NativeExpressADData2> list) {
-                if (adLoadListener != null)
-                    adLoadListener.onSuccess2(list);
-            }
-
-            @Override
-            public void onNoAD(AdError adError) {
-                if (adLoadListener != null)
-                    adLoadListener.onSuccess2(null);
-            }
-        });
-
-        nativeExpressAD2.setAdSize(widthDP, heightDP);
-        VideoOption2.Builder builder = new VideoOption2.Builder();
-        builder.setAutoPlayPolicy(VideoOption2.AutoPlayPolicy.WIFI) // WIFI 鐜涓嬪彲浠ヨ嚜鍔ㄦ挱鏀捐棰�
-                .setAutoPlayMuted(true) // 鑷姩鎾斁鏃朵负闈欓煶
-                .setDetailPageMuted(false)  // 瑙嗛璇︽儏椤垫挱鏀炬椂涓嶉潤闊�
-                .setMaxVideoDuration(0) // 璁剧疆杩斿洖瑙嗛骞垮憡鐨勬渶澶ц棰戞椂闀匡紙闂尯闂达紝鍙崟鐙缃級锛屽崟浣�:绉掞紝榛樿涓� 0 浠h〃鏃犻檺鍒讹紝鍚堟硶杈撳叆涓猴細5<=maxVideoDuration<=60. 姝よ缃細褰卞搷骞垮憡濉厖锛岃璋ㄦ厧璁剧疆
-                .setMinVideoDuration(0); // 璁剧疆杩斿洖瑙嗛骞垮憡鐨勬渶灏忚棰戞椂闀匡紙闂尯闂达紝鍙崟鐙缃級锛屽崟浣�:绉掞紝榛樿涓� 0 浠h〃鏃犻檺鍒讹紝 姝よ缃細褰卞搷骞垮憡濉厖锛岃璋ㄦ厧璁剧疆
-        nativeExpressAD2.setVideoOption2(builder.build());
-        nativeExpressAD2.loadAd(count);
     }
 
     /**
@@ -468,6 +394,11 @@
                 .setExpressViewAcceptedSize(width, height)
                 .setAdCount(count) //璇锋眰骞垮憡鏁伴噺涓�1鍒�3鏉�
                 .build();
+        if (mTTAdNative == null) {
+            if (adLoadListener != null)
+                adLoadListener.onSuccess(null);
+            return;
+        }
         mTTAdNative.loadNativeExpressAd(adSlot, new TTAdNative.NativeExpressAdListener() {
             @Override
             public void onError(int i, String s) {
@@ -506,68 +437,33 @@
                     ((ViewGroup) ad.getGdt().getParent()).removeAllViews();
                 }
                 fl_ad.addView(ad.getGdt());
-            } else if (ad.getGdt2() != null) {
-                if (fl_ad.getChildCount() > 0 && fl_ad.getChildAt(0) == ad.getGdt2().getAdView()) {
-                    return;
-                }
-                fl_ad.removeAllViews();
-
-                ad.getGdt2().setAdEventListener(new AdEventListener() {
-                    @Override
-                    public void onClick() {
-
-                    }
-
-                    @Override
-                    public void onExposed() {
-
-                    }
-
-                    @Override
-                    public void onRenderSuccess() {
-                        if (ad.getGdt2().getAdView().getParent() != null) {
-                            ((ViewGroup) ad.getGdt2().getAdView().getParent()).removeAllViews();
-                        }
-                        fl_ad.addView(ad.getGdt2().getAdView());
-                    }
-
-                    @Override
-                    public void onRenderFail() {
-
-                    }
-
-                    @Override
-                    public void onAdClosed() {
-                        if (adEventListener != null) {
-                            adEventListener.closeAd(ad);
-                        }
-                    }
-                });
-                ad.getGdt2().render();
-
             } else if (ad.getCsj() != null) {
                 if (fl_ad.getChildCount() > 0 && fl_ad.getChildAt(0) == ad.getCsj().getExpressAdView()) {
                     return;
                 }
 
+
                 ad.getCsj().setDislikeCallback(activity, new TTAdDislike.DislikeInteractionCallback() {
 
+
                     @Override
-                    public void onSelected(int i, String s) {
+                    public void onShow() {
+
+                    }
+
+                    @Override
+                    public void onSelected(int i, String s, boolean b) {
                         if (adEventListener != null) {
                             adEventListener.closeAd(ad);
                         }
                     }
+
 
                     @Override
                     public void onCancel() {
 
                     }
 
-                    @Override
-                    public void onRefuse() {
-
-                    }
                 });
                 ad.getCsj().render();
                 if (ad.getCsj().getExpressAdView().getParent() != null) {
@@ -600,43 +496,8 @@
             list.add(ad);
             if (adRenderListener != null)
                 adRenderListener.onRenderSuccess(list);
-        } else if (ad.getGdt2() != null) {
-            ad.getGdt2().setAdEventListener(new AdEventListener() {
-                @Override
-                public void onClick() {
-
-                }
-
-                @Override
-                public void onExposed() {
-
-                }
-
-                @Override
-                public void onRenderSuccess() {
-                    List<ExpressAdContainer> list = new ArrayList<>();
-                    list.add(ad);
-                    if (adRenderListener != null)
-                        adRenderListener.onRenderSuccess(list);
-                }
-
-                @Override
-                public void onRenderFail() {
-                    List<ExpressAdContainer> list = new ArrayList<>();
-                    list.add(ad);
-                    if (adRenderListener != null)
-                        adRenderListener.onRenderFail(list);
-                }
-
-                @Override
-                public void onAdClosed() {
-                    if (adEventListener != null)
-                        adEventListener.closeAd(ad);
-                }
-            });
-            ad.getGdt2().render();
-
         } else if (ad.getCsj() != null) {
+            Log.i(TAG, "骞垮憡鏇濆厜:csj");
             ad.getCsj().setExpressInteractionListener(new TTNativeExpressAd.ExpressAdInteractionListener() {
                 @Override
                 public void onAdClicked(View view, int i) {
@@ -668,22 +529,26 @@
             if (activity != null)
                 ad.getCsj().setDislikeCallback(activity, new TTAdDislike.DislikeInteractionCallback() {
 
+
                     @Override
-                    public void onSelected(int i, String s) {
+                    public void onShow() {
+
+                    }
+
+                    @Override
+                    public void onSelected(int i, String s, boolean b) {
                         if (adEventListener != null) {
                             adEventListener.closeAd(ad);
                         }
                     }
+
 
                     @Override
                     public void onCancel() {
 
                     }
 
-                    @Override
-                    public void onRefuse() {
 
-                    }
                 });
             ad.getCsj().render();
         }
@@ -706,35 +571,7 @@
 
         if (ad.getGdt() != null) {
             return;
-        } else if (ad.getGdt2() != null) {
-            ad.getGdt2().setAdEventListener(new AdEventListener() {
-                @Override
-                public void onClick() {
-
-                }
-
-                @Override
-                public void onExposed() {
-
-                }
-
-                @Override
-                public void onRenderSuccess() {
-
-                }
-
-                @Override
-                public void onRenderFail() {
-                }
-
-                @Override
-                public void onAdClosed() {
-                    if (adEventListener != null)
-                        adEventListener.closeAd(ad);
-                }
-            });
-
-        } else if (ad.getCsj() != null) {
+        }  else if (ad.getCsj() != null) {
             ad.getCsj().setExpressInteractionListener(new TTNativeExpressAd.ExpressAdInteractionListener() {
                 @Override
                 public void onAdClicked(View view, int i) {
@@ -758,22 +595,26 @@
             });
             ad.getCsj().setDislikeCallback(activity, new TTAdDislike.DislikeInteractionCallback() {
 
+
                 @Override
-                public void onSelected(int i, String s) {
+                public void onShow() {
+
+                }
+
+                @Override
+                public void onSelected(int i, String s, boolean b) {
                     if (adEventListener != null) {
                         adEventListener.closeAd(ad);
                     }
                 }
+
 
                 @Override
                 public void onCancel() {
 
                 }
 
-                @Override
-                public void onRefuse() {
 
-                }
             });
         }
 
@@ -805,17 +646,7 @@
                         }
                         fl_ad.removeAllViews();
                         fl_ad.addView(ad.getGdt());
-                    } else if (ad.getGdt2() != null) {
-                        if (fl_ad.getChildCount() > 0 && fl_ad.getChildAt(0) == ad.getGdt2().getAdView()) {
-                            return;
-                        }
-                        if (ad.getGdt2().getAdView().getParent() != null) {
-                            ((ViewGroup) ad.getGdt2().getAdView().getParent()).removeAllViews();
-                        }
-                        fl_ad.removeAllViews();
-                        fl_ad.addView(ad.getGdt2().getAdView());
-
-                    } else if (ad.getCsj() != null) {
+                    }else if (ad.getCsj() != null) {
                         if (fl_ad.getChildCount() > 0 && fl_ad.getChildAt(0) == ad.getCsj().getExpressAdView()) {
                             return;
                         }
@@ -844,8 +675,6 @@
 
     interface IGDTAdLoadListener {
         public void onSuccess(List<NativeExpressADView> adList);
-
-        public void onSuccess2(List<NativeExpressADData2> adList);
     }
 
     interface ICSJAdLoadListener {

--
Gitblit v1.8.0