Archived
1
0
This repository has been archived on 2026-04-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Michael Gordeev 787a6e9f48 Refactored core
UI navigation framework

Related Work Items: #408, #414, #416
2020-06-15 15:46:38 +03:00

87 lines
2.7 KiB
C#

using FoxTube.Models.Collections;
using FoxTube.Utils;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Windows.UI.Notifications;
using Google.Apis.Blogger.v3;
using Google.Apis.Blogger.v3.Data;
using System.Linq;
using System.Globalization;
using Windows.Foundation.Metadata;
namespace FoxTube.Services
{
public static class InboxService
{
public static BloggerService Service { get; } = new BloggerService(new Google.Apis.Services.BaseClientService.Initializer
{
ApplicationName = "FoxTube",
ApiKey = SecretConstants.BloggerApiKey
});
private static readonly HttpClient client = new HttpClient();
public static InboxCollection GetInboxCollection() =>
new InboxCollection();
public static async Task PushNew()
{
try
{
PostsResource.ListRequest request = Service.Posts.List(SecretConstants.BlogId);
request.FetchImages = false;
request.Labels = "FoxTube";
request.MaxResults = 500;
request.StartDate = StorageService.LastInboxCheck.ToString("yyyy-MM-dd'T'HH:mm:ss.fffK", DateTimeFormatInfo.InvariantInfo);
request.OrderBy = PostsResource.ListRequest.OrderByEnum.UPDATED;
PostList response = await request.ExecuteAsync();
foreach(Post post in response.Items.Where(i => !i.Labels.Contains("Changelog")))
ToastNotificationManager.CreateToastNotifier().Show(ToastTemplates.GetBlogpostToast(post));
StorageService.LastInboxCheck = DateTime.UtcNow;
}
catch (Exception e)
{
Metrics.SendReport(new Exception("Unable to retrieve toast notifications", e));
}
}
// TODO: Add changelog retrieval
/// <summary>
/// Fires toast notification with the last changelog content
/// </summary>
[Deprecated("In future versions it will be replaced with splash screen full size message", DeprecationType.Deprecate, 1)]
public static async void PushChangelog()
{
try
{
if (string.IsNullOrWhiteSpace(StorageService.LastOpenedVersion))
StorageService.LastOpenedVersion = Metrics.CurrentVersion;
string lastVersion = StorageService.LastOpenedVersion;
if (string.IsNullOrWhiteSpace(lastVersion) || lastVersion == Metrics.CurrentVersion)
return;
PostsResource.ListRequest request = Service.Posts.List(SecretConstants.BlogId);
request.FetchImages = false;
request.Labels = $"FoxTube,Changelog,v{Metrics.CurrentVersion}";
request.MaxResults = 1;
PostList response = await request.ExecuteAsync();
if (response.Items.Count > 0)
ToastNotificationManager.CreateToastNotifier().Show(ToastTemplates.GetBlogpostToast(response.Items.First()));
StorageService.LastOpenedVersion = Metrics.CurrentVersion;
}
catch (Exception e)
{
Metrics.SendReport(new Exception("Unable to retrieve changelog", e));
}
}
}
}