144 lines
7.7 KiB
C#
144 lines
7.7 KiB
C#
using Newtonsoft.Json;
|
|
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 Dictionary<string, string> languagePack = LoadPack();
|
|
|
|
private static Dictionary<string, string> LoadPack()
|
|
{
|
|
object[] saved = JsonConvert.DeserializeObject<object[]>(ApplicationData.Current.RoamingSettings.Values["settings"] as string);
|
|
if (saved[7] as string == "ru-RU")
|
|
return new Dictionary<string, string>()
|
|
{
|
|
{ "addLater", "Посмотреть позже" },
|
|
{ "changelog", "Список изменений" },
|
|
{ "changelogHeader", "Что нового в версии" },
|
|
{ "videoContent", "загрузил новое видео" },
|
|
{ "goChannel", "Открыть канал" }
|
|
};
|
|
else
|
|
return new Dictionary<string, string>()
|
|
{
|
|
{ "addLater", "Add to Watch later" },
|
|
{ "changelog", "Changelog" },
|
|
{ "changelogHeader", "What's new in version" },
|
|
{ "videoContent", "uploaded a new video" },
|
|
{ "goChannel", "Go to channel" }
|
|
};
|
|
}
|
|
|
|
public static ToastNotification GetChangelogToast(string version)
|
|
{
|
|
XmlDocument template = new XmlDocument();
|
|
|
|
template.LoadXml($@"<toast activationType='foreground' launch='changelog|{version}'>
|
|
<visual>
|
|
<binding template='ToastGeneric'>
|
|
<image placement='hero' src='http://foxgame-studio.000webhostapp.com/FoxTubeAssets/WhatsNewThumb.png'/>
|
|
<image placement='appLogoOverride' hint-crop='circle' src='http://foxgame-studio.000webhostapp.com/FoxTubeAssets/NewsAvatar.png'/>
|
|
<text>{languagePack["changelog"]}</text>
|
|
<text>{languagePack["changelogHeader"]} {version}</text>
|
|
</binding>
|
|
</visual>
|
|
</toast>");
|
|
|
|
return new ToastNotification(template);
|
|
}
|
|
|
|
public static ToastNotification GetVideoToast(string id, string channelId, string title, string channel, string thumbnail, string avatar)
|
|
{
|
|
XmlDocument template = new XmlDocument();
|
|
|
|
template.LoadXml($@"<toast activationType='foreground' launch='video|{id}'>
|
|
<visual>
|
|
<binding template='ToastGeneric'>
|
|
<image placement='hero' src='{thumbnail.Replace("&", "%26")}'/>
|
|
<image placement='appLogoOverride' hint-crop='circle' src='{avatar.Replace("&", "%26") ?? "http://foxgame-studio.000webhostapp.com/FoxTubeAssets/LogoAvatar.png"}'/>
|
|
<text>{title}</text>
|
|
<text>{channel} {languagePack["videoContent"]}</text>
|
|
</binding>
|
|
</visual>
|
|
|
|
<actions>
|
|
<action content='{languagePack["addLater"]}' activationType='background' arguments='later|{id}'/>
|
|
<action content='{languagePack["goChannel"]}' activationType='foreground' arguments='channel|{channelId}'/>
|
|
</actions>
|
|
</toast>");
|
|
|
|
return new ToastNotification(template);
|
|
}
|
|
|
|
public static ToastNotification GetInternalToast(string id, string header, string content, string thumbnail, string avatar)
|
|
{
|
|
XmlDocument template = new XmlDocument();
|
|
|
|
template.LoadXml($@"<toast activationType='foreground' launch='inbox|{id}'>
|
|
<visual>
|
|
<binding template='ToastGeneric'>
|
|
<image placement='hero' src='{thumbnail ?? "http://foxgame-studio.000webhostapp.com/FoxTubeAssets/AnnouncementThumb.png"}'/>
|
|
<image placement='appLogoOverride' hint-crop='circle' src='{avatar ?? "http://foxgame-studio.000webhostapp.com/FoxTubeAssets/LogoAvatar.png"}'/>
|
|
<text>{header}</text>
|
|
<text hint-maxLines='5'>{content}</text>
|
|
</binding>
|
|
</visual>
|
|
</toast>");
|
|
|
|
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($@" <tile>
|
|
<visual>
|
|
|
|
<binding template='TileMedium' branding='none'>
|
|
<image placement='peek' src='{avatar?.Replace("&", "%26")}'/>
|
|
<image placement='background' src='{thumbnail?.Replace("&", "%26")}'/>
|
|
<text hint-style='base' hint-overlay='60'>{channel}</text>
|
|
<text hint-wrap='true' hint-style='captionSubtle'>{title}</text>
|
|
</binding>
|
|
|
|
<binding template='TileWide' Branding='nameAndLogo'>
|
|
<image placement='background' hint-overlay='60' src='{thumbnail?.Replace("&", "%26")}'/>
|
|
<group>
|
|
<subgroup hint-weight='33'>
|
|
<image src='{avatar?.Replace("&", "%26")}' hint-crop='circle' />
|
|
</subgroup>
|
|
<subgroup hint-textStacking='center'>
|
|
<text hint-style='base'>{channel}</text>
|
|
<text hint-wrap='true' hint-style='captionSubtle'>{title}</text>
|
|
</subgroup>
|
|
</group>
|
|
</binding>
|
|
|
|
<binding template='TileLarge' hint-textStacking='top' Branding='nameAndLogo'>
|
|
<image placement='background' hint-overlay='60' src='{thumbnail?.Replace("&", "%26")}'/>
|
|
<group>
|
|
<subgroup hint-weight='33'>
|
|
<image src='{avatar?.Replace("&", "%26")}' hint-crop='circle' />
|
|
</subgroup>
|
|
<subgroup hint-textStacking='center'>
|
|
<text hint-style='base'>{channel}</text>
|
|
<text hint-wrap='true' hint-style='captionSubtle'>{title}</text>
|
|
</subgroup>
|
|
</group>
|
|
</binding>
|
|
</visual>
|
|
</tile>");
|
|
|
|
return new TileNotification(doc);
|
|
}
|
|
}
|
|
}
|