private 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); Dictionary <string, bool> templateIdsDictionary = new Dictionary <string, bool>(); foreach (string templateId in TemplateIds) { templateIdsDictionary[templateId] = false; } foreach (var keyValuePair in this.CustomNativeTemplateClickHandlers) { templateIdsDictionary[keyValuePair.Key] = true; } AdLoaderClientArgs clientArgs = new AdLoaderClientArgs() { AdUnitId = this.AdUnitId, AdTypes = this.AdTypes, TemplateIds = templateIdsDictionary, }; this.adLoaderClient = GoogleMobileAdsClientFactory.BuildAdLoaderClient(clientArgs); Utils.CheckInitialization(); this.adLoaderClient.OnCustomNativeTemplateAdLoaded += delegate(object sender, CustomNativeClientEventArgs args) { CustomNativeTemplateAd nativeAd = new CustomNativeTemplateAd(args.nativeAdClient); CustomNativeEventArgs adEventArgs = new CustomNativeEventArgs() { nativeAd = nativeAd }; this.OnCustomNativeTemplateAdLoaded(this, adEventArgs); }; this.adLoaderClient.OnCustomNativeTemplateAdClicked += delegate(object sender, CustomNativeClientEventArgs args) { CustomNativeTemplateAd nativeAd = new CustomNativeTemplateAd(args.nativeAdClient); if (this.CustomNativeTemplateClickHandlers.ContainsKey(nativeAd.GetCustomTemplateId())) { this.CustomNativeTemplateClickHandlers[nativeAd.GetCustomTemplateId()](nativeAd, args.assetName); } }; this.adLoaderClient.OnAdFailedToLoad += delegate( object sender, AdFailedToLoadEventArgs args) { if (this.OnAdFailedToLoad != null) { this.OnAdFailedToLoad(this, args); } }; }
public void onCustomClick(AndroidJavaObject ad, string assetName) { CustomNativeTemplateAd nativeAd = new CustomNativeTemplateAd( new CustomNativeTemplateClient(ad)); this.CustomNativeTemplateCallbacks[nativeAd.GetCustomTemplateId()](nativeAd, assetName); }
private static void NativeCustomTemplateDidReceiveClickCallback( IntPtr nativeCustomAd, string assetName) { CustomNativeTemplateClient client = IntPtrToAdLoaderClient(nativeCustomAd); CustomNativeTemplateAd nativeAd = new CustomNativeTemplateAd(client); client.clickHandler(nativeAd, assetName); }