7cbbc59e16
Fixed headers Added ads to VideoGrid Related Work Items: #162, #188
74 lines
2.3 KiB
C#
74 lines
2.3 KiB
C#
using System.Linq;
|
|
using Windows.UI.Xaml;
|
|
using Windows.UI.Xaml.Controls;
|
|
using Microsoft.Advertising.WinRT.UI;
|
|
using Windows.UI.Xaml.Media.Imaging;
|
|
|
|
namespace FoxTube.Controls.Adverts
|
|
{
|
|
/// <summary>
|
|
/// Advert which is looks similar to video cards
|
|
/// </summary>
|
|
public sealed partial class CardAdvert : UserControl
|
|
{
|
|
NativeAdsManagerV2 manager = new NativeAdsManagerV2(SecretsVault.AppId, SecretsVault.AdUnitId);
|
|
public NativeAdV2 advert;
|
|
public CardAdvert(bool isOnVideoPage = false)
|
|
{
|
|
InitializeComponent();
|
|
if(!isOnVideoPage)
|
|
MainPage.VideoPageSizeChanged += Methods_VideoPageSizeChanged;
|
|
manager.AdReady += AdReady;
|
|
manager.ErrorOccurred += ErrorOccurred;
|
|
manager.RequestAd();
|
|
}
|
|
|
|
private void Methods_VideoPageSizeChanged(object sender = null, params object[] args)
|
|
{
|
|
Visibility = (bool)args[0] ? Visibility.Collapsed : Visibility.Visible;
|
|
}
|
|
|
|
private void ErrorOccurred(object sender, NativeAdErrorEventArgs e)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine("Error has occured while loading ad");
|
|
}
|
|
|
|
private void AdReady(object sender, NativeAdReadyEventArgs e)
|
|
{
|
|
advert = e.NativeAd;
|
|
Initialize();
|
|
e.NativeAd.RegisterAdContainer(this);
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
title.Text = advert.Title;
|
|
image.Source = new BitmapImage(advert.MainImages.First().Url.ToUri());
|
|
|
|
icon.ProfilePicture = advert.AdIcon == null ? null : advert.AdIcon.Source;
|
|
|
|
sponsor.Text = advert.SponsoredBy.GuardFromNull();
|
|
|
|
if (advert.CallToActionText.IsNullOrWhiteSpace())
|
|
(info.Parent as FrameworkElement).Visibility = Visibility.Collapsed;
|
|
else
|
|
info.Text = advert.CallToActionText;
|
|
|
|
desc.Text = string.Empty;
|
|
|
|
if (!advert.Price.IsNullOrWhiteSpace())
|
|
desc.Text += advert.Price;
|
|
|
|
if (!advert.Rating.IsNullOrWhiteSpace())
|
|
desc.Text += " " + advert.Rating;
|
|
|
|
show.Begin();
|
|
}
|
|
|
|
private void Image_ImageOpened(object sender, RoutedEventArgs e)
|
|
{
|
|
showThumb.Begin();
|
|
}
|
|
}
|
|
}
|