diff --git a/FoxTube.Background/FoxTube.Background.csproj b/FoxTube.Background/FoxTube.Background.csproj index d7c0956..a9896f1 100644 --- a/FoxTube.Background/FoxTube.Background.csproj +++ b/FoxTube.Background/FoxTube.Background.csproj @@ -131,11 +131,6 @@ 6.1.5 - - - ..\..\..\..\..\..\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\microsoft.netcore.universalwindowsplatform\6.1.5\ref\uap10.0.15138\System.Net.WebClient.dll - - 14.0 diff --git a/FoxTube/Classes/Methods.cs b/FoxTube/Classes/Methods.cs index 7ea2a79..7013a5a 100644 --- a/FoxTube/Classes/Methods.cs +++ b/FoxTube/Classes/Methods.cs @@ -36,18 +36,6 @@ namespace FoxTube get { return (Window.Current.Content as Frame).Content as MainPage; } } - public static CardAdvert CardAdvert { get; private set; } - - public static void InitializeAds() - { - NativeAdsManagerV2 manager = new NativeAdsManagerV2(SecretsVault.AppId, SecretsVault.AdUnitId); - manager.AdReady += (s, e) => - { - card = new CardAdvert(e.NativeAd); - e.NativeAd.RegisterAdContainer(card); - }; - } - public static void CloseApp() { CoreApplication.Exit(); diff --git a/FoxTube/Classes/SecretsVault.cs b/FoxTube/Classes/SecretsVault.cs index 01f7a0f..55fe10f 100644 --- a/FoxTube/Classes/SecretsVault.cs +++ b/FoxTube/Classes/SecretsVault.cs @@ -2,13 +2,13 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using FoxTube.Controls.Adverts; using Google.Apis.Auth.OAuth2; using Google.Apis.Services; using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3.Data; using Newtonsoft.Json; using Windows.Storage; +using Windows.Services.Store; namespace FoxTube { @@ -18,7 +18,7 @@ namespace FoxTube //Events public static event ObjectEventHandler AuthorizationStateChanged; public static event ObjectEventHandler SubscriptionsChanged; - public static event Event NotPurchased; //Rising when app finds out that it's not a PRO version + public static event ObjectEventHandler Purchased; //Rising when app finds out that it's not a PRO version //Private properties private static ClientSecrets Secrets => new ClientSecrets() @@ -37,8 +37,8 @@ namespace FoxTube ApplicationName = "FoxTube" }; public static YouTubeService Service => IsAuthorized ? new YouTubeService(Initializer) : NoAuthService; - public static string AppId => "d25517cb-12d4-4699-8bdc-52040c712cab"; - public static string AdUnitId => "test"; + public static string AppId => true ? "d25517cb-12d4-4699-8bdc-52040c712cab" : "9ncqqxjtdlfh"; + public static string AdUnitId => true ? "test" : "1100037769"; public static bool AdsDisabled { get; private set; } = true; //User info @@ -196,15 +196,38 @@ namespace FoxTube /// /// Connects to MS Store and checks if user has bought ad-free /// - public static void CheckAddons() + public static async void CheckAddons() { - //TODO: Check addons list - bool purchased = true; - - if(!purchased) + try { - AdsDisabled = false; - NotPurchased?.Invoke(); + StoreContext store = StoreContext.GetDefault(); + StoreProductQueryResult requset = await store.GetAssociatedStoreProductsAsync(new[] { "Consumable", "Durable", "UnmanagedConsumable" }); + + if (!requset.Products["foxtube-adsremove"].IsInUserCollection) + { + AdsDisabled = false; + Purchased?.Invoke(args:false); + } + } + catch { } + } + + public static async void GetAdblock() + { + StoreContext store = StoreContext.GetDefault(); + StorePurchaseResult request = await store.RequestPurchaseAsync("foxtube-adsremove"); + + switch (request.Status) + { + case StorePurchaseStatus.AlreadyPurchased: + Purchased?.Invoke(args: true); + AdsDisabled = true; + break; + + case StorePurchaseStatus.Succeeded: + Purchased?.Invoke(args: true); + AdsDisabled = true; + break; } } #endregion diff --git a/FoxTube/Controls/Advert.xaml.cs b/FoxTube/Controls/Advert.xaml.cs index dfdf5e7..36d3b90 100644 --- a/FoxTube/Controls/Advert.xaml.cs +++ b/FoxTube/Controls/Advert.xaml.cs @@ -36,7 +36,7 @@ namespace FoxTube.Controls Visibility = Visibility.Visible; else Visibility = Visibility.Collapsed; - SecretsVault.NotPurchased += () => Visibility = Visibility.Visible; + SecretsVault.Purchased += (s, e) => Visibility = (bool)e[0] ? Visibility.Collapsed : Visibility.Visible; } private void Grid_SizeChanged(object sender, SizeChangedEventArgs e) diff --git a/FoxTube/Controls/Adverts/CardAdvert.xaml.cs b/FoxTube/Controls/Adverts/CardAdvert.xaml.cs index d03c1d0..64fd8e8 100644 --- a/FoxTube/Controls/Adverts/CardAdvert.xaml.cs +++ b/FoxTube/Controls/Adverts/CardAdvert.xaml.cs @@ -3,7 +3,6 @@ using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Microsoft.Advertising.WinRT.UI; using Windows.UI.Xaml.Media.Imaging; -using System.Diagnostics; namespace FoxTube.Controls.Adverts { @@ -12,12 +11,20 @@ namespace FoxTube.Controls.Adverts /// public sealed partial class CardAdvert : UserControl { - NativeAdV2 advert; - public CardAdvert(NativeAdV2 ad) + NativeAdsManagerV2 manager = new NativeAdsManagerV2(SecretsVault.AppId, SecretsVault.AdUnitId); + public NativeAdV2 advert; + public CardAdvert() { InitializeComponent(); - advert = ad; + manager.AdReady += AdReady; + manager.RequestAd(); + } + + private void AdReady(object sender, NativeAdReadyEventArgs e) + { + advert = e.NativeAd; Initialize(); + e.NativeAd.RegisterAdContainer(this); } public void Initialize() @@ -43,6 +50,8 @@ namespace FoxTube.Controls.Adverts desc.Text = advert.CallToActionText; else desc.Text = advert.Price; + + Visibility = Visibility.Visible; } private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e) diff --git a/FoxTube/Pages/MainPage.xaml b/FoxTube/Pages/MainPage.xaml index f75b267..e158186 100644 --- a/FoxTube/Pages/MainPage.xaml +++ b/FoxTube/Pages/MainPage.xaml @@ -36,7 +36,7 @@ - + diff --git a/FoxTube/Pages/MainPage.xaml.cs b/FoxTube/Pages/MainPage.xaml.cs index 80e9003..42967ba 100644 --- a/FoxTube/Pages/MainPage.xaml.cs +++ b/FoxTube/Pages/MainPage.xaml.cs @@ -41,10 +41,14 @@ namespace FoxTube InitializeComponent(); CheckVersion(); - + SecretsVault.AuthorizationStateChanged += AuthorizationStateChanged; SecretsVault.SubscriptionsChanged += SecretsVault_SubscriptionsChanged; - SecretsVault.NotPurchased += () => removeAds.Visibility = Visibility.Visible; + SecretsVault.Purchased += (sender, e) => + { + removeAds.Visibility = (e[0] as bool?).Value ? Visibility.Collapsed : Visibility.Visible; + content.Navigate(typeof(Home)); + }; SecretsVault.CheckAuthorization(); SecretsVault.CheckAddons(); @@ -351,7 +355,7 @@ namespace FoxTube if (videoPlaceholder.Content != null) (videoPlaceholder.Content as VideoPage).player.close_Click(this, null); - + videoPlaceholder.Content = null; Fullscreen(false); @@ -740,5 +744,10 @@ namespace FoxTube { ((NavigationViewItem)sender).ContextFlyout.ShowAt((NavigationViewItem)sender); } + + private void RemoveAds_Tapped(object sender, TappedRoutedEventArgs e) + { + SecretsVault.GetAdblock(); + } } } diff --git a/FoxTube/Pages/VideoGrid.xaml.cs b/FoxTube/Pages/VideoGrid.xaml.cs index f56f555..a450fdc 100644 --- a/FoxTube/Pages/VideoGrid.xaml.cs +++ b/FoxTube/Pages/VideoGrid.xaml.cs @@ -1,6 +1,7 @@ using FoxTube.Controls.Adverts; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Navigation; namespace FoxTube.Pages { @@ -17,8 +18,8 @@ namespace FoxTube.Pages public void Add(UIElement card) { list.Items.Add(card); - if (list.Items.Count % 5 == 0) - list.Items.Add(new CardAdvert()); + /*if (list.Items.Count % 10 == 0) + list.Items.Add(new CardAdvert());*/ empty.Visibility = Visibility.Collapsed; } diff --git a/FoxTube/Pages/VideoPage.xaml.cs b/FoxTube/Pages/VideoPage.xaml.cs index bd0feb2..74f431d 100644 --- a/FoxTube/Pages/VideoPage.xaml.cs +++ b/FoxTube/Pages/VideoPage.xaml.cs @@ -1,4 +1,5 @@ using FoxTube.Controls; +using FoxTube.Controls.Adverts; using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3.Data; using System; diff --git a/FoxTube/Strings/en-US/Main.resw b/FoxTube/Strings/en-US/Main.resw index 6c22b41..1721f7b 100644 --- a/FoxTube/Strings/en-US/Main.resw +++ b/FoxTube/Strings/en-US/Main.resw @@ -151,7 +151,7 @@ Liked videos - "You are on metered connection now. Additional charges may apply. Do you want to continue?" + You are on metered connection now. Additional charges may apply. Do you want to continue? My channel @@ -180,6 +180,9 @@ Sign in with existing account + + Add account + Create new Google account diff --git a/FoxTube/Strings/ru-RU/Main.resw b/FoxTube/Strings/ru-RU/Main.resw index dd196ec..b8263f6 100644 --- a/FoxTube/Strings/ru-RU/Main.resw +++ b/FoxTube/Strings/ru-RU/Main.resw @@ -151,10 +151,7 @@ Понравившиеся - "You are on metered connection now. Additional charges may apply. Do you want to continue?" - - - Мой аккаунт + Передача данных в этой сети ограничена. Может взиматься дополнительная плата. Вы хотите продолжить? Мой канал @@ -168,9 +165,6 @@ Нет - - Уведомления - Плейлист @@ -186,8 +180,8 @@ Войти с помощью существующего аккаунта Google - - Войти + + Войти в аккаунт Создать новый аккаунт Google