-Fixed Unspecified error on App.e.g.cs
-Refactoring
This commit is contained in:
@@ -0,0 +1,180 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace FoxTube.Classes
|
||||
{
|
||||
public static class SettingsStorage
|
||||
{
|
||||
public static string VideoQuality
|
||||
{
|
||||
get { return (string)settings[0]; }
|
||||
set
|
||||
{
|
||||
settings[0] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
public static string RememberedQuality
|
||||
{
|
||||
get { return (string)settings[1]; }
|
||||
set
|
||||
{
|
||||
settings[1] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool VideoNotifications
|
||||
{
|
||||
get { return (bool)settings[2]; }
|
||||
set
|
||||
{
|
||||
settings[2] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
public static bool DevNotifications
|
||||
{
|
||||
get { return (bool)settings[3]; }
|
||||
set
|
||||
{
|
||||
settings[3] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckConnection
|
||||
{
|
||||
get { return (bool)settings[4]; }
|
||||
set
|
||||
{
|
||||
settings[4] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
public static bool Autoplay
|
||||
{
|
||||
get { return (bool)settings[5]; }
|
||||
set
|
||||
{
|
||||
settings[5] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
public static int Volume
|
||||
{
|
||||
get { return (int)settings[6]; }
|
||||
set
|
||||
{
|
||||
settings[6] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
|
||||
public static string Language
|
||||
{
|
||||
get { return (string)settings[7]; }
|
||||
set
|
||||
{
|
||||
settings[7] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
public static string Region
|
||||
{
|
||||
get { return (string)settings[8]; }
|
||||
set
|
||||
{
|
||||
settings[8] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
public static int SafeSearch
|
||||
{
|
||||
get { return (int)settings[9]; }
|
||||
set
|
||||
{
|
||||
settings[9] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
|
||||
public static int Theme
|
||||
{
|
||||
get { return (int)settings[10]; }
|
||||
set
|
||||
{
|
||||
settings[10] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
public static bool HasAccount
|
||||
{
|
||||
get { return (bool)settings[11]; }
|
||||
set
|
||||
{
|
||||
settings[11] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
|
||||
public static string Version
|
||||
{
|
||||
get
|
||||
{
|
||||
if (storage.Values["ver"] == null)
|
||||
{
|
||||
PackageVersion ver = Package.Current.Id.Version;
|
||||
return $"{ver.Major}.{ver.Minor}";
|
||||
}
|
||||
else return (string)storage.Values["version"];
|
||||
}
|
||||
set
|
||||
{
|
||||
storage.Values["version"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
//Settings storage
|
||||
private static ApplicationDataContainer storage = ApplicationData.Current.LocalSettings;
|
||||
|
||||
//Predefined preferences
|
||||
private static object[] settings = new object[]
|
||||
{
|
||||
"remember",
|
||||
"1080p",
|
||||
|
||||
true,
|
||||
true,
|
||||
|
||||
true,
|
||||
true,
|
||||
100,
|
||||
|
||||
(new[] { "ua", "ru", "by", "kz", "kg", "md", "lv", "ee" }).Contains(CultureInfo.InstalledUICulture.TwoLetterISOLanguageName) ? "ru-RU" : "en-US",
|
||||
CultureInfo.CurrentCulture.Name,
|
||||
0,
|
||||
|
||||
2,
|
||||
false
|
||||
};
|
||||
|
||||
public static void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
settings = JsonConvert.DeserializeObject<object[]>(storage.Values["settings"] as string);
|
||||
}
|
||||
catch (NullReferenceException) { }
|
||||
}
|
||||
|
||||
public static void SaveData()
|
||||
{
|
||||
storage.Values["settings"] = JsonConvert.SerializeObject(settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user