From 8327000a0cce5e47226372e0e25c1e6faec497e7 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 12 一月 2022 16:56:43 +0800
Subject: [PATCH] 推送功能完善

---
 lib/utils/ad_util.dart |   53 +++++++++++++++++++++++++++++++----------------------
 1 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/lib/utils/ad_util.dart b/lib/utils/ad_util.dart
index ec845f4..7cbee53 100644
--- a/lib/utils/ad_util.dart
+++ b/lib/utils/ad_util.dart
@@ -7,30 +7,34 @@
 import 'package:locations/utils/string_util.dart';
 import 'package:flutter_tencentad/flutter_tencentad.dart';
 
+import 'ui_constant.dart';
+
 //绱ф�ヨ仈绯讳汉杈撳叆妗嗙‘瀹氫簨浠�
 typedef OnAdCallback = void Function(bool success, String msg);
 
+typedef OnRewardAdCallback = void Function(RewardAdStatus status, String msg);
+
+enum RewardAdStatus { fail, click, ready, verify, close }
+
 class AdUtil {
+  static AdinfoModel? splashAdInfo;
+
   static Future init() async {
     await CSJAdUtil.init();
     await GDTAdUtil.init();
+    splashAdInfo = await getAdInfo(AdPosition.splash);
   }
 
-  static void showSplashAd(
-      double width, double height, OnAdCallback adCallback) async {
-    //鍔犺浇骞垮憡
-  }
-
-  static Widget? loadSplash(AdinfoModel? adInfo, double width, double height,
+  static Widget loadSplash(AdinfoModel? adInfo, double width, double height,
       OnAdCallback adCallback) {
     if (adInfo == null) {
       adCallback(false, "骞垮憡淇℃伅涓虹┖");
-      return null;
+      return Container();
     }
 
     if (StringUtil.isNullOrEmpty(adInfo.type)) {
       adCallback(false, "骞垮憡绫诲瀷涓虹┖");
-      return null;
+      return Container();
     }
 
     if (adInfo.type == "csj") {
@@ -78,14 +82,14 @@
     }
   }
 
-  static loadReward(AdinfoModel? adInfo, OnAdCallback callback) async {
+  static loadReward(AdinfoModel? adInfo, OnRewardAdCallback callback) async {
     if (adInfo == null) {
-      callback(false, "骞垮憡淇℃伅涓虹┖");
+      callback(RewardAdStatus.fail, "骞垮憡淇℃伅涓虹┖");
       return null;
     }
 
     if (StringUtil.isNullOrEmpty(adInfo.type)) {
-      callback(false, "骞垮憡绫诲瀷涓虹┖");
+      callback(RewardAdStatus.fail, "骞垮憡绫诲瀷涓虹┖");
       return null;
     }
 
@@ -157,7 +161,7 @@
           //绌垮北鐢插箍鍛� ios appid 蹇呭~
           useTextureView: false,
           //浣跨敤TextureView鎺т欢鎾斁瑙嗛,榛樿涓篠urfaceView,褰撴湁SurfaceView鍐茬獊鐨勫満鏅紝鍙互浣跨敤TextureView 閫夊~
-          appName: "瀹氫綅杩借釜杞ㄨ抗",
+          appName: Constant.APP_NAME,
           //appname 蹇呭~
           allowShowNotify: true,
           //鏄惁鍏佽sdk灞曠ず閫氱煡鏍忔彁绀� 閫夊~
@@ -174,11 +178,11 @@
     }
   }
 
-  static Widget? loadSplash(
+  static Widget loadSplash(
       String? pid, double width, double height, OnAdCallback adCallback) {
     if (pid == null) {
       adCallback(false, "pid涓虹┖");
-      return null;
+      return Container();
     }
     return FlutterUnionad.splashAdView(
       //鏄惁浣跨敤涓�у寲妯$増  璁惧畾widget瀹介珮
@@ -286,7 +290,7 @@
     );
   }
 
-  static loadReward(String pid, OnAdCallback adCallback) async {
+  static loadReward(String pid, OnRewardAdCallback adCallback) async {
     FlutterUnionad.loadRewardVideoAd(
       mIsExpress: true,
       //鏄惁涓�у寲 閫夊~
@@ -315,23 +319,25 @@
         },
         onClick: () {
           print("婵�鍔卞箍鍛婄偣鍑�");
+          adCallback(RewardAdStatus.click, "婵�鍔卞箍鍛婄偣鍑�");
         },
         onFail: (error) {
           print("婵�鍔卞箍鍛婂け璐� $error");
-          adCallback(false, "婵�鍔卞箍鍛婂け璐� $error");
+          adCallback(RewardAdStatus.fail, "婵�鍔卞箍鍛婂け璐� $error");
         },
         onClose: () {
           print("婵�鍔卞箍鍛婂叧闂�");
+          adCallback(RewardAdStatus.close, "婵�鍔卞箍鍛婂叧闂�");
         },
         onSkip: () {
           print("婵�鍔卞箍鍛婅烦杩�");
         },
         onVerify: (bool isVerify, int rewardAmount, String rewardName,
             int errorCode, String message) {
-          adCallback(true, "鑾峰彇婵�鍔辨垚鍔�");
+          adCallback(RewardAdStatus.verify, "鑾峰彇婵�鍔辨垚鍔�");
         },
         onReady: () async {
-          print("婵�鍔卞箍鍛婇鍔犺浇鍑嗗灏辩华");
+          adCallback(RewardAdStatus.ready, "婵�鍔卞箍鍛婇鍔犺浇鍑嗗灏辩华");
           //鏄剧ず婵�鍔卞箍鍛�
           await FlutterUnionad.showRewardVideoAd();
         },
@@ -400,7 +406,7 @@
     }
   }
 
-  static Widget? loadSplash(
+  static Widget loadSplash(
       String? pid, double width, double height, OnAdCallback adCallback) {
     return FlutterTencentad.splashAdView(
       //android骞垮憡id
@@ -499,7 +505,7 @@
         ));
   }
 
-  static loadReward(String pid, OnAdCallback adCallback) async {
+  static loadReward(String pid, OnRewardAdCallback adCallback) async {
     await FlutterTencentad.loadRewardVideoAd(
         //android骞垮憡id
         androidId: pid,
@@ -521,19 +527,22 @@
         print("婵�鍔卞箍鍛婃樉绀�");
       }, onClick: () {
         print("婵�鍔卞箍鍛婄偣鍑�");
+        adCallback(RewardAdStatus.click, "婵�鍔卞箍鍛婄偣鍑�");
       }, onFail: (code, message) {
         print("婵�鍔卞箍鍛婂け璐� $code $message");
-        adCallback(false, "婵�鍔卞箍鍛婂け璐�");
+        adCallback(RewardAdStatus.fail, "婵�鍔卞箍鍛婂け璐�");
       }, onClose: () {
         print("婵�鍔卞箍鍛婂叧闂�");
+        adCallback(RewardAdStatus.close, "婵�鍔卞箍鍛婂叧闂�");
       }, onReady: () async {
         print("婵�鍔卞箍鍛婇鍔犺浇鍑嗗灏辩华");
+        adCallback(RewardAdStatus.ready, "婵�鍔卞箍鍛婇鍔犺浇鍑嗗灏辩华");
         await FlutterTencentad.showRewardVideoAd();
       }, onUnReady: () {
         print("婵�鍔卞箍鍛婇鍔犺浇鏈噯澶囧氨缁�");
       }, onVerify: (transId, rewardName, rewardAmount) {
         print("婵�鍔卞箍鍛婂鍔�  $transId   $rewardName   $rewardAmount");
-        adCallback(true, "婵�鍔卞箍鍛婂鍔�");
+        adCallback(RewardAdStatus.verify, "婵�鍔卞箍鍛婂鍔�");
       }, onFinish: () {
         print("婵�鍔卞箍鍛婂畬鎴�");
       }),

--
Gitblit v1.8.0