787a6e9f48
UI navigation framework Related Work Items: #408, #414, #416
67 lines
1.6 KiB
C#
67 lines
1.6 KiB
C#
using Windows.Storage;
|
|
using System.Globalization;
|
|
using System.Diagnostics;
|
|
using Windows.UI.Xaml;
|
|
|
|
namespace FoxTube.Services
|
|
{
|
|
public class SettingsService
|
|
{
|
|
private static readonly ApplicationDataContainer storage = ApplicationData.Current.RoamingSettings;
|
|
|
|
public static void ResetSettings() =>
|
|
storage.Values.Clear();
|
|
|
|
public static ElementTheme Theme
|
|
{
|
|
get => (ElementTheme)GetValue(ElementTheme.Default);
|
|
set => SetValue((int)value);
|
|
}
|
|
|
|
public static string RelevanceLanguage
|
|
{
|
|
get => GetValue(GetDefaultLanguage());
|
|
set => SetValue(value);
|
|
}
|
|
|
|
public static bool AllowAnalytics
|
|
{
|
|
get => GetValue(true);
|
|
set => SetValue(value);
|
|
}
|
|
|
|
public static bool AskEveryDownload
|
|
{
|
|
get => GetValue(true);
|
|
set => SetValue(value);
|
|
}
|
|
|
|
public static string DefaultDownloadsFolder
|
|
{
|
|
get => GetValue(null);
|
|
set => SetValue(value);
|
|
}
|
|
|
|
#region Service methods
|
|
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";
|
|
}
|
|
|
|
private static dynamic GetValue(object defaultValue)
|
|
{
|
|
string propName = (new StackTrace()).GetFrame(1).GetMethod().Name.Substring(4);
|
|
return storage.Values[$"Settings.{propName}"] ?? defaultValue;
|
|
}
|
|
|
|
private static void SetValue(object value)
|
|
{
|
|
string propName = (new StackTrace()).GetFrame(1).GetMethod().Name.Substring(4);
|
|
storage.Values[$"Settings.{propName}"] = value;
|
|
}
|
|
#endregion
|
|
}
|
|
} |