Notification system development 1
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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($@"<toast launch='type=comment&action=open&id={assignedId}'>
|
||||
template.LoadXml($@"<toast launch='comment&{Id}'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='{Avatar}'/>
|
||||
@@ -156,16 +157,16 @@ namespace FoxTube.Background
|
||||
|
||||
<action content='Send' imageUri='Assets/Icons/Send.png'
|
||||
hint-inputId='textBox' activationType='background'
|
||||
arguments='type=comment&action=sendReply&id={assignedId}'/>
|
||||
arguments='comment&{Id}&send'/>
|
||||
|
||||
<action content='Like'
|
||||
arguments='type=comment&action=like&id={assignedId}'/>
|
||||
arguments='comment&{Id}&like'/>
|
||||
</actions>
|
||||
</toast>");
|
||||
break;
|
||||
|
||||
case NotificationType.Video:
|
||||
template.LoadXml($@"<toast launch='action=viewPhoto&photoId=92187'>
|
||||
template.LoadXml($@"<toast launch='video&{Id}'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='{Avatar}'/>
|
||||
@@ -178,16 +179,29 @@ namespace FoxTube.Background
|
||||
<actions>
|
||||
<action content='Watch later'
|
||||
activationType='background'
|
||||
arguments='likePhoto&photoId=92187'/>
|
||||
arguments='video&{Id}&later'/>
|
||||
<action content='Go to channel'
|
||||
arguments='action=commentPhoto&photoId=92187'/>
|
||||
arguments='video&{Id}&channel'/>
|
||||
</actions>
|
||||
</toast>");
|
||||
break;
|
||||
|
||||
case NotificationType.Changelog:
|
||||
template.LoadXml($@"<toast launch='changelog&{Id}'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='hero' src='Assets/WhatsNewThumb.png'/>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='Assets/LogoAvatar.png'/>
|
||||
<text>{Content}</text>
|
||||
<text>Changelog</text>
|
||||
</binding>
|
||||
</visual>
|
||||
</toast>");
|
||||
break;
|
||||
|
||||
case NotificationType.Internal:
|
||||
string thumb1 = string.IsNullOrWhiteSpace(Thumbnail) ? "Assets/AnnouncementThumb.png" : Thumbnail;
|
||||
template.LoadXml($@"<toast launch='action=openThread&threadId=92187'>
|
||||
template.LoadXml($@"<toast launch='internal&{Id}'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='hero' src='{thumb1}'/>
|
||||
@@ -199,9 +213,9 @@ namespace FoxTube.Background
|
||||
|
||||
<actions>
|
||||
<action content='Watch full post'
|
||||
arguments='action=commentPhoto&photoId=92187'/>
|
||||
arguments='internal&{Id}'/>
|
||||
<action content='Manage notifications'
|
||||
arguments='action=commentPhoto&photoId=92187'/>
|
||||
arguments='notifications'/>
|
||||
</actions>
|
||||
</toast>");
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user