Notificaions development 0
This commit is contained in:
@@ -1,235 +1,67 @@
|
||||
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.Data.Xml.Dom;
|
||||
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
|
||||
public static class Notification
|
||||
{
|
||||
Video, Comment, Post, Internal, Changelog
|
||||
}
|
||||
|
||||
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;
|
||||
Id = id;
|
||||
Type = TypeConversion(type);
|
||||
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 $@"<item time='{TimeStamp.ToString("YYYY-MM-DDThh:mm:ss")}' type='{TypeConversion(Type)}' id='{Id}'>
|
||||
<images thumbnail='{Thumbnail}' avatar='{Avatar}'/>
|
||||
<channelName>{Channel}</channelName>
|
||||
<content>{Content}</content>
|
||||
</item>";
|
||||
}
|
||||
|
||||
public Button GetNotification()
|
||||
{
|
||||
StackPanel stackPanel = new StackPanel() { Margin = new Thickness(10, 0, 0, 0) };
|
||||
|
||||
//Channel
|
||||
switch (Type)
|
||||
{
|
||||
case NotificationType.Internal:
|
||||
stackPanel.Children.Add(new TextBlock()
|
||||
{
|
||||
FontSize = 14,
|
||||
FontStyle = Windows.UI.Text.FontStyle.Italic,
|
||||
Foreground = new SolidColorBrush(Colors.Gray),
|
||||
Text = "Developer's message"
|
||||
});
|
||||
break;
|
||||
|
||||
case NotificationType.Changelog:
|
||||
stackPanel.Children.Add(new TextBlock()
|
||||
{
|
||||
FontSize = 14,
|
||||
FontStyle = Windows.UI.Text.FontStyle.Italic,
|
||||
Foreground = new SolidColorBrush(Colors.Gray),
|
||||
Text = "Changelog"
|
||||
});
|
||||
break;
|
||||
|
||||
case NotificationType.Video:
|
||||
stackPanel.Children.Add(new TextBlock()
|
||||
{
|
||||
FontSize = 14,
|
||||
FontStyle = Windows.UI.Text.FontStyle.Italic,
|
||||
Foreground = new SolidColorBrush(Colors.Gray),
|
||||
Text = $"{Channel} uploaded new video"
|
||||
});
|
||||
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()
|
||||
public static ToastNotification GetChangelogToast(string version)
|
||||
{
|
||||
XmlDocument template = new XmlDocument();
|
||||
switch (Type)
|
||||
{
|
||||
case NotificationType.Video:
|
||||
template.LoadXml($@"<toast launch='video={Id}'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='{Avatar}'/>
|
||||
<text>{Content}</text>
|
||||
<text>{Channel} uploaded a new video</text>
|
||||
<image src='{Thumbnail}'/>
|
||||
</binding>
|
||||
</visual>
|
||||
|
||||
<actions>
|
||||
<action content='Watch later'
|
||||
activationType='background'
|
||||
arguments='video&{Id}&later'/>
|
||||
<action content='Go to channel'
|
||||
arguments='video&{Id}&channel'/>
|
||||
</actions>
|
||||
</toast>");
|
||||
break;
|
||||
|
||||
case NotificationType.Changelog:
|
||||
template.LoadXml($@"<toast launch='{Id}'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='hero' src='http://foxgame.hol.es/FoxTubeAssets/WhatsNewThumb.png'/>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='http://foxgame.hol.es/FoxTubeAssets/NewsAvatar.png'/>
|
||||
<text>{Content}</text>
|
||||
<text>{Channel}</text>
|
||||
</binding>
|
||||
</visual>
|
||||
</toast>");
|
||||
break;
|
||||
|
||||
case NotificationType.Internal:
|
||||
template.LoadXml($@"<toast launch='internal={Id}'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='hero' src='{Thumbnail}'/>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='{Avatar}'/>
|
||||
<text>{Content}</text>
|
||||
<text hint-maxLines='5'>{Channel}</text>
|
||||
</binding>
|
||||
</visual>
|
||||
</toast>");
|
||||
break;
|
||||
}
|
||||
template.LoadXml($@"<toast activationType='foreground' launch='changelog-{version.Replace(".", "-")}'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='hero' src='http://foxgame.hol.es/FoxTubeAssets/WhatsNewThumb.png'/>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='http://foxgame.hol.es/FoxTubeAssets/NewsAvatar.png'/>
|
||||
<text>Changelog</text>
|
||||
<text>See what's new in version {version}</text>
|
||||
</binding>
|
||||
</visual>
|
||||
</toast>");
|
||||
|
||||
return new ToastNotification(template);
|
||||
}
|
||||
|
||||
private string TypeConversion(NotificationType type)
|
||||
public static ToastNotification GetVideoToast(string id, string channelId, string title, string channel, string thumbnail, string avatar)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case NotificationType.Comment:
|
||||
return "comment";
|
||||
case NotificationType.Post:
|
||||
return "post";
|
||||
case NotificationType.Video:
|
||||
return "video";
|
||||
case NotificationType.Changelog:
|
||||
return "changelog";
|
||||
default:
|
||||
return "internal";
|
||||
}
|
||||
XmlDocument template = new XmlDocument();
|
||||
|
||||
template.LoadXml($@"<toast activationType='foreground' launch='video-{id}'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='hero' src='{thumbnail}'/>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='{avatar}'/>
|
||||
<text>{title}</text>
|
||||
<text>{channel} uploaded a new video</text>
|
||||
</binding>
|
||||
</visual>
|
||||
|
||||
<actions>
|
||||
<action content='Add to Watch later' activationType='background' arguments='later-{id}'/>
|
||||
<action content='Go to channel' activationType='foreground' arguments='channel-{channelId}'/>
|
||||
</actions>
|
||||
</toast>");
|
||||
|
||||
return new ToastNotification(template);
|
||||
}
|
||||
|
||||
private NotificationType TypeConversion(string type)
|
||||
public static ToastNotification GetInternalToast(string id, string header, string content, string thumbnail, string avatar)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case "comment":
|
||||
return NotificationType.Comment;
|
||||
case "post":
|
||||
return NotificationType.Post;
|
||||
case "video":
|
||||
return NotificationType.Video;
|
||||
case "changelog":
|
||||
return NotificationType.Changelog;
|
||||
default:
|
||||
return NotificationType.Internal;
|
||||
}
|
||||
XmlDocument template = new XmlDocument();
|
||||
|
||||
template.LoadXml($@"<toast activationType='foreground' launch='inbox-{id}'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='hero' src='{thumbnail ?? "http://foxgame.hol.es/FoxTubeAssets/AnnouncementThumb.png"}'/>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='{avatar ?? "http://foxgame.hol.es/FoxTubeAssets/LogoAvatar.png"}'/>
|
||||
<text>{header}</text>
|
||||
<text hint-maxLines='5'>{content}</text>
|
||||
</binding>
|
||||
</visual>
|
||||
</toast>");
|
||||
|
||||
return new ToastNotification(template);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user