Archived
1
0

222: Fixed

227: Additional fixes (final)
Introduced new settings storing system

Related Work Items: #222, #227
This commit is contained in:
Michael Gordeev
2018-12-23 22:22:22 +03:00
parent 91fd3f6ab9
commit efb07fda10
8 changed files with 96 additions and 229 deletions
+42 -67
View File
@@ -1,49 +1,42 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace FoxTube.Pages.SettingsPages
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// Settings page with general preferences
/// </summary>
public sealed partial class General : Page
{
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
public General()
{
this.InitializeComponent();
InitializeComponent();
language.SelectedIndex = (string)settings.Values["language"] == "en-US"? 0 : 1;
quality.SelectedItem = quality.Items.ToList().Find(x => (x as ComboBoxItem).Tag as string == (string)settings.Values["quality"]);
language.SelectedItem = language.Items.Find(i => ((ComboBoxItem)i).Tag.ToString() == SettingsStorage.Language);
CultureInfo.GetCultures(CultureTypes.AllCultures).FindAll(i => !i.IsNeutralCulture).ForEach(i =>
{
region.Items.Add(new ComboBoxItem
{
Content = i.DisplayName,
Tag = i.IetfLanguageTag
});
if (i.IetfLanguageTag == SettingsStorage.Region)
region.SelectedItem = region.Items.Last();
});
safeSearch.SelectedIndex = SettingsStorage.SafeSearch;
newVideo.IsOn = (bool)settings.Values["newVideoNotification"];
quality.SelectedItem = quality.Items.ToList().Find(i => ((ComboBoxItem)i).Tag.ToString() == SettingsStorage.VideoQuality);
mobileWarning.IsOn = SettingsStorage.CheckConnection;
autoplay.IsOn = SettingsStorage.Autoplay;
mobileWarning.IsOn = (bool)settings.Values["moblieWarning"];
autoplay.IsOn = (bool)settings.Values["videoAutoplay"];
newVideo.IsOn = SettingsStorage.VideoNotifications;
devNews.IsOn = SettingsStorage.DevNotifications;
safeSearch.SelectedIndex = (int)settings.Values["safeSearch"];
switch((int)settings.Values["themeMode"])
switch(SettingsStorage.Theme)
{
case 0:
light.IsChecked = true;
@@ -55,77 +48,63 @@ namespace FoxTube.Pages.SettingsPages
system.IsChecked = true;
break;
}
foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
region.Items.Add(culture.DisplayName);
if (culture.Name == (string)settings.Values["region"])
region.SelectedIndex = region.Items.Count - 1;
}
}
private void language_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if ((string)settings.Values["language"] != (language.SelectedItem as ComboBoxItem).Tag.ToString())
{
settings.Values["language"] = (language.SelectedItem as ComboBoxItem).Tag.ToString();
restartNote.Visibility = Visibility.Visible;
}
else
restartNote.Visibility = Visibility.Collapsed;
if (SettingsStorage.Language == (language.SelectedItem as ComboBoxItem).Tag.ToString())
return;
SettingsStorage.Language = (language.SelectedItem as ComboBoxItem).Tag.ToString();
restartNote.Visibility = Visibility.Visible;
}
private void quality_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
settings.Values["quality"] = (quality.SelectedItem as ComboBoxItem).Tag as string;
SettingsStorage.VideoQuality = (quality.SelectedItem as ComboBoxItem).Tag as string;
}
private void mobileWarning_Toggled(object sender, RoutedEventArgs e)
{
settings.Values["moblieWarning"] = mobileWarning.IsOn;
SettingsStorage.CheckConnection = mobileWarning.IsOn;
}
private void autoplay_Toggled(object sender, RoutedEventArgs e)
{
settings.Values["videoAutoplay"] = autoplay.IsOn;
SettingsStorage.Autoplay = autoplay.IsOn;
}
private async void notification_IsEnabledChanged(object sender, RoutedEventArgs e)
private void notification_IsEnabledChanged(object sender, RoutedEventArgs e)
{
settings.Values["newVideoNotification"] = newVideo.IsOn;
bool[] notificationsSettings = new bool[] { (bool)settings.Values["newVideoNotification"], (bool)settings.Values["devNews"] };
await FileIO.WriteTextAsync(
await ApplicationData.Current.RoamingFolder.CreateFileAsync("notifications.json", CreationCollisionOption.ReplaceExisting),
JsonConvert.SerializeObject(notificationsSettings));
SettingsStorage.VideoNotifications = newVideo.IsOn;
}
private void region_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
settings.Values["region"] = CultureInfo.GetCultures(CultureTypes.AllCultures)[region.SelectedIndex].Name;
SettingsStorage.Region = CultureInfo.GetCultures(CultureTypes.AllCultures)[region.SelectedIndex].Name;
}
private void safeSearch_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
settings.Values["safeSearch"] = safeSearch.SelectedIndex;
SettingsStorage.SafeSearch = safeSearch.SelectedIndex;
}
private void RadioButton_Checked(object sender, RoutedEventArgs e)
{
if (sender == light && (int)settings.Values["themeMode"] != 0)
if (sender == light && SettingsStorage.Theme != 0)
{
settings.Values["themeMode"] = 0;
SettingsStorage.Theme = 0;
Methods.MainPage.RequestedTheme = ElementTheme.Light;
}
if (sender == dark && (int)settings.Values["themeMode"] != 1)
else if (sender == dark && SettingsStorage.Theme != 1)
{
settings.Values["themeMode"] = 1;
SettingsStorage.Theme = 1;
Methods.MainPage.RequestedTheme = ElementTheme.Dark;
}
if (sender == system && (int)settings.Values["themeMode"] != 2)
else if (sender == system && SettingsStorage.Theme != 2)
{
settings.Values["themeMode"] = 2;
Color uiTheme = (new Windows.UI.ViewManagement.UISettings()).GetColorValue(Windows.UI.ViewManagement.UIColorType.Background);
SettingsStorage.Theme = 2;
Color uiTheme = new Windows.UI.ViewManagement.UISettings().GetColorValue(Windows.UI.ViewManagement.UIColorType.Background);
if (uiTheme == Colors.Black)
Methods.MainPage.RequestedTheme = ElementTheme.Dark;
else
@@ -139,13 +118,9 @@ namespace FoxTube.Pages.SettingsPages
CoreApplication.Exit();
}
private async void devNews_Toggled(object sender, RoutedEventArgs e)
private void devNews_Toggled(object sender, RoutedEventArgs e)
{
settings.Values["devnews"] = devNews.IsOn;
bool[] notificationsSettings = new bool[] { (bool)settings.Values["newVideoNotification"], (bool)settings.Values["devNews"] };
await FileIO.WriteTextAsync(
await ApplicationData.Current.RoamingFolder.CreateFileAsync("notifications.json", CreationCollisionOption.ReplaceExisting),
JsonConvert.SerializeObject(notificationsSettings));
SettingsStorage.DevNotifications = devNews.IsOn;
}
}
}