Refactored core
UI navigation framework Related Work Items: #408, #414, #416
This commit is contained in:
@@ -18,18 +18,15 @@ namespace FoxTube.Utils
|
||||
|
||||
public static NativeAdsManagerV2 AdsManager => new NativeAdsManagerV2(ApplicationId, AdsId);
|
||||
|
||||
static AddonsInterop() =>
|
||||
UpdateStoreState();
|
||||
|
||||
public static async void UpdateStoreState()
|
||||
public static async Task<bool> UpdateProPurchasedState()
|
||||
{
|
||||
StoreProductQueryResult requset = await StoreContext.GetDefault().GetAssociatedStoreProductsAsync(new[] { "Durable" });
|
||||
|
||||
if (requset.Products[ProProductId].IsInUserCollection)
|
||||
return;
|
||||
return AdsDisabled = true;
|
||||
|
||||
Price = requset.Products[ProProductId].Price.FormattedPrice;
|
||||
AdsDisabled = false;
|
||||
return AdsDisabled = false;
|
||||
}
|
||||
|
||||
public static async Task<bool> PurchaseApp()
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.ApplicationModel.Background;
|
||||
using Windows.System.Power;
|
||||
using Windows.UI.Notifications;
|
||||
|
||||
namespace FoxTube.Utils
|
||||
{
|
||||
// TODO: Complete class
|
||||
public static class BackgroundManager
|
||||
{
|
||||
public static async Task PerformBackgroundTask(BackgroundActivatedEventArgs args)
|
||||
{
|
||||
|
||||
if (args.TaskInstance.TriggerDetails is ToastNotificationActionTriggerDetail details)
|
||||
{
|
||||
ProcessBackgroundAction(details.Argument);
|
||||
// TODO: Process toast parameters
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Restore user
|
||||
// TODO: Update subscriptions
|
||||
// TODO: Update homepage cache
|
||||
}
|
||||
|
||||
//var saverRequest = PowerManager.EnergySaverStatus;
|
||||
}
|
||||
|
||||
public static async Task ProcessBackgroundAction(string uri)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static async void RegisterBackgroundTasks()
|
||||
{
|
||||
var backgroundRequest = await BackgroundExecutionManager.RequestAccessAsync();
|
||||
if (backgroundRequest == BackgroundAccessStatus.DeniedBySystemPolicy || backgroundRequest == BackgroundAccessStatus.DeniedByUser)
|
||||
return;
|
||||
|
||||
RegisterBackgoundTask("FoxtubeToastBackground", new ToastNotificationActionTrigger());
|
||||
RegisterBackgoundTask("FoxtubeBackground", new TimeTrigger(15, false));
|
||||
}
|
||||
|
||||
private static void RegisterBackgoundTask(string taskName, IBackgroundTrigger trigger)
|
||||
{
|
||||
if (BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name.Equals(taskName)))
|
||||
return;
|
||||
|
||||
BackgroundTaskBuilder builder = new BackgroundTaskBuilder
|
||||
{
|
||||
Name = taskName,
|
||||
IsNetworkRequested = true
|
||||
};
|
||||
builder.SetTrigger(trigger);
|
||||
|
||||
BackgroundTaskRegistration registration = builder.Register();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ namespace FoxTube.Utils
|
||||
{
|
||||
if (!HasFeedbackHub)
|
||||
{
|
||||
Storage.SetValue(Storage.Settings.PromptFeedback, false);
|
||||
StorageService.PromptFeedback = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace FoxTube.Utils
|
||||
ContentDialogResult result = await dialog.ShowAsync();
|
||||
|
||||
if (result != ContentDialogResult.None)
|
||||
Storage.SetValue(Storage.Settings.PromptFeedback, false);
|
||||
StorageService.PromptFeedback = false;
|
||||
|
||||
if (result == ContentDialogResult.Primary)
|
||||
OpenFeedbackHub();
|
||||
@@ -80,7 +80,7 @@ namespace FoxTube.Utils
|
||||
ContentDialogResult result = await dialog.ShowAsync();
|
||||
|
||||
if (result != ContentDialogResult.None)
|
||||
Storage.SetValue(Storage.Settings.PromptReview, false);
|
||||
StorageService.PromptFeedback = false;
|
||||
|
||||
if (result == ContentDialogResult.Primary)
|
||||
RequestStoreReview();
|
||||
|
||||
@@ -5,8 +5,8 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Windows.ApplicationModel;
|
||||
using FoxTube.Services;
|
||||
using System.Globalization;
|
||||
|
||||
namespace FoxTube.Utils
|
||||
{
|
||||
@@ -15,26 +15,29 @@ namespace FoxTube.Utils
|
||||
static readonly Stopwatch sw = new Stopwatch();
|
||||
public static TimeSpan Uptime
|
||||
{
|
||||
get => Storage.GetValue<TimeSpan?>(Storage.Metrics.Uptime) ?? TimeSpan.FromSeconds(0);
|
||||
set => Storage.SetValue(Storage.Metrics.Uptime, value);
|
||||
get => StorageService.Uptime;
|
||||
set => StorageService.Uptime = value;
|
||||
}
|
||||
|
||||
public static string CurrentVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
PackageVersion v = Package.Current.Id.Version;
|
||||
return $"{v.Major}.{v.Minor}.{v.Revision}.{v.Build}";
|
||||
// TODO: Remove on release
|
||||
/*PackageVersion v = Package.Current.Id.Version;
|
||||
return $"{v.Major}.{v.Minor}.{v.Revision}.{v.Build}";*/
|
||||
return "2.0 Preview 1";
|
||||
}
|
||||
}
|
||||
|
||||
static Metrics()
|
||||
{
|
||||
sw.Start();
|
||||
if (!Storage.GetValue<bool>(Storage.Settings.AllowAnalytics))
|
||||
if (!SettingsService.AllowAnalytics)
|
||||
return;
|
||||
|
||||
AppCenter.Start(SecretConstants.MetricsId, typeof(Analytics), typeof(Crashes));
|
||||
AppCenter.SetCountryCode(Storage.GetValue<string>(Storage.Settings.Region));
|
||||
AppCenter.SetCountryCode(RegionInfo.CurrentRegion.TwoLetterISORegionName);
|
||||
AppCenter.LogLevel = LogLevel.Verbose;
|
||||
}
|
||||
|
||||
@@ -43,7 +46,7 @@ namespace FoxTube.Utils
|
||||
sw.Stop();
|
||||
Uptime += sw.Elapsed;
|
||||
|
||||
if (Storage.GetValue<bool>(Storage.Settings.AllowAnalytics))
|
||||
if (SettingsService.AllowAnalytics)
|
||||
AddEvent("Session closed",
|
||||
("Duration", sw.Elapsed.ToString()),
|
||||
("Spend time total", Uptime.ToString()));
|
||||
@@ -51,7 +54,7 @@ namespace FoxTube.Utils
|
||||
|
||||
public static void AddEvent(string eventName, params (string key, string value)[] details)
|
||||
{
|
||||
if (Storage.GetValue<bool>(Storage.Settings.AllowAnalytics))
|
||||
if (SettingsService.AllowAnalytics)
|
||||
Analytics.TrackEvent(eventName,
|
||||
details.Length < 1 ? null :
|
||||
details.Select(i => new KeyValuePair<string, string>(i.key, i.value)) as Dictionary<string, string>);
|
||||
@@ -59,7 +62,7 @@ namespace FoxTube.Utils
|
||||
|
||||
public static void SendReport(Exception exception, ErrorAttachmentLog[] logs = null, params (string key, string value)[] details)
|
||||
{
|
||||
if (Storage.GetValue<bool>(Storage.Settings.AllowAnalytics))
|
||||
if (SettingsService.AllowAnalytics)
|
||||
{
|
||||
logs ??= new ErrorAttachmentLog[0];
|
||||
Crashes.TrackError(exception ?? new Exception("Unknown exception"),
|
||||
|
||||
@@ -11,6 +11,8 @@ namespace FoxTube.Utils
|
||||
public static class SecretConstants
|
||||
{
|
||||
public const string YoutubeApiKey = "AIzaSyBgHrCnrlzlVmk0cJKL8RqP9Y8x6XSuk_0";
|
||||
public const string BloggerApiKey = "AIzaSyD7tpbuvmYDv9h4udo9L_g3r0sLPFAnN00";
|
||||
public const string BlogId = "8566398713922921363";
|
||||
public const string MetricsId = "45774462-9ea7-438a-96fc-03982666f39e";
|
||||
public const string ProAddonId = "9NP1QK556625";
|
||||
public const string AdsUnitId = "1100044398";
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using System.Linq;
|
||||
using Microsoft.Toolkit.Uwp.Notifications;
|
||||
using Google.Apis.Blogger.v3.Data;
|
||||
using Windows.UI.Notifications;
|
||||
using AngleSharp.Html.Parser;
|
||||
|
||||
namespace FoxTube.Utils
|
||||
{
|
||||
public static class ToastTemplates
|
||||
{
|
||||
public static ToastNotification GetBlogpostToast(Post post)
|
||||
{
|
||||
ToastContent toastContent = new ToastContent
|
||||
{
|
||||
Visual = new ToastVisual
|
||||
{
|
||||
BindingGeneric = new ToastBindingGeneric
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new AdaptiveText
|
||||
{
|
||||
Text = new BindableString(post.Title)
|
||||
},
|
||||
new AdaptiveText()
|
||||
{
|
||||
Text = new BindableString(new HtmlParser().ParseDocument(post.Content).QuerySelector("p").TextContent),
|
||||
HintMaxLines = 2
|
||||
}
|
||||
},
|
||||
AppLogoOverride = new ToastGenericAppLogo
|
||||
{
|
||||
Source = post.Author.Image.Url,
|
||||
HintCrop = ToastGenericAppLogoCrop.Circle
|
||||
}
|
||||
}
|
||||
},
|
||||
Launch = $"Settings/Inbox/{post.Id}",
|
||||
ActivationType = ToastActivationType.Foreground
|
||||
};
|
||||
|
||||
if (post.Images.Count > 0)
|
||||
toastContent.Visual.BindingGeneric.HeroImage = new ToastGenericHeroImage
|
||||
{
|
||||
Source = post.Images.FirstOrDefault()?.Url
|
||||
};
|
||||
|
||||
return new ToastNotification(toastContent.GetXml());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
using System;
|
||||
using Windows.ApplicationModel.Core;
|
||||
using Windows.Security.Credentials;
|
||||
using Windows.UI;
|
||||
using Windows.UI.ViewManagement;
|
||||
|
||||
namespace FoxTube.Utils
|
||||
{
|
||||
@@ -29,11 +31,36 @@ namespace FoxTube.Utils
|
||||
public static async void InitializeFailsafeProtocol()
|
||||
{
|
||||
Metrics.AddEvent("Failsafe protocol initiated");
|
||||
await Storage.ResetStorage();
|
||||
await StorageService.ClearStorage();
|
||||
PasswordVault passwordVault = new PasswordVault();
|
||||
foreach (PasswordCredential credential in passwordVault.RetrieveAll())
|
||||
passwordVault.Remove(credential);
|
||||
RestartApp();
|
||||
}
|
||||
|
||||
public static void UpdateTitleBarTheme(bool isDark)
|
||||
{
|
||||
ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar;
|
||||
titleBar.ButtonBackgroundColor = Colors.Transparent;
|
||||
titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
|
||||
titleBar.ButtonInactiveForegroundColor = Colors.Gray;
|
||||
|
||||
if (isDark)
|
||||
{
|
||||
titleBar.ButtonForegroundColor =
|
||||
titleBar.ButtonHoverForegroundColor =
|
||||
titleBar.ButtonPressedForegroundColor = Colors.White;
|
||||
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(50, 255, 255, 255);
|
||||
titleBar.ButtonPressedBackgroundColor = Color.FromArgb(30, 255, 255, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
titleBar.ButtonForegroundColor =
|
||||
titleBar.ButtonHoverForegroundColor =
|
||||
titleBar.ButtonPressedForegroundColor = Colors.Black;
|
||||
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(50, 0, 0, 0);
|
||||
titleBar.ButtonPressedBackgroundColor = Color.FromArgb(70, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user