diff --git a/FoxTube.Background/BackgroundProcessor.cs b/FoxTube.Background/BackgroundProcessor.cs index 45e1136..fa39192 100644 --- a/FoxTube.Background/BackgroundProcessor.cs +++ b/FoxTube.Background/BackgroundProcessor.cs @@ -32,7 +32,6 @@ namespace FoxTube.Background ClientId = "349735264870-2ekqlm0a4mkg3mmrfcv90s3qp3o15dq0.apps.googleusercontent.com", ClientSecret = "BkVZOAaCU2Zclf0Zlicg6y2_" }; - private YouTubeService Service => new YouTubeService(new BaseClientService.Initializer() { ApiKey = "AIzaSyBgHrCnrlzlVmk0cJKL8RqP9Y8x6XSuk_0", @@ -41,6 +40,7 @@ namespace FoxTube.Background XmlDocument doc = new XmlDocument(); BackgroundTaskDeferral def; + public void Run(IBackgroundTaskInstance taskInstance) { def = taskInstance.GetDeferral(); @@ -48,16 +48,17 @@ namespace FoxTube.Background settings.Values.Add("lastCheck", XmlConvert.ToString(DateTime.Now, "YYYY-MM-DDThh:mm:ss")); else lastCheck = XmlConvert.ToDateTime(settings.Values["lastCheck"] as string, XmlDateTimeSerializationMode.Unspecified); - if (settings.Values["notificationsHistory"] != null) - doc.LoadXml(settings.Values["notificationsHistory"] as string); - else + try { - doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null)); - doc.AppendChild(doc.CreateElement("history")); - settings.Values.Add("notificationsHistory", doc.InnerXml); + doc.LoadXml(settings.Values["notificationsHistory"] as string); + } + catch + { + return; } CheckAnnouncements(); + CheckAccount(); SendNSave(); @@ -78,36 +79,37 @@ namespace FoxTube.Background subRequest.Mine = true; subRequest.MaxResults = 50; SubscriptionListResponse subResponse = await subRequest.ExecuteAsync(); - List> subs = new List>(); + Dictionary subs = new Dictionary(); foreach (Subscription s in subResponse.Items) - subs.Add(new KeyValuePair(s.Snippet.ResourceId.ChannelId, s.Snippet.Thumbnails.Standard.Url)); + subs.Add(s.Snippet.ResourceId.ChannelId, s.Snippet.Thumbnails.Standard.Url); string nextToken = subResponse.NextPageToken; while (nextToken != null) { subRequest.PageToken = nextToken; subResponse = await subRequest.ExecuteAsync(); + nextToken = subResponse.NextPageToken; + foreach (Subscription s in subResponse.Items) - subs.Add(new KeyValuePair(s.Snippet.ResourceId.ChannelId, s.Snippet.Thumbnails.Standard.Url)); + subs.Add(s.Snippet.ResourceId.ChannelId, s.Snippet.Thumbnails.Standard.Url); } foreach(var s in subs) { - var request = Service.Search.List("snippet"); + SearchResource.ListRequest request = Service.Search.List("snippet"); request.PublishedAfter = lastCheck; request.ChannelId = s.Key; request.Type = "video"; - var response = await request.ExecuteAsync(); + SearchListResponse response = await request.ExecuteAsync(); - if(response.Items.Count > 0) - foreach (var a in response.Items) - Notifications.Add(new Notification("video", a.Id.VideoId, - a.Snippet.ChannelTitle, - a.Snippet.Title, - a.Snippet.PublishedAt.Value, - a.Snippet.Thumbnails.Standard.Url, - s.Value)); + foreach (var i in response.Items) + Notifications.Add(new Notification("video", i.Id.VideoId, + i.Snippet.ChannelTitle, + i.Snippet.Title, + i.Snippet.PublishedAt.Value, + i.Snippet.Thumbnails.Standard.Url, + s.Value)); } } @@ -117,10 +119,10 @@ namespace FoxTube.Background doc.Load(XmlReader.Create("http://foxgame.hol.es/foxtube-messages.xml")); if ((XmlConvert.ToDateTimeOffset((doc["posts"].FirstChild as XmlElement).GetAttribute("time"), "YYYY-MM-DDThh:mm:ss") - lastCheck.ToUniversalTime()).TotalSeconds > 0) Notifications.Add(new Notification("internal", (doc["posts"].FirstChild as XmlElement).GetAttribute("id"), + doc["posts"].FirstChild["header"].InnerText, doc["posts"].FirstChild["notificationHeader"].InnerText, - doc["posts"].FirstChild["content"].InnerText, XmlConvert.ToDateTimeOffset((doc["posts"].FirstChild as XmlElement).GetAttribute("time"), "YYYY-MM-DDThh:mm:ss"), - (doc["posts"].FirstChild as XmlElement).GetAttribute("image"), null)); + (doc["posts"].FirstChild as XmlElement).GetAttribute("image"), (doc["posts"].FirstChild as XmlElement).GetAttribute("avatar"))); } void SendNotification(Notification notification) diff --git a/FoxTube.Background/Notification.cs b/FoxTube.Background/Notification.cs index aca3e3f..a872194 100644 --- a/FoxTube.Background/Notification.cs +++ b/FoxTube.Background/Notification.cs @@ -37,10 +37,25 @@ namespace FoxTube.Background TimeStamp = date; Id = id; Type = TypeConversion(type); - Avatar = avatarUrl == null? "ms-appx:///Assets/Icons/Profile.png" : avatarUrl; + Avatar = avatarUrl ?? "ms-appx:///Assets/Icons/Profile.png"; Thumbnail = thumbnailUrl; } + public Notification(string xmlSource) + { + System.Xml.XmlDocument d = new System.Xml.XmlDocument(); + d.InnerXml = xmlSource; + System.Xml.XmlElement xml = d["item"]; + + Channel = xml["channelName"].InnerText; + Content = xml["content"].InnerText; + TimeStamp = DateTimeOffset.Parse(xml.GetAttribute("time")); + Id = xml.GetAttribute("id"); + Type = TypeConversion(xml.GetAttribute("type")); + Avatar = xml["images"].GetAttribute("avatar"); + Thumbnail = xml["images"].GetAttribute("thumbnail"); + } + public string GetXml() { return $@" @@ -57,33 +72,23 @@ namespace FoxTube.Background //Channel switch (Type) { - case NotificationType.Comment: - stackPanel.Children.Add(new TextBlock() - { - FontSize = 14, - FontStyle = Windows.UI.Text.FontStyle.Italic, - Foreground = new SolidColorBrush(Colors.Gray), - Text = string.Format("{0} replied to your comment", Channel) - }); - break; - case NotificationType.Internal: stackPanel.Children.Add(new TextBlock() { FontSize = 14, FontStyle = Windows.UI.Text.FontStyle.Italic, Foreground = new SolidColorBrush(Colors.Gray), - Text = Channel + Text = "Developer's message" }); break; - case NotificationType.Post: + case NotificationType.Changelog: stackPanel.Children.Add(new TextBlock() { FontSize = 14, FontStyle = Windows.UI.Text.FontStyle.Italic, Foreground = new SolidColorBrush(Colors.Gray), - Text = string.Format("{0} published new post", Channel) + Text = "Changelog" }); break; @@ -93,7 +98,7 @@ namespace FoxTube.Background FontSize = 14, FontStyle = Windows.UI.Text.FontStyle.Italic, Foreground = new SolidColorBrush(Colors.Gray), - Text = string.Format("{0} uploaded new video", Channel) + Text = $"{Channel} uploaded new video" }); break; } @@ -142,36 +147,13 @@ namespace FoxTube.Background XmlDocument template = new XmlDocument(); switch (Type) { - case NotificationType.Comment: - template.LoadXml($@" - - - - {Channel} posted a new comment - {Content} - - - - - - - - - - - "); - break; - case NotificationType.Video: - template.LoadXml($@" + template.LoadXml($@" - {Channel} uploaded a new video {Content} + {Channel} uploaded a new video @@ -187,62 +169,28 @@ namespace FoxTube.Background break; case NotificationType.Changelog: - template.LoadXml($@" + template.LoadXml($@" - - + + {Content} - Changelog + {Channel} "); break; case NotificationType.Internal: - string thumb1 = string.IsNullOrWhiteSpace(Thumbnail) ? "Assets/AnnouncementThumb.png" : Thumbnail; - template.LoadXml($@" + template.LoadXml($@" - - - {Channel} - {Content} - - - - - - - - "); - break; - - case NotificationType.Post: - string thumb2 = string.IsNullOrWhiteSpace(Thumbnail) ? "" : $""; - template.LoadXml($@" - - - {thumb2} + - {Channel} - {Content} + {Content} + {Channel} - - - - - - - "); break; } diff --git a/FoxTube/Controls/NotificationsCenter.xaml.cs b/FoxTube/Controls/NotificationsCenter.xaml.cs index 81f7810..aa9d015 100644 --- a/FoxTube/Controls/NotificationsCenter.xaml.cs +++ b/FoxTube/Controls/NotificationsCenter.xaml.cs @@ -36,28 +36,13 @@ namespace FoxTube public void Initialize() { - if (settings.Values["notificationsHistory"] != null) + try { doc.LoadXml(settings.Values["notificationsHistory"] as string); foreach (XmlElement n in doc["history"].ChildNodes) - { - AddNotification(new Notification( - n.GetAttribute("type"), - n.GetAttribute("id"), - n["channelName"].InnerText, - n["content"].InnerText, - XmlConvert.ToDateTime(n.GetAttribute("time"), "YYYY-MM-DDThh:mm:ss"), - n["images"].GetAttribute("thumbnail"), - n["images"].GetAttribute("avatar") - )); - } - } - else - { - doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null)); - doc.AppendChild(doc.CreateElement("history")); - settings.Values.Add("notificationsHistory", doc.InnerXml); + AddNotification(new Notification(n.ToString())); } + catch { } BackgroundProcessor.NotificationRecieved += NewNotification; } @@ -95,6 +80,7 @@ namespace FoxTube Notification n = notifications[array.Children.IndexOf(sender as Button)]; switch(n.Type) { + case NotificationType.Changelog: case NotificationType.Internal: Methods.MainPage.GoToDeveloper(n.Id); break; diff --git a/FoxTube/FoxTube.csproj b/FoxTube/FoxTube.csproj index d2f7579..5898399 100644 --- a/FoxTube/FoxTube.csproj +++ b/FoxTube/FoxTube.csproj @@ -130,9 +130,6 @@ About.xaml - - Feedback.xaml - History.xaml @@ -160,6 +157,9 @@ PlaylistPage.xaml + + Subscriptions.xaml + Search.xaml @@ -315,10 +315,6 @@ Designer MSBuild:Compile - - Designer - MSBuild:Compile - Designer MSBuild:Compile @@ -367,6 +363,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/FoxTube/Pages/LoadingPage.xaml.cs b/FoxTube/Pages/LoadingPage.xaml.cs index e783b84..7ddfb17 100644 --- a/FoxTube/Pages/LoadingPage.xaml.cs +++ b/FoxTube/Pages/LoadingPage.xaml.cs @@ -72,11 +72,9 @@ namespace FoxTube await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:troubleshoot")); } - private void feedback_Click(object sender, RoutedEventArgs e) + private async void feedback_Click(object sender, RoutedEventArgs e) { - Frame root = Window.Current.Content as Frame; - MainPage main = root.Content as MainPage; - main.PreDefineFeedback(true, string.Format("Exception:\n{0}\n\nMessage:\n{1}", exception, message)); + await Windows.System.Launcher.LaunchUriAsync(new Uri("feedback-hub:")); } private void wifiRefresh_Click(object sender, RoutedEventArgs e) diff --git a/FoxTube/Pages/MainPage.xaml b/FoxTube/Pages/MainPage.xaml index 9c83845..a6b2ba9 100644 --- a/FoxTube/Pages/MainPage.xaml +++ b/FoxTube/Pages/MainPage.xaml @@ -52,7 +52,7 @@ - + diff --git a/FoxTube/Pages/MainPage.xaml.cs b/FoxTube/Pages/MainPage.xaml.cs index faa9361..8543a7d 100644 --- a/FoxTube/Pages/MainPage.xaml.cs +++ b/FoxTube/Pages/MainPage.xaml.cs @@ -90,9 +90,17 @@ namespace FoxTube if (settings.Values["defaultDownload"] == null) settings.Values.Add("defaultDownload", Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\DownloadedVideos"); + if (settings.Values["notificationsHistory"] == null) + { + XmlDocument doc = new XmlDocument(); + doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null)); + doc.AppendChild(doc.CreateElement("history")); + settings.Values.Add("notificationsHistory", doc.InnerXml); + } + PackageVersion ver = Package.Current.Id.Version; if (settings.Values["ver"] == null) - settings.Values.Add("var", $"{ver.Major}.{ver.Minor}"); + settings.Values.Add("ver", $"{ver.Major}.{ver.Minor}"); if((string)settings.Values["ver"] != $"{ver.Major}.{ver.Minor}") { @@ -106,12 +114,12 @@ namespace FoxTube doc.LoadXml(settings.Values["notificationsHistory"] as string); Background.Notification n = new Background.Notification("changelog", - $"changelog-{e.GetAttribute("version")}", + $"changelog-{e.GetAttribute("version").Replace('.', '-')}", "Changelog", - $"What's new in version {e.GetAttribute("version")}", - XmlConvert.ToDateTimeOffset(e.GetAttribute("time"), "YYYY-MM-DDThh:mm:ss"), - "", - ""); + $"What's new in version {e.GetAttribute("version")}", + DateTime.Parse(e.GetAttribute("time")), + "http://foxgame.hol.es/FoxTubeAssets/WhatsNewThumb.png", + "http://foxgame.hol.es/FoxTubeAssets/NewsAvatar.png"); doc["history"].InnerXml += n.GetXml(); settings.Values["notificationsHistory"] = doc.InnerXml; @@ -137,14 +145,19 @@ namespace FoxTube public void SetTitleBar() { var titleBar = ApplicationView.GetForCurrentView().TitleBar; - - titleBar.ButtonForegroundColor = Colors.Black; + titleBar.ButtonBackgroundColor = Colors.Transparent; titleBar.ButtonHoverBackgroundColor = Colors.IndianRed; titleBar.ButtonPressedBackgroundColor = Colors.DarkRed; + titleBar.ButtonInactiveBackgroundColor = Colors.Transparent; + + if (RequestedTheme == ElementTheme.Dark) + titleBar.ButtonForegroundColor = Colors.White; + else if(RequestedTheme == ElementTheme.Light) + titleBar.ButtonForegroundColor = Colors.Black; CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar; - coreTitleBar.ExtendViewIntoTitleBar = false; + coreTitleBar.ExtendViewIntoTitleBar = true; } private void SecretsVault_SubscriptionsChanged(object sender, params object[] args) @@ -255,14 +268,9 @@ namespace FoxTube notificationMenu.Content = "\xED0D"; } - private void feedback_Click(object sender, RoutedEventArgs e) + private async void feedback_Click(object sender, RoutedEventArgs e) { - content.Navigate(typeof(Settings), "feedback"); - } - - public void PreDefineFeedback(bool isProblem, string meta) - { - content.Navigate(typeof(Settings), $"feedback&isProblem={isProblem}&meta={meta}"); + await Launcher.LaunchUriAsync(new Uri("feedback-hub:")); } private async void createAccount_Click(object sender, RoutedEventArgs e) @@ -447,7 +455,7 @@ namespace FoxTube else if (args.SelectedItem == toLater) content.Navigate(typeof(PlaylistPage), SecretsVault.UserChannel.ContentDetails.RelatedPlaylists.WatchLater); else if (args.SelectedItem == toSubscriptions) - content.Navigate(typeof(Settings)); + content.Navigate(typeof(Subscriptions)); else if (args.SelectedItem == toDownloads) content.Navigate(typeof(Downloads)); else if (args.SelectedItem == toChannel) @@ -468,6 +476,7 @@ namespace FoxTube { typeof(ChannelPage), () => header.Text = "Channel" }, { typeof(PlaylistPage), () => header.Text = "Playlist" }, { typeof(Search), () => header.Text = "Search" }, + { typeof(Subscriptions), () => header.Text = "Subscriptions" }, { typeof(History), () => header.Text = "History" }, { typeof(Home), () => header.Text = "Home" }, { typeof(Downloads), () => header.Text = "Downloads" } @@ -488,9 +497,9 @@ namespace FoxTube nav.SelectedItem = nav.SettingsItem; else s = Sender.None; - + } }, - { typeof(ChannelPage), () => + { typeof(ChannelPage), () => { if((content.Content as ChannelPage).channelId == SecretsVault.AccountId) { @@ -512,14 +521,14 @@ namespace FoxTube b = true; break; } - + if(!b) { nav.SelectedItem = null; } } } }, - { typeof(PlaylistPage), () => + { typeof(PlaylistPage), () => { if((content.Content as PlaylistPage).playlistId == SecretsVault.UserChannel.ContentDetails.RelatedPlaylists.Likes) { @@ -540,10 +549,14 @@ namespace FoxTube nav.SelectedItem = null; } } }, - { typeof(Search), () => - { - nav.SelectedItem = null; - } }, + { typeof(Search), () => nav.SelectedItem = null }, + {typeof(Subscriptions), () => + { + if(nav.SelectedItem != toSubscriptions) + nav.SelectedItem = toSubscriptions; + else + s = Sender.None; + } }, { typeof(History), () => { if(nav.SelectedItem != toHistory) diff --git a/FoxTube/Pages/Settings.xaml b/FoxTube/Pages/Settings.xaml index 19b3e70..c674962 100644 --- a/FoxTube/Pages/Settings.xaml +++ b/FoxTube/Pages/Settings.xaml @@ -16,11 +16,6 @@ - - - - - diff --git a/FoxTube/Pages/Settings.xaml.cs b/FoxTube/Pages/Settings.xaml.cs index 68516e5..787c375 100644 --- a/FoxTube/Pages/Settings.xaml.cs +++ b/FoxTube/Pages/Settings.xaml.cs @@ -38,13 +38,7 @@ namespace FoxTube base.OnNavigatedTo(e); if(!string.IsNullOrWhiteSpace(e.Parameter as string)) { - if((e.Parameter as string).Contains("feedback")) - { - pivot.SelectedIndex = 1; - if ((string)e.Parameter != "feedback") - ((pivot.SelectedItem as PivotItem).Content as Feedback).PreDefine(Convert.ToBoolean((e.Parameter as string).Split('&', '=')[2]), (e.Parameter as string).Split('&', '=')[4]); - } - else if ((e.Parameter as string).Contains("inbox")) + if ((e.Parameter as string).Contains("inbox")) { pivot.SelectedIndex = 4; if ((string)e.Parameter != "inbox") @@ -65,7 +59,7 @@ namespace FoxTube private void pivot_SelectionChanged(object sender, SelectionChangedEventArgs e) { - if (pivot.SelectedIndex == 4 && !inboxLoaded) + if (pivot.SelectedIndex == 3 && !inboxLoaded) { (((pivot.Items[4] as PivotItem).Content as ScrollViewer).Content as Inbox).LoadItems(); inboxLoaded = true; diff --git a/FoxTube/Pages/SettingsPages/About.xaml b/FoxTube/Pages/SettingsPages/About.xaml index 881b065..1317355 100644 --- a/FoxTube/Pages/SettingsPages/About.xaml +++ b/FoxTube/Pages/SettingsPages/About.xaml @@ -8,7 +8,7 @@ mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> - + @@ -50,6 +50,7 @@ + + + + + + + + + + + + + + + + + + + diff --git a/FoxTube/Pages/Subscriptions.xaml.cs b/FoxTube/Pages/Subscriptions.xaml.cs new file mode 100644 index 0000000..4a56ebf --- /dev/null +++ b/FoxTube/Pages/Subscriptions.xaml.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; +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 Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 + +namespace FoxTube.Pages +{ + /// + /// An empty page that can be used on its own or navigated to within a Frame. + /// + public sealed partial class Subscriptions : Page + { + public Subscriptions() + { + this.InitializeComponent(); + } + } +}