From 75cf3892864154ae61059056d927cd6154bdecf5 Mon Sep 17 00:00:00 2001 From: Michael Gordeev Date: Sun, 4 Nov 2018 15:15:57 +0300 Subject: [PATCH] Notification system done --- FoxTube.Background/BackgroundProcessor.cs | 27 +--------- FoxTube.Background/Notification.cs | 4 +- FoxTube/Classes/AdSizeTrigger.cs | 20 ------- FoxTube/Controls/Advert.xaml | 50 ++--------------- FoxTube/Controls/Advert.xaml.cs | 65 ++++++++++++++++------- FoxTube/FoxTube.csproj | 1 - FoxTube/Pages/MainPage.xaml.cs | 42 +++++++-------- FoxTube/Pages/VideoPage.xaml | 6 +-- 8 files changed, 77 insertions(+), 138 deletions(-) delete mode 100644 FoxTube/Classes/AdSizeTrigger.cs diff --git a/FoxTube.Background/BackgroundProcessor.cs b/FoxTube.Background/BackgroundProcessor.cs index 12275c1..8a3a369 100644 --- a/FoxTube.Background/BackgroundProcessor.cs +++ b/FoxTube.Background/BackgroundProcessor.cs @@ -1,16 +1,9 @@ -using Google.Apis.Auth.OAuth2; -using Google.Apis.Services; +using Google.Apis.Services; using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3.Data; using Newtonsoft.Json; using System; using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; using System.Xml; using Windows.ApplicationModel.Background; using Windows.Storage; @@ -21,14 +14,7 @@ namespace FoxTube.Background public sealed class BackgroundProcessor : IBackgroundTask { private DateTime lastCheck = DateTime.Now; - private ApplicationDataContainer settings = ApplicationData.Current.LocalSettings; - - private ClientSecrets Secrets => new ClientSecrets() - { - ClientId = "349735264870-2ekqlm0a4mkg3mmrfcv90s3qp3o15dq0.apps.googleusercontent.com", - ClientSecret = "BkVZOAaCU2Zclf0Zlicg6y2_" - }; private YouTubeService Service => new YouTubeService(new BaseClientService.Initializer() { ApiKey = "AIzaSyBgHrCnrlzlVmk0cJKL8RqP9Y8x6XSuk_0", @@ -66,12 +52,7 @@ namespace FoxTube.Background { try { - ToastNotificationManager.CreateToastNotifier().Show(Notification.GetInternalToast(null, "Checking videos...", DateTime.Now.ToString(), null, null)); Dictionary subscriptions = JsonConvert.DeserializeObject>(await FileIO.ReadTextAsync(await ApplicationData.Current.RoamingFolder.GetFileAsync("background.json"))); - Debug.WriteLine("Subscriptions list"); - foreach (var i in subscriptions) - Debug.WriteLine($"{i.Key}: {i.Value}"); - Debug.WriteLine("Subscriptions list end"); foreach (var s in subscriptions) { SearchResource.ListRequest request = Service.Search.List("snippet"); @@ -81,16 +62,12 @@ namespace FoxTube.Background request.MaxResults = 5; SearchListResponse response = await request.ExecuteAsync(); - foreach (var i in response.Items) + foreach (SearchResult i in response.Items) ToastNotificationManager.CreateToastNotifier().Show( Notification.GetVideoToast(i.Id.VideoId, i.Snippet.ChannelId, i.Snippet.Title, i.Snippet.ChannelTitle, i.Snippet.Thumbnails.Medium.Url, s.Value)); - - ToastNotificationManager.CreateToastNotifier().Show(Notification.GetVideoToast(null, s.Key, DateTime.Now.ToString(), s.Key, null, s.Value)); } } catch { } - - ToastNotificationManager.CreateToastNotifier().Show(Notification.GetInternalToast(null, "New videos checked", DateTime.Now.ToString(), null, null)); } void CheckAnnouncements() diff --git a/FoxTube.Background/Notification.cs b/FoxTube.Background/Notification.cs index 14521f2..d49c352 100644 --- a/FoxTube.Background/Notification.cs +++ b/FoxTube.Background/Notification.cs @@ -30,8 +30,8 @@ namespace FoxTube.Background template.LoadXml($@" - - + + {title} {channel} uploaded a new video diff --git a/FoxTube/Classes/AdSizeTrigger.cs b/FoxTube/Classes/AdSizeTrigger.cs deleted file mode 100644 index 380cda6..0000000 --- a/FoxTube/Classes/AdSizeTrigger.cs +++ /dev/null @@ -1,20 +0,0 @@ -using FoxTube.Controls; -using Windows.UI.Xaml; - -namespace FoxTube.Classes -{ - public class AdSizeTrigger : StateTriggerBase - { - private Advert _class; - - public Advert Class - { - get { return _class; } - set - { - _class = value; - SetActive(!_class.OverrideSize); - } - } - } -} diff --git a/FoxTube/Controls/Advert.xaml b/FoxTube/Controls/Advert.xaml index 0db12aa..5c2bd8e 100644 --- a/FoxTube/Controls/Advert.xaml +++ b/FoxTube/Controls/Advert.xaml @@ -5,55 +5,13 @@ xmlns:ad="using:Microsoft.Advertising.WinRT.UI" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - mc:Ignorable="d" - xmlns:classes="using:FoxTube.Classes"> + mc:Ignorable="d"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + Height="50" + Width="300"/> diff --git a/FoxTube/Controls/Advert.xaml.cs b/FoxTube/Controls/Advert.xaml.cs index 05276aa..3c12a1d 100644 --- a/FoxTube/Controls/Advert.xaml.cs +++ b/FoxTube/Controls/Advert.xaml.cs @@ -1,20 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.Foundation; -using Windows.Foundation.Collections; +using System.Diagnostics; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Controls.Primitives; -using Windows.UI.Xaml.Data; -using Windows.UI.Xaml.Input; -using Windows.UI.Xaml.Media; -using Windows.UI.Xaml.Navigation; - -// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 namespace FoxTube.Controls { @@ -23,10 +9,26 @@ namespace FoxTube.Controls public string AdUnitId { get; set; } = "test"; public string AppId => "3f83fe91-d6be-434d-a0ae-7351c5a997f1"; public bool OverrideSize { get; set; } = false; - public Advert Instance => this; - public int Height { get; set; } = 50; - public int Width { get; set; } = 300; + public new double Height + { + get { return ad.Height; } + set + { + ad.Height = value; + OverrideSize = true; + } + } + + public new double Width + { + get { return ad.Width; } + set + { + ad.Width = value; + OverrideSize = true; + } + } public Advert() { @@ -37,5 +39,32 @@ namespace FoxTube.Controls Visibility = Visibility.Collapsed; SecretsVault.NotPurchased += () => Visibility = Visibility.Visible; } + + private void Grid_SizeChanged(object sender, SizeChangedEventArgs e) + { + if (OverrideSize) + return; + + if(grid.ActualWidth >= 728) + { + ad.Width = 728; + ad.Height = 90; + } + else if (grid.ActualWidth >= 640) + { + ad.Width = 640; + ad.Height = 100; + } + else if (grid.ActualWidth >= 320) + { + ad.Width = 320; + ad.Height = 50; + } + else + { + ad.Width = 300; + ad.Height = 50; + } + } } } diff --git a/FoxTube/FoxTube.csproj b/FoxTube/FoxTube.csproj index 99aa405..45f9b69 100644 --- a/FoxTube/FoxTube.csproj +++ b/FoxTube/FoxTube.csproj @@ -96,7 +96,6 @@ App.xaml - diff --git a/FoxTube/Pages/MainPage.xaml.cs b/FoxTube/Pages/MainPage.xaml.cs index fe5a2bb..e0d1319 100644 --- a/FoxTube/Pages/MainPage.xaml.cs +++ b/FoxTube/Pages/MainPage.xaml.cs @@ -124,30 +124,15 @@ namespace FoxTube public void SetTitleBar() { var titleBar = ApplicationView.GetForCurrentView().TitleBar; - - titleBar.ButtonBackgroundColor = Colors.Transparent; + + titleBar.BackgroundColor = Colors.Red; + titleBar.ButtonBackgroundColor = Colors.Red; titleBar.ButtonHoverBackgroundColor = Colors.IndianRed; titleBar.ButtonPressedBackgroundColor = Colors.DarkRed; - titleBar.ButtonInactiveBackgroundColor = Colors.Transparent; + titleBar.ButtonInactiveBackgroundColor = Colors.DeepPink; + titleBar.ForegroundColor = Colors.White; - if((int)settings.Values["themeMode"] == 2) - { - Color uiTheme = new UISettings().GetColorValue(UIColorType.Background); - if (uiTheme == Colors.Black) - titleBar.ButtonForegroundColor = Colors.White; - else - titleBar.ButtonForegroundColor = Colors.Black; - } - else - { - if (RequestedTheme == ElementTheme.Dark) - titleBar.ButtonForegroundColor = Colors.White; - else if (RequestedTheme == ElementTheme.Light) - titleBar.ButtonForegroundColor = Colors.Black; - } - - CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar; - coreTitleBar.ExtendViewIntoTitleBar = true; + CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false; } private void SecretsVault_SubscriptionsChanged(object sender, params object[] args) @@ -393,6 +378,7 @@ namespace FoxTube nav.IsBackEnabled = true; else nav.IsBackEnabled = false; + CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true; } public void MaximizeVideo() @@ -404,25 +390,33 @@ namespace FoxTube videoPlaceholder.Margin = new Thickness(0); nav.IsBackEnabled = true; + CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false; } public void Fullscreen(bool on) { if (on) { + nav.CompactModeThresholdWidth = short.MaxValue; + nav.ExpandedModeThresholdWidth = short.MaxValue; nav.OpenPaneLength = 0; nav.CompactPaneLength = 0; if ((videoPlaceholder.Content as VideoPage).player.MiniView) - nav.Margin = new Thickness(0, -80, 0, 0); + nav.Margin = new Thickness(0, -48, 0, 0); else - nav.Margin = new Thickness(0, -91, 0, 0); + nav.Margin = new Thickness(0, -60, 0, 0); } else { + + nav.CompactModeThresholdWidth = 641; + nav.ExpandedModeThresholdWidth = 1008; nav.Margin = new Thickness(0); nav.OpenPaneLength = 300; nav.CompactPaneLength = 48; } + + CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = on; } public void CloseVideo() @@ -441,6 +435,8 @@ namespace FoxTube nav.IsBackEnabled = true; else nav.IsBackEnabled = false; + + CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false; } private void search_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args) diff --git a/FoxTube/Pages/VideoPage.xaml b/FoxTube/Pages/VideoPage.xaml index 698605a..df992c1 100644 --- a/FoxTube/Pages/VideoPage.xaml +++ b/FoxTube/Pages/VideoPage.xaml @@ -153,12 +153,12 @@ - + + - @@ -194,7 +194,7 @@ - +