Archived
1
0

Notification system done

This commit is contained in:
Michael Gordeev
2018-11-04 15:15:57 +03:00
parent 3661f9be38
commit 75cf389286
8 changed files with 77 additions and 138 deletions
+2 -25
View File
@@ -1,16 +1,9 @@
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Services;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using Windows.ApplicationModel.Background;
using Windows.Storage;
@@ -21,14 +14,7 @@ namespace FoxTube.Background
public sealed class BackgroundProcessor : IBackgroundTask
{
private DateTime lastCheck = DateTime.Now;
private ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
private ClientSecrets Secrets => new ClientSecrets()
{
ClientId = "349735264870-2ekqlm0a4mkg3mmrfcv90s3qp3o15dq0.apps.googleusercontent.com",
ClientSecret = "BkVZOAaCU2Zclf0Zlicg6y2_"
};
private YouTubeService Service => new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = "AIzaSyBgHrCnrlzlVmk0cJKL8RqP9Y8x6XSuk_0",
@@ -66,12 +52,7 @@ namespace FoxTube.Background
{
try
{
ToastNotificationManager.CreateToastNotifier().Show(Notification.GetInternalToast(null, "Checking videos...", DateTime.Now.ToString(), null, null));
Dictionary<string, string> subscriptions = JsonConvert.DeserializeObject<Dictionary<string, string>>(await FileIO.ReadTextAsync(await ApplicationData.Current.RoamingFolder.GetFileAsync("background.json")));
Debug.WriteLine("Subscriptions list");
foreach (var i in subscriptions)
Debug.WriteLine($"{i.Key}: {i.Value}");
Debug.WriteLine("Subscriptions list end");
foreach (var s in subscriptions)
{
SearchResource.ListRequest request = Service.Search.List("snippet");
@@ -81,16 +62,12 @@ namespace FoxTube.Background
request.MaxResults = 5;
SearchListResponse response = await request.ExecuteAsync();
foreach (var i in response.Items)
foreach (SearchResult i in response.Items)
ToastNotificationManager.CreateToastNotifier().Show(
Notification.GetVideoToast(i.Id.VideoId, i.Snippet.ChannelId, i.Snippet.Title, i.Snippet.ChannelTitle, i.Snippet.Thumbnails.Medium.Url, s.Value));
ToastNotificationManager.CreateToastNotifier().Show(Notification.GetVideoToast(null, s.Key, DateTime.Now.ToString(), s.Key, null, s.Value));
}
}
catch { }
ToastNotificationManager.CreateToastNotifier().Show(Notification.GetInternalToast(null, "New videos checked", DateTime.Now.ToString(), null, null));
}
void CheckAnnouncements()