using Google.Apis.YouTube.v3.Data; using Microsoft.Toolkit.Uwp.Notifications; using Newtonsoft.Json; using System; using System.Collections.Generic; using Windows.Data.Xml.Dom; using Windows.Storage; using Windows.UI.Notifications; namespace FoxTube.Background { public static class Notification { private static readonly Dictionary languagePack = LoadPack(); private static Dictionary LoadPack() { dynamic saved = JsonConvert.DeserializeObject(ApplicationData.Current.RoamingSettings.Values["settings"] as string); if (saved.language as string == "ru-RU") return new Dictionary() { { "addLater", "Посмотреть позже" }, { "changelog", "Список изменений" }, { "changelogHeader", "Что нового в версии" }, { "videoContent", "загрузил новое видео" }, { "live", "ПРЯМОЙ ЭФИР" }, { "upcoming", "Запланирован" }, { "liveContent", "начал прямой эфир" }, { "upcomingContent", "запланировал прямой эфир" }, { "goChannel", "Открыть канал" } }; else return new Dictionary() { { "addLater", "Add to Watch later" }, { "changelog", "Changelog" }, { "changelogHeader", "What's new in version" }, { "videoContent", "uploaded a new video" }, { "live", "LIVE" }, { "upcoming", "Upcoming" }, { "liveContent", "started live broadcast" }, { "upcomingContent", "planned live broadcast" }, { "goChannel", "Go to channel" } }; } public static ToastNotification GetChangelogToast(string version) { XmlDocument template = new XmlDocument(); template.LoadXml($@" {languagePack["changelog"]} {languagePack["changelogHeader"]} {version} "); return new ToastNotification(template); } public static ToastNotification GetVideoToast(string id, string channelId, string title, string channel, string thumbnail, DateTimeOffset timeStamp, string avatar) { XmlDocument template = new XmlDocument(); string ts = $"{timeStamp.Year}-{timeStamp.Month:00}-{timeStamp.Day:00}T{timeStamp.Hour:00}:{timeStamp.Minute:00}:{timeStamp.Second:00}Z"; template.LoadXml($@" {System.Security.SecurityElement.Escape(title)} {System.Security.SecurityElement.Escape(channel)} {languagePack["videoContent"]} "); return new ToastNotification(template); } public static ToastNotification GetStreamToast(string id, string channelId, string title, string channel, string thumbnail, DateTimeOffset timeStamp, string avatar) { XmlDocument template = new XmlDocument(); string ts = $"{timeStamp.Year}-{timeStamp.Month:00}-{timeStamp.Day:00}T{timeStamp.Hour:00}:{timeStamp.Minute:00}:{timeStamp.Second:00}Z"; template.LoadXml($@" 🔴 [{languagePack["live"]}] {System.Security.SecurityElement.Escape(title)} {System.Security.SecurityElement.Escape(channel)} {languagePack["liveContent"]} "); return new ToastNotification(template); } public static ToastNotification GetUpcomingToast(string id, string channelId, string title, string channel, string thumbnail, DateTimeOffset timeStamp, string avatar) { XmlDocument template = new XmlDocument(); string ts = $"{timeStamp.Year}-{timeStamp.Month:00}-{timeStamp.Day:00}T{timeStamp.Hour:00}:{timeStamp.Minute:00}:{timeStamp.Second:00}Z"; template.LoadXml($@" 🔴 [{languagePack["upcoming"]}] {System.Security.SecurityElement.Escape(title)} {System.Security.SecurityElement.Escape(channel)} {languagePack["upcomingContent"]} "); return new ToastNotification(template); } public static ToastNotification GetInternalToast(string id, string header, string content, string thumbnail, string avatar) { XmlDocument template = new XmlDocument(); template.LoadXml($@" {header} {content} "); return new ToastNotification(template); } } public static class Tiles { public static TileNotification GetTileLayout(string title, string channel, string thumbnail, string avatar) { XmlDocument doc = new XmlDocument(); doc.LoadXml($@" {channel} {title} {channel} {title} {channel} {title} "); return new TileNotification(doc); } } }