DownloadAgent
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
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 class Notification
|
||||
{
|
||||
public string Channel { get; set; }
|
||||
public string Content { get; set; }
|
||||
public DateTime TimeStamp { get; set; }
|
||||
public NotificationType Type { get; set; }
|
||||
public string Avatar { get; set; }
|
||||
public string Thumbnail { get; set; }
|
||||
|
||||
public Notification(NotificationType type,
|
||||
string channelName, string content, DateTime date,
|
||||
string thumbnailUrl, string avatarUrl = "ms-appx:///Assets/Icons/Profile.png")
|
||||
{
|
||||
Channel = channelName;
|
||||
Content = content;
|
||||
TimeStamp = date;
|
||||
Type = type;
|
||||
Avatar = avatarUrl;
|
||||
Thumbnail = thumbnailUrl;
|
||||
}
|
||||
|
||||
public UIElement 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($@"<toast launch='type=comment&action=open&id={assignedId}'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='{Avatar}'/>
|
||||
<text>{Channel} posted a new comment</text>
|
||||
<text>{Content}</text>
|
||||
</binding>
|
||||
</visual>
|
||||
|
||||
<actions>
|
||||
<input id='textBox' type='text' placeHolderContent='Send a reply'/>
|
||||
|
||||
<action content='Send' imageUri='Assets/Icons/Send.png'
|
||||
hint-inputId='textBox' activationType='background'
|
||||
arguments='type=comment&action=sendReply&id={assignedId}'/>
|
||||
|
||||
<action content='Like'
|
||||
arguments='type=comment&action=like&id={assignedId}'/>
|
||||
</actions>
|
||||
</toast>");
|
||||
break;
|
||||
|
||||
case NotificationType.Video:
|
||||
template.LoadXml($@"<toast launch='action=viewPhoto&photoId=92187'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='{Avatar}'/>
|
||||
<text>{Channel} uploaded a new video</text>
|
||||
<text>{Content}</text>
|
||||
<image src='{Thumbnail}'/>
|
||||
</binding>
|
||||
</visual>
|
||||
|
||||
<actions>
|
||||
<action content='Watch later'
|
||||
activationType='background'
|
||||
arguments='likePhoto&photoId=92187'/>
|
||||
<action content='Go to channel'
|
||||
arguments='action=commentPhoto&photoId=92187'/>
|
||||
</actions>
|
||||
</toast>");
|
||||
Reference in New Issue
Block a user