diff --git a/FoxTube.Background/BackgroundProcessor.cs b/FoxTube.Background/BackgroundProcessor.cs index 5d91aa0..45e1136 100644 --- a/FoxTube.Background/BackgroundProcessor.cs +++ b/FoxTube.Background/BackgroundProcessor.cs @@ -16,7 +16,7 @@ using Windows.UI.Notifications; namespace FoxTube.Background { - public delegate void NotificationHandler(object sender, string xml); + public delegate void NotificationHandler(object sender, Notification item); public sealed class BackgroundProcessor : IBackgroundTask { @@ -45,7 +45,7 @@ namespace FoxTube.Background { def = taskInstance.GetDeferral(); if (settings.Values["lastCheck"] == null) - settings.Values.Add("lastCheck", XmlConvert.ToString(DateTime.Now)); + 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) @@ -57,9 +57,6 @@ namespace FoxTube.Background settings.Values.Add("notificationsHistory", doc.InnerXml); } - if((bool)settings.Values["authorized"] == true) - CheckAccount(); - CheckAnnouncements(); SendNSave(); @@ -114,49 +111,44 @@ namespace FoxTube.Background } } - string CheckAnnouncements() + void CheckAnnouncements() { XmlDocument doc = new XmlDocument(); - doc.Load(XmlReader.Create("http://foxgame.hol.es/ftp.xml")); - if ((XmlConvert.ToDateTime((doc["posts"].FirstChild as XmlElement).GetAttribute("time"), XmlDateTimeSerializationMode.Utc) - lastCheck.ToUniversalTime()).TotalSeconds > 0) + 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["notificationHeader"].InnerText, doc["posts"].FirstChild["content"].InnerText, - XmlConvert.ToDateTime((doc["posts"].FirstChild as XmlElement).GetAttribute("time"), - XmlDateTimeSerializationMode.Unspecified), + XmlConvert.ToDateTimeOffset((doc["posts"].FirstChild as XmlElement).GetAttribute("time"), "YYYY-MM-DDThh:mm:ss"), (doc["posts"].FirstChild as XmlElement).GetAttribute("image"), null)); - - return doc.InnerXml; } void SendNotification(Notification notification) { - ToastNotificationManager.CreateToastNotifier().Show(notification.GetToast(0)); + ToastNotificationManager.CreateToastNotifier().Show(notification.GetToast()); } void SendNSave() { foreach (Notification n in Notifications) { - NotificationRecieved.Invoke(this, n.GetXml()); + NotificationRecieved.Invoke(this, n); doc["history"].InnerXml += n.GetXml(); } settings.Values.Add("notificationsHistory", doc.InnerXml); - if ((bool)settings.Values["notifications"]) - foreach (Notification n in Notifications) - switch (n.Type) - { - case NotificationType.Video: - if ((bool)settings.Values["newVideoNotification"]) - SendNotification(n); - break; + foreach (Notification n in Notifications) + switch (n.Type) + { + case NotificationType.Video: + if ((bool)settings.Values["newVideoNotification"]) + SendNotification(n); + break; - case NotificationType.Internal: - if ((bool)settings.Values["newmessagesNotification"]) - SendNotification(n); - break; - } + case NotificationType.Internal: + SendNotification(n); + break; + } } } } diff --git a/FoxTube.Background/Notification.cs b/FoxTube.Background/Notification.cs index a2c17b5..aca3e3f 100644 --- a/FoxTube.Background/Notification.cs +++ b/FoxTube.Background/Notification.cs @@ -15,7 +15,7 @@ namespace FoxTube.Background { public enum NotificationType { - Video, Comment, Post, Internal + Video, Comment, Post, Internal, Changelog } public sealed class Notification @@ -35,6 +35,7 @@ namespace FoxTube.Background Channel = channelName; Content = content; TimeStamp = date; + Id = id; Type = TypeConversion(type); Avatar = avatarUrl == null? "ms-appx:///Assets/Icons/Profile.png" : avatarUrl; Thumbnail = thumbnailUrl; @@ -136,13 +137,13 @@ namespace FoxTube.Background return item; } - public ToastNotification GetToast(int assignedId) + public ToastNotification GetToast() { XmlDocument template = new XmlDocument(); switch (Type) { case NotificationType.Comment: - template.LoadXml($@" + template.LoadXml($@" @@ -156,16 +157,16 @@ namespace FoxTube.Background + arguments='comment&{Id}&send'/> + arguments='comment&{Id}&like'/> "); break; case NotificationType.Video: - template.LoadXml($@" + template.LoadXml($@" @@ -178,16 +179,29 @@ namespace FoxTube.Background + arguments='video&{Id}&later'/> + arguments='video&{Id}&channel'/> "); break; + case NotificationType.Changelog: + template.LoadXml($@" + + + + + {Content} + Changelog + + + "); + break; + case NotificationType.Internal: string thumb1 = string.IsNullOrWhiteSpace(Thumbnail) ? "Assets/AnnouncementThumb.png" : Thumbnail; - template.LoadXml($@" + template.LoadXml($@" @@ -199,9 +213,9 @@ namespace FoxTube.Background + arguments='internal&{Id}'/> + arguments='notifications'/> "); break; @@ -246,6 +260,8 @@ namespace FoxTube.Background return "post"; case NotificationType.Video: return "video"; + case NotificationType.Changelog: + return "changelog"; default: return "internal"; } @@ -261,6 +277,8 @@ namespace FoxTube.Background return NotificationType.Post; case "video": return NotificationType.Video; + case "changelog": + return NotificationType.Changelog; default: return NotificationType.Internal; } diff --git a/FoxTube/Classes/InboxItem.cs b/FoxTube/Classes/InboxItem.cs index 7e99901..842d370 100644 --- a/FoxTube/Classes/InboxItem.cs +++ b/FoxTube/Classes/InboxItem.cs @@ -13,6 +13,7 @@ namespace FoxTube.Classes public string PatchVersion { get; set; } public string Subject { get; set; } public string Content { get; set; } + public string Id { get; set; } public string Icon { @@ -47,20 +48,22 @@ namespace FoxTube.Classes } - public InboxItem(string version, string content, string timeStamp) + public InboxItem(string version, string content, string timeStamp, string id) { Type = InboxItemType.PatchNote; PatchVersion = version; Content = content; TimeStamp = DateTime.Parse(timeStamp); + Id = id; } - public InboxItem(string title, string content, DateTime timeStamp) + public InboxItem(string title, string content, DateTime timeStamp, string id) { Type = InboxItemType.Default; Content = content; Subject = title; TimeStamp = timeStamp; + Id = id; } } } diff --git a/FoxTube/Classes/SecretsVault.cs b/FoxTube/Classes/SecretsVault.cs index 20f395e..4be5580 100644 --- a/FoxTube/Classes/SecretsVault.cs +++ b/FoxTube/Classes/SecretsVault.cs @@ -111,11 +111,19 @@ namespace FoxTube public static async void Authorize() { - try { Credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, new[] { Google.Apis.Oauth2.v2.Oauth2Service.Scope.UserinfoProfile, YouTubeService.Scope.YoutubeForceSsl }, "user", CancellationToken.None); } - catch { } - if(Credential != null) + try { - try + Credential = await GoogleWebAuthorizationBroker.AuthorizeAsync( + Secrets, + new[] + { + Google.Apis.Oauth2.v2.Oauth2Service.Scope.UserinfoProfile, + YouTubeService.Scope.YoutubeForceSsl + }, + "user", + CancellationToken.None); + + if (Credential != null) { if (settings.Values["authorized"] == null) settings.Values.Add("authorized", true); @@ -174,27 +182,27 @@ namespace FoxTube Subscriptions.Add(s); } } - catch - { - MessageDialog dialog = new MessageDialog("We were unabled to retrieve your account information due to weak internet connection or Google servers' problems. PLease, try again later", "Failed to connect"); - - dialog.Commands.Add(new UICommand("Try again", (command) => - { - Authorize(); - })); - dialog.Commands.Add(new UICommand("Quit", (command) => - { - Methods.CloseApp(); - })); - dialog.Commands.Add(new UICommand("Close")); - - await dialog.ShowAsync(); - - IsAuthorized = false; - } - - AuthorizationStateChanged.Invoke(null, null); } + catch + { + MessageDialog dialog = new MessageDialog("We were unabled to retrieve your account information due to weak internet connection or Google servers' problems. PLease, try again later", "Failed to connect"); + + dialog.Commands.Add(new UICommand("Try again", (command) => + { + Authorize(); + })); + dialog.Commands.Add(new UICommand("Quit", (command) => + { + Methods.CloseApp(); + })); + dialog.Commands.Add(new UICommand("Close")); + + await dialog.ShowAsync(); + + IsAuthorized = false; + } + + AuthorizationStateChanged.Invoke(null, null); } public static async void Deauthenticate() diff --git a/FoxTube/Controls/NotificationsCenter.xaml b/FoxTube/Controls/NotificationsCenter.xaml index d57aaef..d8261ed 100644 --- a/FoxTube/Controls/NotificationsCenter.xaml +++ b/FoxTube/Controls/NotificationsCenter.xaml @@ -6,17 +6,14 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" - d:DesignHeight="450" - d:DesignWidth="350"> + d:DesignHeight="400" + d:DesignWidth="300"> - - + + - -