1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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);
}
}
}
|