diff options
Diffstat (limited to 'Client/Assembly-CSharp/GoogleMobileAds/Api/AdLoader.cs')
-rw-r--r-- | Client/Assembly-CSharp/GoogleMobileAds/Api/AdLoader.cs | 93 |
1 files changed, 93 insertions, 0 deletions
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<string, Action<CustomNativeTemplateAd, string>> CustomNativeTemplateClickHandlers { get; private set; } + + public string AdUnitId { get; private set; } + + public HashSet<NativeAdType> AdTypes { get; private set; } + + public HashSet<string> TemplateIds { get; private set; } + + public event EventHandler<AdFailedToLoadEventArgs> OnAdFailedToLoad; + + public event EventHandler<CustomNativeEventArgs> OnCustomNativeTemplateAdLoaded; + + private IAdLoaderClient adLoaderClient; + + public class Builder + { + internal string AdUnitId { get; private set; } + + internal HashSet<NativeAdType> AdTypes { get; private set; } + + internal HashSet<string> TemplateIds { get; private set; } + + internal Dictionary<string, Action<CustomNativeTemplateAd, string>> CustomNativeTemplateClickHandlers { get; private set; } + + public Builder(string adUnitId) + { + this.AdUnitId = adUnitId; + this.AdTypes = new HashSet<NativeAdType>(); + this.TemplateIds = new HashSet<string>(); + this.CustomNativeTemplateClickHandlers = new Dictionary<string, Action<CustomNativeTemplateAd, string>>(); + } + + public AdLoader.Builder ForCustomNativeAd(string templateId) + { + this.TemplateIds.Add(templateId); + this.AdTypes.Add(NativeAdType.CustomTemplate); + return this; + } + + public AdLoader.Builder ForCustomNativeAd(string templateId, Action<CustomNativeTemplateAd, string> 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<string, Action<CustomNativeTemplateAd, string>>(builder.CustomNativeTemplateClickHandlers); + this.TemplateIds = new HashSet<string>(builder.TemplateIds); + this.AdTypes = new HashSet<NativeAdType>(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); + } + } +} |