From e9ea621b93fbb58d9edfca8375918791637bbd52 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 30 Dec 2020 20:59:04 +0800 Subject: +init --- .../GoogleMobileAds/Api/AdLoader.cs | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Client/Assembly-CSharp/GoogleMobileAds/Api/AdLoader.cs (limited to 'Client/Assembly-CSharp/GoogleMobileAds/Api/AdLoader.cs') diff --git a/Client/Assembly-CSharp/GoogleMobileAds/Api/AdLoader.cs b/Client/Assembly-CSharp/GoogleMobileAds/Api/AdLoader.cs new file mode 100644 index 0000000..3116a90 --- /dev/null +++ b/Client/Assembly-CSharp/GoogleMobileAds/Api/AdLoader.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using GoogleMobileAds.Common; + +namespace GoogleMobileAds.Api +{ + public class AdLoader + { + public Dictionary> CustomNativeTemplateClickHandlers { get; private set; } + + public string AdUnitId { get; private set; } + + public HashSet AdTypes { get; private set; } + + public HashSet TemplateIds { get; private set; } + + public event EventHandler OnAdFailedToLoad; + + public event EventHandler OnCustomNativeTemplateAdLoaded; + + private IAdLoaderClient adLoaderClient; + + public class Builder + { + internal string AdUnitId { get; private set; } + + internal HashSet AdTypes { get; private set; } + + internal HashSet TemplateIds { get; private set; } + + internal Dictionary> CustomNativeTemplateClickHandlers { get; private set; } + + public Builder(string adUnitId) + { + this.AdUnitId = adUnitId; + this.AdTypes = new HashSet(); + this.TemplateIds = new HashSet(); + this.CustomNativeTemplateClickHandlers = new Dictionary>(); + } + + public AdLoader.Builder ForCustomNativeAd(string templateId) + { + this.TemplateIds.Add(templateId); + this.AdTypes.Add(NativeAdType.CustomTemplate); + return this; + } + + public AdLoader.Builder ForCustomNativeAd(string templateId, Action callback) + { + this.TemplateIds.Add(templateId); + this.CustomNativeTemplateClickHandlers[templateId] = callback; + this.AdTypes.Add(NativeAdType.CustomTemplate); + return this; + } + + public AdLoader Build() + { + return new AdLoader(this); + } + } + + private AdLoader(AdLoader.Builder builder) + { + this.AdUnitId = string.Copy(builder.AdUnitId); + this.CustomNativeTemplateClickHandlers = new Dictionary>(builder.CustomNativeTemplateClickHandlers); + this.TemplateIds = new HashSet(builder.TemplateIds); + this.AdTypes = new HashSet(builder.AdTypes); + MethodInfo method = Type.GetType("GoogleMobileAds.GoogleMobileAdsClientFactory,Assembly-CSharp").GetMethod("BuildAdLoaderClient", BindingFlags.Static | BindingFlags.Public); + this.adLoaderClient = (IAdLoaderClient)method.Invoke(null, new object[] + { + this + }); + Utils.CheckInitialization(); + this.adLoaderClient.OnCustomNativeTemplateAdLoaded += delegate(object sender, CustomNativeEventArgs args) + { + this.OnCustomNativeTemplateAdLoaded(this, args); + }; + this.adLoaderClient.OnAdFailedToLoad += delegate(object sender, AdFailedToLoadEventArgs args) + { + if (this.OnAdFailedToLoad != null) + { + this.OnAdFailedToLoad(this, args); + } + }; + } + + public void LoadAd(AdRequest request) + { + this.adLoaderClient.LoadAd(request); + } + } +} -- cgit v1.1-26-g67d0