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
FoxTube/FoxTube.Core/Services/SettingsService.cs
T
Michael Gordeev 787a6e9f48 Refactored core
UI navigation framework

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

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
}
}