2017-10-18 10:32:51 +02:00
|
|
|
|
using System;
|
2017-10-19 15:53:03 +02:00
|
|
|
|
using Windows.Data.Json;
|
2017-10-18 10:32:51 +02:00
|
|
|
|
using Windows.Data.Xml.Dom;
|
|
|
|
|
using Windows.UI.Notifications;
|
|
|
|
|
using ModernKeePass.Interfaces;
|
2017-10-25 18:29:50 +02:00
|
|
|
|
using ModernKeePass.ViewModels;
|
2017-10-18 10:32:51 +02:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Common
|
|
|
|
|
{
|
|
|
|
|
public static class ToastNotificationHelper
|
|
|
|
|
{
|
2017-10-31 18:49:18 +01:00
|
|
|
|
public static void ShowMovedToast(IPwEntity entity, string action, string text)
|
2017-10-18 10:32:51 +02:00
|
|
|
|
{
|
2017-10-25 18:29:50 +02:00
|
|
|
|
var entityType = entity is GroupVm ? "Group" : "Entry";
|
2017-10-18 10:32:51 +02:00
|
|
|
|
var notificationXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
|
|
|
|
|
var toastElements = notificationXml.GetElementsByTagName("text");
|
2017-10-31 18:49:18 +01:00
|
|
|
|
toastElements[0].AppendChild(notificationXml.CreateTextNode($"{action} {entityType} {entity.Name}"));
|
|
|
|
|
toastElements[1].AppendChild(notificationXml.CreateTextNode(text));
|
2017-10-18 10:32:51 +02:00
|
|
|
|
var toastNode = notificationXml.SelectSingleNode("/toast");
|
|
|
|
|
|
2017-10-19 15:53:03 +02:00
|
|
|
|
var launch = new JsonObject
|
|
|
|
|
{
|
|
|
|
|
{"entityType", JsonValue.CreateStringValue(entityType)},
|
|
|
|
|
{"entityId", JsonValue.CreateStringValue(entity.Id)}
|
|
|
|
|
};
|
|
|
|
|
((XmlElement)toastNode)?.SetAttribute("launch", launch.Stringify());
|
2017-10-18 10:32:51 +02:00
|
|
|
|
|
|
|
|
|
var toast = new ToastNotification(notificationXml)
|
|
|
|
|
{
|
|
|
|
|
ExpirationTime = DateTime.Now.AddSeconds(5)
|
|
|
|
|
};
|
|
|
|
|
ToastNotificationManager.CreateToastNotifier().Show(toast);
|
|
|
|
|
}
|
2017-11-27 15:26:36 +01:00
|
|
|
|
|
|
|
|
|
public static void ShowGenericToast(string title, string text)
|
|
|
|
|
{
|
|
|
|
|
var notificationXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
|
|
|
|
|
var toastElements = notificationXml.GetElementsByTagName("text");
|
|
|
|
|
toastElements[0].AppendChild(notificationXml.CreateTextNode(title));
|
|
|
|
|
toastElements[1].AppendChild(notificationXml.CreateTextNode(text));
|
|
|
|
|
|
|
|
|
|
var toast = new ToastNotification(notificationXml)
|
|
|
|
|
{
|
|
|
|
|
ExpirationTime = DateTime.Now.AddSeconds(5)
|
|
|
|
|
};
|
|
|
|
|
ToastNotificationManager.CreateToastNotifier().Show(toast);
|
|
|
|
|
}
|
2017-10-18 10:32:51 +02:00
|
|
|
|
}
|
|
|
|
|
}
|