Added advert cards
This commit is contained in:
@@ -189,6 +189,11 @@
|
|||||||
<Name>Visual C++ 2015 Runtime for Universal Windows Platform Apps</Name>
|
<Name>Visual C++ 2015 Runtime for Universal Windows Platform Apps</Name>
|
||||||
</SDKReference>
|
</SDKReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.Advertising">
|
||||||
|
<HintPath>..\..\..\..\NuGet\microsoft.advertising.xaml\10.1811.22001\SDK\Windows Kits\10\ExtensionSDKs\Microsoft.Advertising.Xaml\10.0\References\CommonConfiguration\neutral\Microsoft.Advertising.winmd</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using Microsoft.Advertising.WinRT.UI;
|
||||||
using System.Net.Http;
|
using System;
|
||||||
using Windows.ApplicationModel.Core;
|
using Windows.ApplicationModel.Core;
|
||||||
using Windows.UI.Notifications;
|
|
||||||
|
|
||||||
namespace FoxTube.Core.Helpers
|
namespace FoxTube.Core.Helpers
|
||||||
{
|
{
|
||||||
@@ -32,5 +31,7 @@ namespace FoxTube.Core.Helpers
|
|||||||
Settings.ResetSettings();
|
Settings.ResetSettings();
|
||||||
RestartApp();
|
RestartApp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static NativeAdsManagerV2 AdManager => new NativeAdsManagerV2("9ncqqxjtdlfh", "1100044398");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,12 @@
|
|||||||
d:DesignWidth="400"
|
d:DesignWidth="400"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
Margin="3"
|
Margin="3"
|
||||||
SizeChanged="UserControl_SizeChanged">
|
SizeChanged="UserControl_SizeChanged"
|
||||||
|
Visibility="Collapsed"
|
||||||
|
Opacity="0">
|
||||||
|
<UserControl.OpacityTransition>
|
||||||
|
<ScalarTransition/>
|
||||||
|
</UserControl.OpacityTransition>
|
||||||
|
|
||||||
<controls:DropShadowPanel BlurRadius="10" ShadowOpacity=".5"
|
<controls:DropShadowPanel BlurRadius="10" ShadowOpacity=".5"
|
||||||
OffsetX="2" OffsetY="2"
|
OffsetX="2" OffsetY="2"
|
||||||
@@ -19,14 +24,14 @@
|
|||||||
HorizontalContentAlignment="Stretch"
|
HorizontalContentAlignment="Stretch"
|
||||||
VerticalContentAlignment="Stretch">
|
VerticalContentAlignment="Stretch">
|
||||||
<Button Background="{ThemeResource SystemControlBackgroundChromeMediumBrush}" Style="{StaticResource ButtonRevealStyle}" Windows10version1809:CornerRadius="5" Padding="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
<Button Background="{ThemeResource SystemControlBackgroundChromeMediumBrush}" Style="{StaticResource ButtonRevealStyle}" Windows10version1809:CornerRadius="5" Padding="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RowSpacing="5">
|
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RowSpacing="5" x:Name="grid">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="20"/>
|
<RowDefinition Height="20"/>
|
||||||
<RowDefinition/>
|
<RowDefinition/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<controls:ImageEx PlaceholderStretch="UniformToFill" CornerRadius="5,5,0,0" PlaceholderSource="/Assets/DefaultVideoThumbnail.png"/>
|
<controls:ImageEx PlaceholderStretch="UniformToFill" CornerRadius="5,5,0,0" PlaceholderSource="/Assets/DefaultVideoThumbnail.png" Source="{Binding advert.MainImages[0].Url}"/>
|
||||||
|
|
||||||
<controls:DropShadowPanel VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5" OffsetX="2" OffsetY="2">
|
<controls:DropShadowPanel VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5" OffsetX="2" OffsetY="2">
|
||||||
<StackPanel Padding="5,2,5,3" Background="Orange" CornerRadius="5">
|
<StackPanel Padding="5,2,5,3" Background="Orange" CornerRadius="5">
|
||||||
@@ -34,9 +39,9 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</controls:DropShadowPanel>
|
</controls:DropShadowPanel>
|
||||||
|
|
||||||
<controls:DropShadowPanel VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="5,10" OffsetX="2" OffsetY="2">
|
<controls:DropShadowPanel VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="5,10" OffsetX="2" OffsetY="2" x:Name="cta">
|
||||||
<StackPanel Padding="5,2,5,3" Background="Yellow" CornerRadius="5">
|
<StackPanel Padding="5,2,5,3" Background="Yellow" CornerRadius="5">
|
||||||
<TextBlock Text="Call to action" Foreground="Black" FontSize="12"/>
|
<TextBlock Text="{x:Bind advert.CallToActionText}" Foreground="Black" FontSize="12"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</controls:DropShadowPanel>
|
</controls:DropShadowPanel>
|
||||||
|
|
||||||
@@ -47,12 +52,12 @@
|
|||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<controls:ImageEx CornerRadius="999" BorderThickness="3" BorderBrush="{ThemeResource SystemControlBackgroundChromeMediumBrush}" Background="Red"
|
<controls:ImageEx CornerRadius="999" BorderThickness="3" BorderBrush="{ThemeResource SystemControlBackgroundChromeMediumBrush}" Background="Red"
|
||||||
Width="50" Height="50" VerticalAlignment="Bottom" Margin="0,-30,0,0" PlaceholderSource="/Assets/Icons/Contact.png" PlaceholderStretch="UniformToFill"/>
|
Width="50" Height="50" VerticalAlignment="Bottom" Margin="0,-30,0,0" PlaceholderSource="/Assets/Icons/Contact.png" PlaceholderStretch="UniformToFill" Source="{x:Bind advert.AdIcon}"/>
|
||||||
<TextBlock Text="██████████" Grid.Column="1"/>
|
<TextBlock Text="{x:Bind advert.SponsoredBy}" Grid.Column="1"/>
|
||||||
<TextBlock Text="██████████" Grid.Column="2"/>
|
<TextBlock x:Name="description" Text="" Grid.Column="2"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<TextBlock Margin="10,0" Grid.Row="2" MaxLines="2" TextTrimming="CharacterEllipsis" TextWrapping="WrapWholeWords" Text="██████████"/>
|
<TextBlock Margin="10,0" Grid.Row="2" MaxLines="2" TextTrimming="CharacterEllipsis" TextWrapping="WrapWholeWords" Text="{x:Bind advert.Title}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Button>
|
</Button>
|
||||||
</controls:DropShadowPanel>
|
</controls:DropShadowPanel>
|
||||||
|
|||||||
@@ -1,14 +1,51 @@
|
|||||||
using Windows.UI.Xaml;
|
using FoxTube.Core.Helpers;
|
||||||
|
using Microsoft.Advertising.WinRT.UI;
|
||||||
|
using Microsoft.Toolkit.Uwp.UI.Controls;
|
||||||
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
|
|
||||||
namespace FoxTube.Controls.Cards
|
namespace FoxTube.Controls.Cards
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Advert which is looks similar to video cards
|
||||||
|
/// </summary>
|
||||||
public sealed partial class AdvertCard : UserControl
|
public sealed partial class AdvertCard : UserControl
|
||||||
{
|
{
|
||||||
public AdvertCard() =>
|
NativeAdsManagerV2 manager = Utils.AdManager;
|
||||||
|
NativeAdV2 advert;
|
||||||
|
public AdvertCard()
|
||||||
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
manager.AdReady += AdReady;
|
||||||
|
manager.ErrorOccurred += ErrorOccurred;
|
||||||
|
manager.RequestAd();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ErrorOccurred(object sender, NativeAdErrorEventArgs e)
|
||||||
|
{
|
||||||
|
(Parent as StaggeredPanel)?.Children.Remove(this);
|
||||||
|
Metrics.AddEvent("Error has occured while loading ad",
|
||||||
|
("Code", e.ErrorCode.ToString()),
|
||||||
|
("Message", e.ErrorMessage),
|
||||||
|
("Request ID", e.RequestId));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AdReady(object sender, NativeAdReadyEventArgs e)
|
||||||
|
{
|
||||||
|
advert = e.NativeAd;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(advert.CallToActionText))
|
||||||
|
cta.Visibility = Visibility.Collapsed;
|
||||||
|
|
||||||
|
description.Text += $"{advert.Price} {advert.Rating}";
|
||||||
|
|
||||||
|
e.NativeAd.RegisterAdContainer(grid);
|
||||||
|
|
||||||
|
Metrics.AddEvent("Advert loaded",
|
||||||
|
("Region", Settings.Region),
|
||||||
|
("Version", Metrics.CurrentVersion));
|
||||||
|
}
|
||||||
void UserControl_SizeChanged(object sender, SizeChangedEventArgs e) =>
|
void UserControl_SizeChanged(object sender, SizeChangedEventArgs e) =>
|
||||||
Height = .75 * ActualWidth;
|
Height = .75 * ActualWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using FoxTube.Controls.Cards;
|
using FoxTube.Controls.Cards;
|
||||||
|
using FoxTube.Core.Helpers;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
|
|
||||||
@@ -16,8 +17,8 @@ namespace FoxTube.Controls
|
|||||||
{
|
{
|
||||||
empty.Opacity = 0;
|
empty.Opacity = 0;
|
||||||
|
|
||||||
//if (!StoreInterop.AdsDisabled && ItemsCount % 5 == 0 && ItemsCount > 0)
|
if (!StoreInterop.AdsDisabled && ItemsCount % 5 == 0 && ItemsCount > 0)
|
||||||
// Items.Add(new AdvertCard());
|
Items.Add(new AdvertCard());
|
||||||
Items.Add(item);
|
Items.Add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user