Archived
1
0

Refactored core

UI navigation framework

Related Work Items: #408, #414, #416
This commit is contained in:
Michael Gordeev
2020-06-15 15:46:38 +03:00
parent c58d846057
commit 787a6e9f48
72 changed files with 2002 additions and 1227 deletions
+35 -26
View File
@@ -1,18 +1,24 @@
using FoxTube.Models.Collections;
using FoxTube.Utils;
using Newtonsoft.Json;
using System;
using System.Net;
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 const string lastChangelogVersionKey = "Inbox.lastChangelogVersion";
public const string lastCheckKey = "Inbox.lastChangelogVersion";
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();
@@ -23,22 +29,19 @@ namespace FoxTube.Services
{
try
{
// TODO: Add backend
HttpResponseMessage response = await client.GetAsync($"https://xfox111.net/FoxTube/Inbox?" +
$"toast=true&" +
$"publishedAfter={Storage.Registry.Values[lastCheckKey]}&" +
$"lang={Storage.GetValue<string>(Storage.Settings.UILanguage)}&" +
$"appVersion={Metrics.CurrentVersion}");
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;
Storage.Registry.Values[lastCheckKey] = DateTime.UtcNow.Ticks;
PostList response = await request.ExecuteAsync();
if (response.StatusCode == HttpStatusCode.NoContent)
return;
foreach(Post post in response.Items.Where(i => !i.Labels.Contains("Changelog")))
ToastNotificationManager.CreateToastNotifier().Show(ToastTemplates.GetBlogpostToast(post));
string[] toasts = JsonConvert.DeserializeObject<string[]>(await response.Content.ReadAsStringAsync());
foreach (string toast in toasts)
ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toast.ToXml()));
StorageService.LastInboxCheck = DateTime.UtcNow;
}
catch (Exception e)
{
@@ -46,27 +49,33 @@ namespace FoxTube.Services
}
}
// 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
{
// TODO: Add backend
if ((string)Storage.Registry.Values[lastChangelogVersionKey] == Metrics.CurrentVersion)
if (string.IsNullOrWhiteSpace(StorageService.LastOpenedVersion))
StorageService.LastOpenedVersion = Metrics.CurrentVersion;
string lastVersion = StorageService.LastOpenedVersion;
if (string.IsNullOrWhiteSpace(lastVersion) || lastVersion == Metrics.CurrentVersion)
return;
Storage.Registry.Values[lastChangelogVersionKey] = Metrics.CurrentVersion;
PostsResource.ListRequest request = Service.Posts.List(SecretConstants.BlogId);
request.FetchImages = false;
request.Labels = $"FoxTube,Changelog,v{Metrics.CurrentVersion}";
request.MaxResults = 1;
HttpResponseMessage response = await client.GetAsync($"https://xfox111.net/API/FoxTube/Changelog?" +
$"lang={Storage.GetValue<string>(Storage.Settings.UILanguage)}&" +
$"version={Metrics.CurrentVersion}");
PostList response = await request.ExecuteAsync();
if (response.StatusCode == HttpStatusCode.NoContent)
return;
if (response.Items.Count > 0)
ToastNotificationManager.CreateToastNotifier().Show(ToastTemplates.GetBlogpostToast(response.Items.First()));
ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification((await response.Content.ReadAsStringAsync()).ToXml()));
StorageService.LastOpenedVersion = Metrics.CurrentVersion;
}
catch (Exception e)
{