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/Classes/Settings.cs
T
Michael Gordeev 6d093c90f5 Done frame controls
Related Work Items: #314, #315
2019-08-11 10:51:22 +03:00

267 lines
7.0 KiB
C#

using Newtonsoft.Json;
using System;
using System.Globalization;
using System.Linq;
using Windows.ApplicationModel;
using Windows.Storage;
using Windows.UI.Xaml.Controls;
namespace FoxTube.Classes
{
public static class Settings
{
public class SettingsContainer
{
public string videoQuality = "remember";
public string rememberedQuality = "1080p";
public bool videoNotifications = true;
public bool devNotifications = true;
public bool checkConnection = true;
public bool autoplay = true;
public double volume = 100;
public string language = GetLanguage();
public string relevanceLanguage = CultureInfo.InstalledUICulture.TwoLetterISOLanguageName;
public string region = CultureInfo.InstalledUICulture.Name.Split('-')[1];
public int safeSearch = 0;
public bool[] hasAccount = new bool[5] { false, false, false, false, false };
public int theme = 2;
public string version = GetCurrentVersion();
public bool mature = false;
public TimeSpan uptime = TimeSpan.FromSeconds(0);
public bool promptReview = true;
public bool promptFeedback = true;
public bool processClipboard = true;
public bool minimizeCommandbar = false;
static string GetLanguage()
{
if ((new[] { "ua", "ru", "by", "kz", "kg", "md", "lv", "ee" }).Contains(CultureInfo.InstalledUICulture.TwoLetterISOLanguageName))
return "ru-RU";
else
return "en-US";
}
}
public static string GetCurrentVersion()
{
PackageVersion ver = Package.Current.Id.Version;
return $"{ver.Major}.{ver.Minor}";
}
public static string VideoQuality
{
get => Container.videoQuality;
set
{
Container.videoQuality = value;
SaveData();
}
}
public static string RememberedQuality
{
get => Container.rememberedQuality;
set
{
Container.rememberedQuality = value;
SaveData();
}
}
public static bool VideoNotifications
{
get => Container.videoNotifications;
set
{
Container.videoNotifications = value;
SaveData();
}
}
public static bool DevNotifications
{
get => Container.devNotifications;
set
{
Container.devNotifications = value;
SaveData();
}
}
public static bool CheckConnection
{
get => Container.checkConnection;
set
{
Container.checkConnection = value;
SaveData();
}
}
public static bool Autoplay
{
get => Container.autoplay;
set
{
Container.autoplay = value;
SaveData();
}
}
public static double Volume
{
get => Container.volume;
set
{
Container.volume = value;
SaveData();
}
}
public static string Language
{
get => Container.language;
set
{
Container.language = value;
SaveData();
}
}
public static string RelevanceLanguage
{
get => Container.relevanceLanguage;
set
{
Container.relevanceLanguage = value;
SaveData();
}
}
public static string Region
{
get => Container.region;
set
{
Container.region = value;
SaveData();
}
}
public static int SafeSearch
{
get => Container.safeSearch;
set
{
Container.safeSearch = value;
SaveData();
}
}
public static bool[] HasAccount => Container.hasAccount;
public static void SetAccount(int index, bool isAuthorized)
{
HasAccount[index] = isAuthorized;
SaveData();
}
public static int Theme
{
get => Container.theme;
set
{
Container.theme = value;
SaveData();
}
}
public static string Version
{
get => Container.version;
set
{
Container.version = value;
SaveData();
}
}
public static bool Mature
{
get => Container.mature;
set
{
Container.mature = value;
SaveData();
}
}
public static TimeSpan Uptime
{
get => Container.uptime;
set
{
Container.uptime = value;
SaveData();
}
}
public static bool PromptReview
{
get => Container.promptReview;
set
{
Container.promptReview = value;
SaveData();
}
}
public static bool PromptFeedback
{
get => Container.promptFeedback;
set
{
Container.promptFeedback = value;
SaveData();
}
}
public static bool ProcessClipboard
{
get => Container.processClipboard;
set
{
Container.processClipboard = value;
SaveData();
}
}
public static AppBarClosedDisplayMode AppBarClosedMode
{
get => Container.minimizeCommandbar ? AppBarClosedDisplayMode.Minimal : AppBarClosedDisplayMode.Compact;
set
{
Container.minimizeCommandbar = value == AppBarClosedDisplayMode.Minimal;
SaveData();
}
}
//Settings storage
static readonly ApplicationDataContainer storage = ApplicationData.Current.RoamingSettings;
static SettingsContainer Container = new SettingsContainer();
/// <summary>
/// Loads saved settings from storage
/// </summary>
public static void LoadData()
{
try
{
Container = JsonConvert.DeserializeObject<SettingsContainer>(storage.Values["settings"] as string);
}
catch
{
Container = new SettingsContainer();
SaveData();
}
}
static void SaveData() =>
storage.Values["settings"] = JsonConvert.SerializeObject(Container);
}
}