using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Windows.Data.Xml.Dom; using Windows.UI; using Windows.UI.Notifications; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media.Imaging; namespace FoxTube.Background { public enum NotificationType { Video, Comment, Post, Internal } public sealed class Notification { public string Channel { get; set; } public string Content { get; set; } public DateTimeOffset TimeStamp { get; set; } public NotificationType Type { get; set; } public string Avatar { get; set; } public string Thumbnail { get; set; } public string Id { get; set; } public Notification(string type, string id, string channelName, string content, DateTimeOffset date, string thumbnailUrl, string avatarUrl) { Channel = channelName; Content = content; TimeStamp = date; Type = TypeConversion(type); Avatar = avatarUrl == null? "ms-appx:///Assets/Icons/Profile.png" : avatarUrl; Thumbnail = thumbnailUrl; } public string GetXml() { return $@" {Channel} {Content} "; } public Button GetNotification() { StackPanel stackPanel = new StackPanel() { Margin = new Thickness(10, 0, 0, 0) }; //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 }); break; case NotificationType.Post: 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) }); break; case NotificationType.Video: stackPanel.Children.Add(new TextBlock() { FontSize = 14, FontStyle = Windows.UI.Text.FontStyle.Italic, Foreground = new SolidColorBrush(Colors.Gray), Text = string.Format("{0} uploaded new video", Channel) }); break; } //Content stackPanel.Children.Add(new TextBlock() { TextWrapping = TextWrapping.WrapWholeWords, Text = Content, }); //Time stackPanel.Children.Add(new TextBlock() { FontSize = 13, Foreground = new SolidColorBrush(Colors.Gray), Text = TimeStamp.ToString() }); PersonPicture avatar = new PersonPicture() { Height = 50, VerticalAlignment = VerticalAlignment.Top, ProfilePicture = string.IsNullOrWhiteSpace(Avatar) ? null : new BitmapImage(new Uri(Avatar)) }; Grid grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(50) }); grid.ColumnDefinitions.Add(new ColumnDefinition()); grid.Children.Add(avatar); Grid.SetColumn(stackPanel, 1); grid.Children.Add(stackPanel); Button item = new Button() { HorizontalAlignment = HorizontalAlignment.Stretch, HorizontalContentAlignment = HorizontalAlignment.Left, Background = new SolidColorBrush(Colors.Transparent), Content = grid }; return item; } public ToastNotification GetToast(int assignedId) { XmlDocument template = new XmlDocument(); switch (Type) { case NotificationType.Comment: template.LoadXml($@" {Channel} posted a new comment {Content} "); break; case NotificationType.Video: template.LoadXml($@" {Channel} uploaded a new video {Content} "); break; case NotificationType.Internal: string thumb1 = string.IsNullOrWhiteSpace(Thumbnail) ? "Assets/AnnouncementThumb.png" : Thumbnail; template.LoadXml($@" {Channel} {Content} "); break; case NotificationType.Post: string thumb2 = string.IsNullOrWhiteSpace(Thumbnail) ? "" : $""; template.LoadXml($@" {thumb2} {Channel} {Content} "); break; } return new ToastNotification(template); } private string TypeConversion(NotificationType type) { switch(type) { case NotificationType.Comment: return "comment"; case NotificationType.Post: return "post"; case NotificationType.Video: return "video"; default: return "internal"; } } private NotificationType TypeConversion(string type) { switch (type) { case "comment": return NotificationType.Comment; case "post": return NotificationType.Post; case "video": return NotificationType.Video; default: return NotificationType.Internal; } } } }