Core update. Base core features are done (main app doesn't compile)
Related Work Items: #416, #422, #423, #424
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using Windows.UI.Xaml;
|
||||
|
||||
namespace FoxTube.Services
|
||||
{
|
||||
public static class Storage
|
||||
{
|
||||
public static event EventHandler<Settings> SettingsChanged;
|
||||
|
||||
public static StorageFolder Folder => ApplicationData.Current.RoamingFolder;
|
||||
public static ApplicationDataContainer Registry { get; } = ApplicationData.Current.RoamingSettings;
|
||||
|
||||
private static readonly Dictionary<Settings, object> _defaultSettings = new Dictionary<Settings, object>
|
||||
{
|
||||
{ Settings.Theme, ElementTheme.Default },
|
||||
{ Settings.UILanguage, GetDefaultLanguage() },
|
||||
{ Settings.RelevanceLanguage, GetDefaultLanguage() },
|
||||
{ Settings.PromptFeedback, true },
|
||||
{ Settings.PromptReview, true },
|
||||
{ Settings.AllowAnalytics, true }
|
||||
};
|
||||
|
||||
public enum Settings
|
||||
{
|
||||
/// <summary>
|
||||
/// ElementTheme
|
||||
/// </summary>
|
||||
Theme,
|
||||
/// <summary>
|
||||
/// string
|
||||
/// </summary>
|
||||
UILanguage,
|
||||
/// <summary>
|
||||
/// string
|
||||
/// </summary>
|
||||
RelevanceLanguage,
|
||||
/// <summary>
|
||||
/// string
|
||||
/// </summary>
|
||||
DefaultDownloadsFolder,
|
||||
/// <summary>
|
||||
/// bool
|
||||
/// </summary>
|
||||
PromptFeedback,
|
||||
/// <summary>
|
||||
/// bool
|
||||
/// </summary>
|
||||
PromptReview,
|
||||
/// <summary>
|
||||
/// bool
|
||||
/// </summary>
|
||||
AllowAnalytics,
|
||||
/// <summary>
|
||||
/// string
|
||||
/// </summary>
|
||||
Region
|
||||
}
|
||||
|
||||
public enum Metrics
|
||||
{
|
||||
/// <summary>
|
||||
/// TimeSpan
|
||||
/// </summary>
|
||||
Uptime
|
||||
}
|
||||
|
||||
|
||||
public static void SetValue(Settings key, object value)
|
||||
{
|
||||
Registry.Values[$"{key.GetType().Name}.{key}"] = value;
|
||||
SettingsChanged?.Invoke(value, key);
|
||||
}
|
||||
public static void SetValue(Metrics key, object value) =>
|
||||
Registry.Values[$"{key.GetType().Name}.{key}"] = value;
|
||||
|
||||
public static T GetValue<T>(Settings key) =>
|
||||
(T)(Registry.Values[$"{key.GetType().Name}.{key}"] ?? (_defaultSettings.ContainsKey(key) ? _defaultSettings[key] : null));
|
||||
public static T GetValue<T>(Metrics key) =>
|
||||
(T)Registry.Values[$"{key.GetType().Name}.{key}"];
|
||||
|
||||
|
||||
private static string GetDefaultLanguage()
|
||||
{
|
||||
if (CultureInfo.InstalledUICulture.TwoLetterISOLanguageName.Belongs("ua", "ru", "by", "kz", "kg", "md", "lv", "ee")) //Languages for Russian-speaking countries
|
||||
return "ru-RU";
|
||||
else
|
||||
return "en-US";
|
||||
}
|
||||
|
||||
public static async Task ResetStorage()
|
||||
{
|
||||
Registry.Values.Clear();
|
||||
foreach (IStorageItem i in await Folder.GetItemsAsync())
|
||||
await i.DeleteAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user